|
|
@@ -6,7 +6,20 @@ import android.util.Log;
|
|
|
import android.widget.Toast;
|
|
|
|
|
|
import com.alibaba.fastjson.JSON;
|
|
|
+import com.android.volley.Response;
|
|
|
+import com.android.volley.VolleyError;
|
|
|
+import com.xzjmyk.pm.activity.AppConfig;
|
|
|
+import com.xzjmyk.pm.activity.MyApplication;
|
|
|
import com.xzjmyk.pm.activity.R;
|
|
|
+import com.xzjmyk.pm.activity.bean.LoginRegisterResult;
|
|
|
+import com.xzjmyk.pm.activity.bean.User;
|
|
|
+import com.xzjmyk.pm.activity.db.dao.UserDao;
|
|
|
+import com.xzjmyk.pm.activity.helper.LoginHelper;
|
|
|
+import com.xzjmyk.pm.activity.sp.UserSp;
|
|
|
+import com.xzjmyk.pm.activity.util.DeviceInfoUtil;
|
|
|
+import com.xzjmyk.pm.activity.util.Md5Util;
|
|
|
+
|
|
|
+import java.util.HashMap;
|
|
|
|
|
|
public class Result {
|
|
|
/**
|
|
|
@@ -55,6 +68,7 @@ public class Result {
|
|
|
} else if (result.resultCode == CODE_TOKEN_ERROR) {// Token过期或错误
|
|
|
//TODO 发出异常登录的广播
|
|
|
Log.i("gongpengming", "发出异常登录的广播2");
|
|
|
+ loginIM(context);
|
|
|
// LoginHelper.broadcastToken(context);
|
|
|
// LoginHelper.broadcastConflict(context);
|
|
|
if (showToast)
|
|
|
@@ -70,6 +84,55 @@ public class Result {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ //当发现taken过期时候重新登陆
|
|
|
+ public static void loginIM(final Context context) {
|
|
|
+ String userId = UserSp.getInstance(context).getUserId("");
|
|
|
+ User user = UserDao.getInstance().getUserByUserId(userId);
|
|
|
+ final String phoneNumber = user.getTelephone();
|
|
|
+ final String password = user.getPassword();
|
|
|
+ AppConfig mConfig = MyApplication.getInstance().getConfig();
|
|
|
+ // 加密之后的密码
|
|
|
+ final String requestTag = "login";
|
|
|
+ HashMap<String, String> params = new HashMap<String, String>();
|
|
|
+ params.put("telephone", Md5Util.toMD5(phoneNumber));// 账号登陆的时候需要MD5加密,服务器需求
|
|
|
+ params.put("password", password);
|
|
|
+ // 附加信息
|
|
|
+ params.put("model", DeviceInfoUtil.getModel());
|
|
|
+ params.put("osVersion", DeviceInfoUtil.getOsVersion());
|
|
|
+ params.put("serial", DeviceInfoUtil.getDeviceId(context));
|
|
|
+ // 地址信息
|
|
|
+ double latitude = MyApplication.getInstance().getBdLocationHelper().getLatitude();
|
|
|
+ double longitude = MyApplication.getInstance().getBdLocationHelper().getLongitude();
|
|
|
+ if (latitude != 0)
|
|
|
+ params.put("latitude", String.valueOf(latitude));
|
|
|
+ if (longitude != 0)
|
|
|
+ params.put("longitude", String.valueOf(longitude));
|
|
|
+ final StringJsonObjectRequest<LoginRegisterResult> request = new StringJsonObjectRequest<LoginRegisterResult>(mConfig.USER_LOGIN,
|
|
|
+ new Response.ErrorListener() {
|
|
|
+ @Override
|
|
|
+ public void onErrorResponse(VolleyError arg0) {
|
|
|
+ }
|
|
|
+ }, new StringJsonObjectRequest.Listener<LoginRegisterResult>() {
|
|
|
+ @Override
|
|
|
+ public void onResponse(ObjectResult<LoginRegisterResult> result) {
|
|
|
+ if (result == null) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ boolean success = false;
|
|
|
+ if (result.getResultCode() == Result.CODE_SUCCESS) {
|
|
|
+ success = LoginHelper.setLoginUser(context, phoneNumber, password, result);// 设置登陆用户信息
|
|
|
+ }
|
|
|
+ if (success) {// 登陆IM成功
|
|
|
+
|
|
|
+ } else {// 登录失败
|
|
|
+
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }, LoginRegisterResult.class, params);
|
|
|
+ request.setTag(requestTag);
|
|
|
+ MyApplication.getInstance().getFastVolley().addDefaultRequest("Result", request);
|
|
|
+ }
|
|
|
+
|
|
|
private static void showResultToast(Context context, Result result) {
|
|
|
if (TextUtils.isEmpty(result.resultMsg)) {
|
|
|
Toast.makeText(context, context.getString(R.string.data_exception), Toast.LENGTH_SHORT).show();
|