mirror of
https://gitee.com/binary/weixin-java-tools.git
synced 2025-08-24 07:23:01 +08:00
为WxMpConfigStorage接口增加autoRefreshToken方法,以方便客户端设置是否自动刷新token. for #77
This commit is contained in:
parent
a37a869a30
commit
088a97221e
@ -100,4 +100,9 @@ public interface WxMpConfigStorage {
|
||||
* @return ApacheHttpClientBuilder
|
||||
*/
|
||||
ApacheHttpClientBuilder getApacheHttpClientBuilder();
|
||||
|
||||
/**
|
||||
* 是否自动刷新token
|
||||
*/
|
||||
boolean autoRefreshToken();
|
||||
}
|
||||
|
@ -270,6 +270,11 @@ public class WxMpInMemoryConfigStorage implements WxMpConfigStorage {
|
||||
return this.apacheHttpClientBuilder;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean autoRefreshToken() {
|
||||
return true;
|
||||
}
|
||||
|
||||
public void setApacheHttpClientBuilder(ApacheHttpClientBuilder apacheHttpClientBuilder) {
|
||||
this.apacheHttpClientBuilder = apacheHttpClientBuilder;
|
||||
}
|
||||
|
@ -101,6 +101,7 @@ public class WxMpServiceImpl implements WxMpService {
|
||||
if (forceRefresh) {
|
||||
this.configStorage.expireAccessToken();
|
||||
}
|
||||
|
||||
if (this.configStorage.isAccessTokenExpired()) {
|
||||
synchronized (this.globalAccessTokenRefreshLock) {
|
||||
if (this.configStorage.isAccessTokenExpired()) {
|
||||
@ -411,8 +412,11 @@ public class WxMpServiceImpl implements WxMpService {
|
||||
if (error.getErrorCode() == 42001 || error.getErrorCode() == 40001) {
|
||||
// 强制设置wxMpConfigStorage它的access token过期了,这样在下一次请求里就会刷新access token
|
||||
this.configStorage.expireAccessToken();
|
||||
return this.execute(executor, uri, data);
|
||||
if(this.configStorage.autoRefreshToken()){
|
||||
return this.execute(executor, uri, data);
|
||||
}
|
||||
}
|
||||
|
||||
if (error.getErrorCode() != 0) {
|
||||
this.log.error("\n[URL]: {}\n[PARAMS]: {}\n[RESPONSE]: {}", uri, data,
|
||||
error);
|
||||
|
Loading…
Reference in New Issue
Block a user