🎨 #1381 企业微信模块配置类增加autoRefreshToken参数配置,方便控制是否自动刷新access_token

This commit is contained in:
Binary Wang 2020-02-22 21:37:53 +08:00
parent 2e2d5ffb56
commit 8b280f4eb1
6 changed files with 28 additions and 2 deletions

View File

@ -281,7 +281,9 @@ public abstract class BaseWxCpServiceImpl<H, P> implements WxCpService, RequestH
if (error.getErrorCode() == 42001 || error.getErrorCode() == 40001 || error.getErrorCode() == 40014) { if (error.getErrorCode() == 42001 || error.getErrorCode() == 40001 || error.getErrorCode() == 40014) {
// 强制设置wxCpConfigStorage它的access token过期了这样在下一次请求里就会刷新access token // 强制设置wxCpConfigStorage它的access token过期了这样在下一次请求里就会刷新access token
this.configStorage.expireAccessToken(); this.configStorage.expireAccessToken();
return execute(executor, uri, data); if (this.getWxCpConfigStorage().autoRefreshToken()) {
return this.execute(executor, uri, data);
}
} }
if (error.getErrorCode() != 0) { if (error.getErrorCode() != 0) {

View File

@ -194,7 +194,9 @@ public abstract class BaseWxCpTpServiceImpl<H, P> implements WxCpTpService, Requ
if (error.getErrorCode() == 42009) { if (error.getErrorCode() == 42009) {
// 强制设置wxCpTpConfigStorage它的suite access token过期了这样在下一次请求里就会刷新suite access token // 强制设置wxCpTpConfigStorage它的suite access token过期了这样在下一次请求里就会刷新suite access token
this.configStorage.expireSuiteAccessToken(); this.configStorage.expireSuiteAccessToken();
return execute(executor, uri, data); if (this.getWxCpTpConfigStorage().autoRefreshToken()) {
return this.execute(executor, uri, data);
}
} }
if (error.getErrorCode() != 0) { if (error.getErrorCode() != 0) {

View File

@ -97,4 +97,10 @@ public interface WxCpConfigStorage {
* @return ApacheHttpClientBuilder * @return ApacheHttpClientBuilder
*/ */
ApacheHttpClientBuilder getApacheHttpClientBuilder(); ApacheHttpClientBuilder getApacheHttpClientBuilder();
/**
* 是否自动刷新token
* @return .
*/
boolean autoRefreshToken();
} }

View File

@ -83,4 +83,10 @@ public interface WxCpTpConfigStorage {
* @return ApacheHttpClientBuilder * @return ApacheHttpClientBuilder
*/ */
ApacheHttpClientBuilder getApacheHttpClientBuilder(); ApacheHttpClientBuilder getApacheHttpClientBuilder();
/**
* 是否自动刷新token
* @return .
*/
boolean autoRefreshToken();
} }

View File

@ -262,6 +262,11 @@ public class WxCpDefaultConfigImpl implements WxCpConfigStorage, Serializable {
return this.apacheHttpClientBuilder; return this.apacheHttpClientBuilder;
} }
@Override
public boolean autoRefreshToken() {
return true;
}
public void setApacheHttpClientBuilder(ApacheHttpClientBuilder apacheHttpClientBuilder) { public void setApacheHttpClientBuilder(ApacheHttpClientBuilder apacheHttpClientBuilder) {
this.apacheHttpClientBuilder = apacheHttpClientBuilder; this.apacheHttpClientBuilder = apacheHttpClientBuilder;
} }

View File

@ -242,6 +242,11 @@ public class WxCpTpDefaultConfigImpl implements WxCpTpConfigStorage, Serializabl
return this.apacheHttpClientBuilder; return this.apacheHttpClientBuilder;
} }
@Override
public boolean autoRefreshToken() {
return true;
}
public void setApacheHttpClientBuilder(ApacheHttpClientBuilder apacheHttpClientBuilder) { public void setApacheHttpClientBuilder(ApacheHttpClientBuilder apacheHttpClientBuilder) {
this.apacheHttpClientBuilder = apacheHttpClientBuilder; this.apacheHttpClientBuilder = apacheHttpClientBuilder;
} }