页面跳转前对ToKen判断

来源:互联网 发布:丹爷辣椒酱淘宝 编辑:程序博客网 时间:2024/05/18 01:35
public class GetMyWalletInfo {private Context context;private String action;public GetMyWalletInfo(Context context, String action) {this.context = context;this.action = action;}/*public GetMyWalletInfo(Context context) {this.context = context;}*/public void getMyWallet() {if (new GetSharePerfence(context).getToken().equals("")) {Toast.makeText(context, "请先登录", Toast.LENGTH_LONG).show();Intent intent = new Intent(context, LoginActivity.class);intent.putExtra("action",action);context.startActivity(intent);} else {RequestParams parmas = new RequestParams(Config.WALLETURL);parmas.addHeader("token", new GetSharePerfence(context).getToken());x.http().get(parmas, new MyCallBack<String>() {@Overridepublic void onSuccess(String result) {Gson gson = new Gson();ErrorMsg errorMsg = gson.fromJson(result, ErrorMsg.class);if (errorMsg.getErrorCode() == 300) {//错误码未300表示token过期Toast.makeText(context, "已过期,请重新登录", Toast.LENGTH_LONG).show();Intent intent = new Intent(context, LoginActivity.class);intent.putExtra("action",action);context.startActivity(intent);} else {Intent intent =new Intent();intent.setAction(action);context.startActivity(intent);}super.onSuccess(result);}});}}}--------------------------------------------点击前的token判断@Overridepublic void onClick(View view) {switch (view.getId()) {case R.id.helper:new GetMyWalletInfo(getContext(), "com.carinsurance").getMyWallet();// getUserInfo(); //实名认证break;case R.id.rl_wallet:new GetMyWalletInfo(getContext(), "com.home").getMyWallet();break;case R.id.rl_task:new GetMyWalletInfo(getContext(), "com.insurance").getMyWallet();break;case R.id.rl_baojai:new GetMyWalletInfo(getContext(), "com.home.baojia").getMyWallet();break;}}


原创粉丝点击