Skip to content

Commit 532c1af

Browse files
committed
#324: 修复分布式刷新access_token冲突问题
1 parent b79370a commit 532c1af

File tree

6 files changed

+6
-27
lines changed

6 files changed

+6
-27
lines changed

weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/impl/WxCpServiceApacheHttpClientImpl.java

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -38,10 +38,7 @@ public HttpType getRequestType() {
3838

3939
@Override
4040
public String getAccessToken(boolean forceRefresh) throws WxErrorException {
41-
if (forceRefresh) {
42-
this.configStorage.expireAccessToken();
43-
}
44-
if (this.configStorage.isAccessTokenExpired()) {
41+
if (this.configStorage.isAccessTokenExpired() || forceRefresh) {
4542
synchronized (this.globalAccessTokenRefreshLock) {
4643
if (this.configStorage.isAccessTokenExpired()) {
4744
String url = "https://qyapi.weixin.qq.com/cgi-bin/gettoken?"

weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/impl/WxCpServiceJoddHttpImpl.java

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,10 +29,7 @@ public HttpType getRequestType() {
2929

3030
@Override
3131
public String getAccessToken(boolean forceRefresh) throws WxErrorException {
32-
if (forceRefresh) {
33-
this.configStorage.expireAccessToken();
34-
}
35-
if (this.configStorage.isAccessTokenExpired()) {
32+
if (this.configStorage.isAccessTokenExpired() || forceRefresh) {
3633
synchronized (this.globalAccessTokenRefreshLock) {
3734
if (this.configStorage.isAccessTokenExpired()) {
3835
String url = "https://qyapi.weixin.qq.com/cgi-bin/gettoken?"

weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/impl/WxCpServiceOkHttpImpl.java

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -37,10 +37,7 @@ public HttpType getRequestType() {
3737
@Override
3838
public String getAccessToken(boolean forceRefresh) throws WxErrorException {
3939
logger.debug("WxCpServiceOkHttpImpl is running");
40-
if (forceRefresh) {
41-
this.configStorage.expireAccessToken();
42-
}
43-
if (this.configStorage.isAccessTokenExpired()) {
40+
if (this.configStorage.isAccessTokenExpired() || forceRefresh) {
4441
synchronized (this.globalAccessTokenRefreshLock) {
4542
if (this.configStorage.isAccessTokenExpired()) {
4643
String url = "https://qyapi.weixin.qq.com/cgi-bin/gettoken?"

weixin-java-miniapp/src/main/java/cn/binarywang/wx/miniapp/api/impl/WxMaServiceImpl.java

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -87,11 +87,7 @@ public String getAccessToken(boolean forceRefresh) throws WxErrorException {
8787
try {
8888
lock.lock();
8989

90-
if (forceRefresh) {
91-
this.getWxMaConfig().expireAccessToken();
92-
}
93-
94-
if (this.getWxMaConfig().isAccessTokenExpired()) {
90+
if (this.getWxMaConfig().isAccessTokenExpired() || forceRefresh) {
9591
String url = String.format(WxMaService.GET_ACCESS_TOKEN_URL, this.getWxMaConfig().getAppid(),
9692
this.getWxMaConfig().getSecret());
9793
try {

weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/impl/WxMpServiceJoddHttpImpl.java

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -51,11 +51,7 @@ public String getAccessToken(boolean forceRefresh) throws WxErrorException {
5151
try {
5252
lock.lock();
5353

54-
if (forceRefresh) {
55-
this.getWxMpConfigStorage().expireAccessToken();
56-
}
57-
58-
if (this.getWxMpConfigStorage().isAccessTokenExpired()) {
54+
if (this.getWxMpConfigStorage().isAccessTokenExpired() || forceRefresh) {
5955
String url = String.format(WxMpService.GET_ACCESS_TOKEN_URL,
6056
this.getWxMpConfigStorage().getAppId(), this.getWxMpConfigStorage().getSecret());
6157

weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/impl/WxMpServiceOkHttpImpl.java

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -43,11 +43,7 @@ public String getAccessToken(boolean forceRefresh) throws WxErrorException {
4343
try {
4444
lock.lock();
4545

46-
if (forceRefresh) {
47-
this.getWxMpConfigStorage().expireAccessToken();
48-
}
49-
50-
if (this.getWxMpConfigStorage().isAccessTokenExpired()) {
46+
if (this.getWxMpConfigStorage().isAccessTokenExpired() || forceRefresh) {
5147
String url = String.format(WxMpService.GET_ACCESS_TOKEN_URL,
5248
this.getWxMpConfigStorage().getAppId(), this.getWxMpConfigStorage().getSecret());
5349

0 commit comments

Comments
 (0)