🎨 优化重构部分代码,抽取公共常量

This commit is contained in:
Binary Wang
2020-08-23 17:02:39 +08:00
parent 817b474dd0
commit 6d996f20b9
6 changed files with 29 additions and 57 deletions

View File

@@ -146,14 +146,8 @@ public class WxOpenComponentServiceImpl implements WxOpenComponentService {
return getWxOpenService().post(uriWithComponentAccessToken, postData);
} catch (WxErrorException e) {
WxError error = e.getError();
/*
* 发生以下情况时尝试刷新access_token
* 40001 获取access_token时AppSecret错误或者access_token无效
* 42001 access_token超时
* 40014 不合法的access_token请开发者认真比对access_token的有效性如是否过期或查看是否正在为恰当的公众号调用接口
*/
if (error.getErrorCode() == 42001 || error.getErrorCode() == 40001 || error.getErrorCode() == 40014) {
// 强制设置wxMpConfigStorage它的access token过期了这样在下一次请求里就会刷新access token
if (WxConsts.ACCESS_TOKEN_ERROR_CODES.contains(error.getErrorCode())) {
// 强制设置access token过期这样在下一次请求里就会刷新access token
Lock lock = this.getWxOpenConfigStorage().getComponentAccessTokenLock();
lock.lock();
try {
@@ -190,13 +184,7 @@ public class WxOpenComponentServiceImpl implements WxOpenComponentService {
return getWxOpenService().get(uriWithComponentAccessToken, null);
} catch (WxErrorException e) {
WxError error = e.getError();
/*
* 发生以下情况时尝试刷新access_token
* 40001 获取access_token时AppSecret错误或者access_token无效
* 42001 access_token超时
* 40014 不合法的access_token请开发者认真比对access_token的有效性如是否过期或查看是否正在为恰当的公众号调用接口
*/
if (error.getErrorCode() == 42001 || error.getErrorCode() == 40001 || error.getErrorCode() == 40014) {
if (WxConsts.ACCESS_TOKEN_ERROR_CODES.contains(error.getErrorCode())) {
// 强制设置wxMpConfigStorage它的access token过期了这样在下一次请求里就会刷新access token
Lock lock = this.getWxOpenConfigStorage().getComponentAccessTokenLock();
lock.lock();