Skip to content

Commit

Permalink
🎨 #1381 企业微信模块配置类增加autoRefreshToken参数配置,方便控制是否自动刷新access_token
Browse files Browse the repository at this point in the history
  • Loading branch information
binarywang committed Feb 22, 2020
1 parent 2e2d5ff commit 8b280f4
Show file tree
Hide file tree
Showing 6 changed files with 28 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -281,7 +281,9 @@ protected <T, E> T executeInternal(RequestExecutor<T, E> executor, String uri, E
if (error.getErrorCode() == 42001 || error.getErrorCode() == 40001 || error.getErrorCode() == 40014) {
// 强制设置wxCpConfigStorage它的access token过期了,这样在下一次请求里就会刷新access token
this.configStorage.expireAccessToken();
return execute(executor, uri, data);
if (this.getWxCpConfigStorage().autoRefreshToken()) {
return this.execute(executor, uri, data);
}
}

if (error.getErrorCode() != 0) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,9 @@ protected <T, E> T executeInternal(RequestExecutor<T, E> executor, String uri, E
if (error.getErrorCode() == 42009) {
// 强制设置wxCpTpConfigStorage它的suite access token过期了,这样在下一次请求里就会刷新suite access token
this.configStorage.expireSuiteAccessToken();
return execute(executor, uri, data);
if (this.getWxCpTpConfigStorage().autoRefreshToken()) {
return this.execute(executor, uri, data);
}
}

if (error.getErrorCode() != 0) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,4 +97,10 @@ public interface WxCpConfigStorage {
* @return ApacheHttpClientBuilder
*/
ApacheHttpClientBuilder getApacheHttpClientBuilder();

/**
* 是否自动刷新token
* @return .
*/
boolean autoRefreshToken();
}
Original file line number Diff line number Diff line change
Expand Up @@ -83,4 +83,10 @@ public interface WxCpTpConfigStorage {
* @return ApacheHttpClientBuilder
*/
ApacheHttpClientBuilder getApacheHttpClientBuilder();

/**
* 是否自动刷新token
* @return .
*/
boolean autoRefreshToken();
}
Original file line number Diff line number Diff line change
Expand Up @@ -262,6 +262,11 @@ public ApacheHttpClientBuilder getApacheHttpClientBuilder() {
return this.apacheHttpClientBuilder;
}

@Override
public boolean autoRefreshToken() {
return true;
}

public void setApacheHttpClientBuilder(ApacheHttpClientBuilder apacheHttpClientBuilder) {
this.apacheHttpClientBuilder = apacheHttpClientBuilder;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -242,6 +242,11 @@ public ApacheHttpClientBuilder getApacheHttpClientBuilder() {
return this.apacheHttpClientBuilder;
}

@Override
public boolean autoRefreshToken() {
return true;
}

public void setApacheHttpClientBuilder(ApacheHttpClientBuilder apacheHttpClientBuilder) {
this.apacheHttpClientBuilder = apacheHttpClientBuilder;
}
Expand Down

0 comments on commit 8b280f4

Please sign in to comment.