diff --git a/app/build.gradle b/app/build.gradle index 6c29e491b9..4bbc856b4e 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -57,6 +57,7 @@ android { buildConfigField "String", "WEIBO_APPKEY", "\"${WEIBO_APPKEY}\"" buildConfigField "String", "MTA_APPKEY", "\"${MTA_APPKEY}\"" buildConfigField "String", "TD_APPID", "\"${TD_APPID}\"" + buildConfigField "String", "PATCH_VERSION_NAME", "\"${PATCH_VERSION_NAME}\"" } diff --git a/app/src/main/java/com/gh/common/constant/Config.java b/app/src/main/java/com/gh/common/constant/Config.java index 603325fbf4..b61496c8c2 100644 --- a/app/src/main/java/com/gh/common/constant/Config.java +++ b/app/src/main/java/com/gh/common/constant/Config.java @@ -37,6 +37,7 @@ public class Config { public static final String USERSEA_APP_ID = BuildConfig.USERSEA_APP_ID; // 登录验证 public static final String USERSEA_APP_SECRET = BuildConfig.USERSEA_APP_SECRET; // 登录验证 public static final String BUGLY_APPID = BuildConfig.BUGLY_APPID; + public static final String PATCH_VERSION_NAME = BuildConfig.PATCH_VERSION_NAME; // 补丁包版本 对应关于->版本号 // http://www.ghzs666.com/article/${articleId}.html public static final String URL_ARTICLE = "http://www.ghzs666.com/article/"; // TODO ghzs/ghzs666 统一 diff --git a/app/src/main/java/com/gh/common/util/LoginUtils.java b/app/src/main/java/com/gh/common/util/LoginUtils.java index bb1475e3fc..2249a6dc63 100644 --- a/app/src/main/java/com/gh/common/util/LoginUtils.java +++ b/app/src/main/java/com/gh/common/util/LoginUtils.java @@ -207,26 +207,13 @@ public class LoginUtils { JSONObject content = new JSONObject(string); int code = content.getInt("code"); - if (loginTag == LoginTag.refresh && code == 40802) { -// JSONObject device = content.getJSONObject("device"); -// String manufacturer = device.getString("manufacturer"); -// -// String model = device.getString("model"); -// -// DialogUtils.showAlertDialog(context, "你的账号已在另外一台设备登录" -// , StringUtils.buildString("(", manufacturer, "-", model, ")") -// , "知道了", null, null, null); -// -// LoginUtils.cleanUserData(context); + if (loginTag.equals(LoginTag.phone)) { + outputErrorHint(context, code); } else { - if (loginTag.equals(LoginTag.phone)) { - outputErrorHint(context, code); - } else { - if (loginTag.equals(LoginTag.qq)) { - GetLoginDataUtils.getInstance(context).QQLogout(); - } - Utils.toast(context, context.getString(R.string.login_failure_hint)); + if (loginTag.equals(LoginTag.qq)) { + GetLoginDataUtils.getInstance(context).QQLogout(); } + Utils.toast(context, context.getString(R.string.login_failure_hint)); } } catch (Exception e1) { e1.printStackTrace(); diff --git a/app/src/main/java/com/gh/gamecenter/AboutActivity.java b/app/src/main/java/com/gh/gamecenter/AboutActivity.java index f479137afb..a90ddbbe6f 100644 --- a/app/src/main/java/com/gh/gamecenter/AboutActivity.java +++ b/app/src/main/java/com/gh/gamecenter/AboutActivity.java @@ -12,6 +12,7 @@ import android.widget.RelativeLayout; import android.widget.TextView; import com.gh.base.BaseActivity; +import com.gh.common.constant.Config; import com.gh.common.util.StringUtils; import com.gh.gamecenter.manager.UpdateManager; @@ -51,7 +52,7 @@ public class AboutActivity extends BaseActivity { initTitle(getString(R.string.title_about)); // ((TextView) findViewById(R.id.about_tv_version)).setText("V" + PackageUtils.getVersionName(this)); - ((TextView) findViewById(R.id.about_tv_version)).setText("V3.0.0"); // TODO 版本号暂时与gradle versionName不一致 + ((TextView) findViewById(R.id.about_tv_version)).setText(Config.PATCH_VERSION_NAME); // TODO 版本号暂时与gradle versionName不一致 } @Override diff --git a/app/src/main/java/com/gh/gamecenter/retrofit/OkHttpRetryInterceptor.kt b/app/src/main/java/com/gh/gamecenter/retrofit/OkHttpRetryInterceptor.kt index 63b8e800fc..94a44d61f9 100644 --- a/app/src/main/java/com/gh/gamecenter/retrofit/OkHttpRetryInterceptor.kt +++ b/app/src/main/java/com/gh/gamecenter/retrofit/OkHttpRetryInterceptor.kt @@ -56,8 +56,8 @@ class OkHttpRetryInterceptor internal constructor(context: Context) : Intercepto CommonDebug.logMethodWithParams(this, "Retrying ${request.url()} for $tryCount") } - if (url.contains("user/info") && TextUtils.isEmpty(request.header("Content-Type"))) { // 过滤在当前类请求的 userinfo - tryCount =3 + if (url.contains("user/info") && !TextUtils.isEmpty(request.header("Content-Type"))) { // 过滤在当前类请求的 userinfo + tryCount = 3 break } @@ -92,7 +92,7 @@ class OkHttpRetryInterceptor internal constructor(context: Context) : Intercepto RetrofitManager.getInstance(mContext) .getApi() .getRetryUserInfo() - .subscribe(object : com.gh.gamecenter.retrofit.Response(){ + .subscribe(object : com.gh.gamecenter.retrofit.Response() { override fun onResponse(userInfo: UserInfoEntity?) { super.onResponse(userInfo) LoginUtils.saveUserInfo(mContext, userInfo) @@ -100,11 +100,13 @@ class OkHttpRetryInterceptor internal constructor(context: Context) : Intercepto newBuilder.header("TOKEN", loginResponseEntity?.accessToken?.value) request = newBuilder.build() response = doRequest(chain, request) + EventBus.getDefault().post(EBReuse(PersonalFragment.LOGIN_TAG)) } override fun onFailure(e: HttpException?) { super.onFailure(e) LoginUtils.cleanUserData(mContext) + EventBus.getDefault().post(EBReuse(PersonalFragment.LOGOUT_TAG)) } }) } @@ -115,6 +117,13 @@ class OkHttpRetryInterceptor internal constructor(context: Context) : Intercepto val responseBody = e?.response()?.errorBody() val string = responseBody?.string() Utils.log("=======string::" + string) + + // 如果当前token 与sp存储的token不一致 证明token已经被刷新过 无需处理当前访问异常 + if (!token.equals(LoginUtils.getToken(mContext))){ + tryCount = 4 + return + } + val content = JSONObject(string) val code = content.getInt("code") LoginUtils.cleanUserData(mContext) @@ -133,6 +142,7 @@ class OkHttpRetryInterceptor internal constructor(context: Context) : Intercepto } else { // 重新登录 LoginUtils.cleanUserData(mContext) + EventBus.getDefault().post(EBReuse(PersonalFragment.LOGOUT_TAG)) Utils.toast(mContext, "账号过期,请重新登录!") } } else { // 网络错误处理 diff --git a/gradle.properties b/gradle.properties index 9d0b118ffd..5228b75f57 100644 --- a/gradle.properties +++ b/gradle.properties @@ -19,6 +19,8 @@ org.gradle.parallel=true # channel packages channel_file=channel.txt +PATCH_VERSION_NAME=3.0.1 + # Third-party keys DEBUG_UMENG_APPKEY=58e5b0b9c62dca35a00005e6 DEBUG_UMENG_MESSAGE_SECRET=ca08596492f8a7fde2ab48dceab8c1f3