??String?id="?loginname="+mUserName.getText().toString()+"&password="+mPassWord.getText().toString();
????????OkHttpClient?mOkHttpClient=new?OkHttpClient();
????????Request?mRequest=new?Request.Builder().get().url(URL+id).build();
????????Log.d("jkie",URL+id);
????????Call?mCall=mOkHttpClient.newCall(mRequest);
????????mCall.enqueue(new?Callback()?{
????????????@Override
????????????public?void?onFailure(Request?request,?IOException?e)?{
//????????????????Toast.makeText(LoginActivity.this,"登錄失敗,請重試!",Toast.LENGTH_SHORT).show();
?????????????Log.d("hjauens",e.getMessage());
????????????}
????????????@Override
????????????public?void?onResponse(Response?response)?throws?IOException?{
????????????????final?String?mResponse=response.body().string();
????????????????Log.d("hhaha",mResponse);
????????????????runOnUiThread(new?Runnable()?{
????????????????????@Override
????????????????????public?void?run()?{
????????????????????????parset(mResponse);
????????????????????}
????????????????});
????????????}
????????});
????}
????private?void?parset(String?mResponse)?{
????????try?{
????????????JSONObject?mJSON=new?JSONObject(mResponse);
????????????JSONObject?mJ=mJSON.getJSONObject("loginUser");
?????????????mToken=mJ.optString("id");
????????????Log.d("token",mToken);
????????????App.getApp().setToken(mToken);
????????????String?message=mJSON.optString("message");
????????????Log.d("消息",message);
//????????????if?(message.equals(Constants.Wrong_account)){
//??????????????LoginActivity.this.showLongToast("賬號有誤");
//??????????}
//??????????if?(message.equals(Constants.Account_no_entry)){
//??????????????LoginActivity.this.showLongToast("賬號禁止登陸");
//??????????}
//??????????if?(message.equals(Constants.Abnormal_occurrence)){
//??????????????LoginActivity.this.?showLongToast("服務器異常");
//??????????}
??????????if?(message.equals(Constants.Successful_operation?)){
??????????????Intent?i=new?Intent(LoginActivity.this,MainActivity.class);
??????????????startActivity(i);
??????????????finish();
??????????}
//??????????if?(message.equals(Constants.password_incorrect)){
//??????????????LoginActivity.this.showLongToast("舊密碼不正確");
//??????????}
//??????????if?(message.equals(Constants.Already_in_use)){
//??????????????LoginActivity.this.showLongToast("用戶名已被使用");
//??????????}
????????}?catch?(JSONException?e)?{
????????????e.printStackTrace();
????????}
????}
????
????后臺給我了一個返回參數?message?然后根據參數值來判斷?登錄狀況??可是都不彈Toast
????
????//??登錄請求返回的參數
?????????//賬號或密碼有誤
????public??static??final?String?Wrong_account="20002";
?????????//賬號禁止登陸
????public??static??final?String?Account_no_entry="20003";
??????????//異常發生
????public??static??final?String?Abnormal_occurrence?="20004";
?????????//操作成功
????public??static??final?String?Successful_operation?="20005";
???????//無訪問該模塊權限
???????public??static??final?String?Jurisdiction="20006";
???????//舊密碼不正確
???????public??static??final?String??password_incorrect="20007";
???????//找不到對象
???????public??static??final?String??Object_not_found="20008";
???????//????用戶名已被使用
???????public??static??final?String?Already_in_use="20009";
添加回答
舉報
0/150
提交
取消