android Volley登入驗證的使用

dingcheng998發表於2016-11-19

使用Volley登入驗證需要在Volley請求中驗證登入和返回相關訊息

   //遠端驗證使用者
    private void removeVerify(){
        String url = "http://192.168.80.2:8080/fag/login";
        DataOfString json = new DataOfString(getApplicationContext(),url, Request.Method.POST,loginPojo.class);
        json.setVolleyCallBck(new StringVolleyCallback() {
            @Override
            public void getStringFromVolley(String s) {
                //System.out.println(s);
            }

            @Override
            public void putStringFromVolley(Map<String, String> map) {
                map.put(USERNAME,userName.getText().toString());
                map.put(PASSWORDS,passWord.getText().toString());
            }

            @Override
            public void getJsonFromJsonString(Object o) {
                 loginPojo pojo = (loginPojo) o;
                 if (pojo.getError_code() == 0){
                     //儲存sessionId
                     BaseApplication.setSessionId(pojo.getSessionId());
                     //儲存使用者資訊
                     userinfo info = pojo.getData();
                     if (info != null){
//                 
                         setuserinfo();
                         Toast.makeText(getApplicationContext(), "登入成功", Toast.LENGTH_SHORT).show();
                     }
                 }else {
                     Toast.makeText(getApplicationContext(), pojo.getReason(), Toast.LENGTH_LONG).show();
                 }
            }

            @Override
            public void getJsonErrorResponse(String s) {

            }
        });
        json.StringFromAndPutNet();
    }

//儲存使用者相關資訊
    private void setuserinfo(){
        //設定登入狀態
        BaseApplication.setApp_isLogin(true);
        finish();
    }



相關文章