예제 #1
0
  public static void login(
      final HttpReqListener listener, final String account, final String password) {
    HttpClient.getInstance()
        .doWork(
            HttpUrl.getLoginUrl(),
            HttpParam.getLoginParam(account, password),
            new HttpClient.HttpCallBack() {
              @Override
              public void succeed(int statusCode, String content) {
                try {
                  JSONObject jsonObject = new JSONObject(content);
                  String flag = jsonObject.optString("status");
                  String tip = null;
                  if (flag.equals("1")) {
                    listener.onUpdate(HttpEvent.EVENT_LOGIN_SUCCESS, null);
                  } else {
                    if (flag.equals("-1")) {
                      tip = "账号为空";
                    } else if (flag.equals("-2")) {
                      tip = "密码为空";
                    } else if (flag.equals("-3")) {
                      tip = "账号或密码错误";
                    }
                    listener.onUpdate(HttpEvent.EVENT_LOGIN_FAIL, tip);
                  }
                } catch (JSONException e) {
                  Log.e("NetWorkUtil", "loginJsonCatch=", e);
                  listener.onUpdate(HttpEvent.EVENT_LOGIN_FAIL, e.toString());
                }
              }

              @Override
              public void failed(Throwable error, String content) {
                listener.onUpdate(HttpEvent.EVENT_LOGIN_FAIL, content);
              }
            });
  }