??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("服務(wù)器異常");
//??????????}
??????????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();
????????}
????}
????
????后臺給我了一個(gè)返回參數(shù)?message?然后根據(jù)參數(shù)值來判斷?登錄狀況??可是都不彈Toast
????
????//??登錄請求返回的參數(shù)
?????????//賬號或密碼有誤
????public??static??final?String?Wrong_account="20002";
?????????//賬號禁止登陸
????public??static??final?String?Account_no_entry="20003";
??????????//異常發(fā)生
????public??static??final?String?Abnormal_occurrence?="20004";
?????????//操作成功
????public??static??final?String?Successful_operation?="20005";
???????//無訪問該模塊權(quán)限
???????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";
2 回答

qq_我們咫尺之間_0
TA貢獻(xiàn)5條經(jīng)驗(yàn) 獲得超1個(gè)贊
你能確定的回調(diào)被調(diào)用了么
然后才是toast的問題
吐槽下? static final 后面的變量全部要大寫
添加回答
舉報(bào)
0/150
提交
取消