登录失败提示
This commit is contained in:
@ -6,6 +6,7 @@ import android.content.SharedPreferences;
|
||||
import android.preference.PreferenceManager;
|
||||
import android.text.TextUtils;
|
||||
|
||||
import com.gh.gamecenter.R;
|
||||
import com.gh.gamecenter.entity.LoginResponseEntity;
|
||||
import com.gh.gamecenter.entity.UserInfoEntity;
|
||||
import com.gh.gamecenter.retrofit.JSONObjectResponse;
|
||||
@ -181,38 +182,27 @@ public class LoginUtils {
|
||||
}
|
||||
saveLoginToken(context, response);
|
||||
|
||||
|
||||
String token = response.getAccessToken().getValue();
|
||||
|
||||
if (loginTag == LoginTag.oldUserPhone) {
|
||||
SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(context);
|
||||
String syncDeviceID = sp.getString("syncDeviceID", null);
|
||||
if (!TextUtils.isEmpty(syncDeviceID)) {
|
||||
syncUserData(context, syncDeviceID, token, listener, loginTag);
|
||||
syncUserData(context, syncDeviceID, listener, loginTag);
|
||||
return;
|
||||
}
|
||||
}
|
||||
getUserData(context, token, listener, loginTag);
|
||||
getUserData(context, listener, loginTag);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onFailure(HttpException e) {
|
||||
super.onFailure(e);
|
||||
if (e == null) {
|
||||
Utils.toast(context, "请检查网络是否可用");
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
ResponseBody responseBody = e.response().errorBody();
|
||||
String string = responseBody.string();
|
||||
Utils.log("=======string::" + string);
|
||||
JSONObject content = new JSONObject(string);
|
||||
int code = content.getInt("code");
|
||||
|
||||
if (loginTag == LoginTag.refresh && code == 40802) {
|
||||
|
||||
Utils.log("=======40802::" + string);
|
||||
JSONObject device = content.getJSONObject("device");
|
||||
String manufacturer = device.getString("manufacturer");
|
||||
|
||||
@ -223,9 +213,11 @@ public class LoginUtils {
|
||||
, "知道了", null, null, null);
|
||||
|
||||
LoginUtils.cleanUserData(context);
|
||||
// TODO 要不要调用退出登录接口
|
||||
} else {
|
||||
outputErrorHint(context, code);
|
||||
Utils.toast(context, context.getString(R.string.login_failure_hint));
|
||||
if (loginTag.equals(LoginTag.qq)) {
|
||||
GetLoginDataUtils.getInstance(context).QQLogout();
|
||||
}
|
||||
}
|
||||
} catch (Exception e1) {
|
||||
e1.printStackTrace();
|
||||
@ -235,7 +227,7 @@ public class LoginUtils {
|
||||
});
|
||||
}
|
||||
|
||||
private static void syncUserData(final Context context, String syncDeviceID, final String token
|
||||
private static void syncUserData(final Context context, String syncDeviceID
|
||||
, final onLoginCallBackListener listener, final LoginTag loginTag) {
|
||||
|
||||
HashMap<String, String> map = new HashMap<>();
|
||||
@ -248,26 +240,26 @@ public class LoginUtils {
|
||||
@Override
|
||||
public void onResponse(ResponseBody response) {
|
||||
super.onResponse(response);
|
||||
getUserData(context, token, listener, loginTag);
|
||||
getUserData(context, listener, loginTag);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onFailure(HttpException e) {
|
||||
super.onFailure(e);
|
||||
if (e == null) {
|
||||
Utils.toast(context, "请检查网络是否可用");
|
||||
return;
|
||||
}
|
||||
try {
|
||||
ResponseBody responseBody = e.response().errorBody();
|
||||
String string = responseBody.string();
|
||||
JSONObject content = new JSONObject(string);
|
||||
int code = content.getInt("code");
|
||||
outputErrorHint(context, code);
|
||||
} catch (Exception e1) {
|
||||
e1.printStackTrace();
|
||||
}
|
||||
getUserData(context, token, listener, loginTag);
|
||||
// if (e == null) {
|
||||
// Utils.toast(context, "请检查网络是否可用");
|
||||
// return;
|
||||
// }
|
||||
// try {
|
||||
// ResponseBody responseBody = e.response().errorBody();
|
||||
// String string = responseBody.string();
|
||||
// JSONObject content = new JSONObject(string);
|
||||
// int code = content.getInt("code");
|
||||
// outputErrorHint(context, code);
|
||||
// } catch (Exception e1) {
|
||||
// e1.printStackTrace();
|
||||
// }
|
||||
getUserData(context, listener, loginTag);
|
||||
}
|
||||
});
|
||||
}
|
||||
@ -330,7 +322,7 @@ public class LoginUtils {
|
||||
LoginResponseEntity.AccessToken accessToken = loginToken.getAccessToken();
|
||||
Long accessExpire = accessToken.getExpire();
|
||||
if (accessExpire != null && accessExpire > Utils.getTime(context)) {
|
||||
getUserData(context, accessToken.getValue(), listener, null);
|
||||
getUserData(context, listener, null);
|
||||
} else {
|
||||
LoginResponseEntity.RefreshToken refreshToken = loginToken.getRefreshToken();
|
||||
Long refreshExpire = refreshToken.getExpire();
|
||||
@ -347,7 +339,7 @@ public class LoginUtils {
|
||||
}
|
||||
|
||||
// 获取用户信息
|
||||
public static void getUserData(final Context context, String token, final onLoginCallBackListener listener, final LoginTag loginTag) {
|
||||
public static void getUserData(final Context context, final onLoginCallBackListener listener, final LoginTag loginTag) {
|
||||
RetrofitManager.getInstance(context)
|
||||
.getApi()
|
||||
.getUserInfo()
|
||||
@ -367,20 +359,24 @@ public class LoginUtils {
|
||||
@Override
|
||||
public void onFailure(HttpException e) {
|
||||
super.onFailure(e);
|
||||
if (e == null) {
|
||||
Utils.toast(context, "请检查网络是否可用");
|
||||
return;
|
||||
}
|
||||
try {
|
||||
ResponseBody responseBody = e.response().errorBody();
|
||||
String string = responseBody.string();
|
||||
Utils.log("getUserData::" + string);
|
||||
JSONObject content = new JSONObject(string);
|
||||
int code = content.getInt("code");
|
||||
outputErrorHint(context, code);
|
||||
} catch (Exception e1) {
|
||||
e1.printStackTrace();
|
||||
Utils.toast(context, context.getString(R.string.login_failure_hint));
|
||||
if (loginTag.equals(LoginTag.qq)) {
|
||||
GetLoginDataUtils.getInstance(context).QQLogout();
|
||||
}
|
||||
// if (e == null) {
|
||||
// Utils.toast(context, "请检查网络是否可用");
|
||||
// return;
|
||||
// }
|
||||
// try {
|
||||
// ResponseBody responseBody = e.response().errorBody();
|
||||
// String string = responseBody.string();
|
||||
// Utils.log("getUserData::" + string);
|
||||
// JSONObject content = new JSONObject(string);
|
||||
// int code = content.getInt("code");
|
||||
// outputErrorHint(context, code);
|
||||
// } catch (Exception e1) {
|
||||
// e1.printStackTrace();
|
||||
// }
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user