diff --git a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/WxMpService.java b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/WxMpService.java index a74e718db5..658d239bdf 100644 --- a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/WxMpService.java +++ b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/WxMpService.java @@ -43,6 +43,14 @@ public interface WxMpService { */ String getAccessToken(boolean forceRefresh) throws WxErrorException; + + /** + *
+   * 强制accessToken过期
+   * 
+ */ + void expireAccessToken(); + /** * 获得jsapi_ticket,不强制刷新jsapi_ticket * diff --git a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/impl/WxMpServiceImpl.java b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/impl/WxMpServiceImpl.java index 87cf7397dd..7e6ffb9524 100644 --- a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/impl/WxMpServiceImpl.java +++ b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/impl/WxMpServiceImpl.java @@ -99,7 +99,7 @@ public String getAccessToken() throws WxErrorException { @Override public String getAccessToken(boolean forceRefresh) throws WxErrorException { if (forceRefresh) { - this.configStorage.expireAccessToken(); + expireAccessToken(); } if (this.configStorage.isAccessTokenExpired()) { synchronized (this.globalAccessTokenRefreshLock) { @@ -134,6 +134,11 @@ public String getAccessToken(boolean forceRefresh) throws WxErrorException { return this.configStorage.getAccessToken(); } + @Override + public void expireAccessToken(){ + this.configStorage.expireAccessToken(); + } + @Override public String getJsapiTicket() throws WxErrorException { return getJsapiTicket(false); @@ -410,8 +415,10 @@ protected synchronized T executeInternal(RequestExecutor executor, */ if (error.getErrorCode() == 42001 || error.getErrorCode() == 40001) { // 强制设置wxMpConfigStorage它的access token过期了,这样在下一次请求里就会刷新access token - this.configStorage.expireAccessToken(); - return this.execute(executor, uri, data); + //this.configStorage.expireAccessToken(); + //return this.execute(executor, uri, data); + //此方法可被重写 + expireAccessToken(); } if (error.getErrorCode() != 0) { this.log.error("\n[URL]: {}\n[PARAMS]: {}\n[RESPONSE]: {}", uri, data,