mirror of
				https://gitee.com/binary/weixin-java-tools.git
				synced 2025-11-01 03:25:35 +08:00 
			
		
		
		
	#324: 修复分布式刷新access_token冲突问题
This commit is contained in:
		| @ -38,10 +38,7 @@ public class WxCpServiceApacheHttpClientImpl extends WxCpServiceAbstractImpl<Clo | |||||||
|  |  | ||||||
|   @Override |   @Override | ||||||
|   public String getAccessToken(boolean forceRefresh) throws WxErrorException { |   public String getAccessToken(boolean forceRefresh) throws WxErrorException { | ||||||
|     if (forceRefresh) { |     if (this.configStorage.isAccessTokenExpired() || forceRefresh) { | ||||||
|       this.configStorage.expireAccessToken(); |  | ||||||
|     } |  | ||||||
|     if (this.configStorage.isAccessTokenExpired()) { |  | ||||||
|       synchronized (this.globalAccessTokenRefreshLock) { |       synchronized (this.globalAccessTokenRefreshLock) { | ||||||
|         if (this.configStorage.isAccessTokenExpired()) { |         if (this.configStorage.isAccessTokenExpired()) { | ||||||
|           String url = "https://qyapi.weixin.qq.com/cgi-bin/gettoken?" |           String url = "https://qyapi.weixin.qq.com/cgi-bin/gettoken?" | ||||||
|  | |||||||
| @ -29,10 +29,7 @@ public class WxCpServiceJoddHttpImpl extends WxCpServiceAbstractImpl<HttpConnect | |||||||
|  |  | ||||||
|   @Override |   @Override | ||||||
|   public String getAccessToken(boolean forceRefresh) throws WxErrorException { |   public String getAccessToken(boolean forceRefresh) throws WxErrorException { | ||||||
|     if (forceRefresh) { |     if (this.configStorage.isAccessTokenExpired() || forceRefresh) { | ||||||
|       this.configStorage.expireAccessToken(); |  | ||||||
|     } |  | ||||||
|     if (this.configStorage.isAccessTokenExpired()) { |  | ||||||
|       synchronized (this.globalAccessTokenRefreshLock) { |       synchronized (this.globalAccessTokenRefreshLock) { | ||||||
|         if (this.configStorage.isAccessTokenExpired()) { |         if (this.configStorage.isAccessTokenExpired()) { | ||||||
|           String url = "https://qyapi.weixin.qq.com/cgi-bin/gettoken?" |           String url = "https://qyapi.weixin.qq.com/cgi-bin/gettoken?" | ||||||
|  | |||||||
| @ -37,10 +37,7 @@ public class WxCpServiceOkHttpImpl extends WxCpServiceAbstractImpl<OkHttpClient, | |||||||
|   @Override |   @Override | ||||||
|   public String getAccessToken(boolean forceRefresh) throws WxErrorException { |   public String getAccessToken(boolean forceRefresh) throws WxErrorException { | ||||||
|     logger.debug("WxCpServiceOkHttpImpl is running"); |     logger.debug("WxCpServiceOkHttpImpl is running"); | ||||||
|     if (forceRefresh) { |     if (this.configStorage.isAccessTokenExpired() || forceRefresh) { | ||||||
|       this.configStorage.expireAccessToken(); |  | ||||||
|     } |  | ||||||
|     if (this.configStorage.isAccessTokenExpired()) { |  | ||||||
|       synchronized (this.globalAccessTokenRefreshLock) { |       synchronized (this.globalAccessTokenRefreshLock) { | ||||||
|         if (this.configStorage.isAccessTokenExpired()) { |         if (this.configStorage.isAccessTokenExpired()) { | ||||||
|           String url = "https://qyapi.weixin.qq.com/cgi-bin/gettoken?" |           String url = "https://qyapi.weixin.qq.com/cgi-bin/gettoken?" | ||||||
|  | |||||||
| @ -87,11 +87,7 @@ public class WxMaServiceImpl implements WxMaService, RequestHttp<CloseableHttpCl | |||||||
|     try { |     try { | ||||||
|       lock.lock(); |       lock.lock(); | ||||||
|  |  | ||||||
|       if (forceRefresh) { |       if (this.getWxMaConfig().isAccessTokenExpired() || forceRefresh) { | ||||||
|         this.getWxMaConfig().expireAccessToken(); |  | ||||||
|       } |  | ||||||
|  |  | ||||||
|       if (this.getWxMaConfig().isAccessTokenExpired()) { |  | ||||||
|         String url = String.format(WxMaService.GET_ACCESS_TOKEN_URL, this.getWxMaConfig().getAppid(), |         String url = String.format(WxMaService.GET_ACCESS_TOKEN_URL, this.getWxMaConfig().getAppid(), | ||||||
|           this.getWxMaConfig().getSecret()); |           this.getWxMaConfig().getSecret()); | ||||||
|         try { |         try { | ||||||
|  | |||||||
| @ -51,11 +51,7 @@ public class WxMpServiceJoddHttpImpl extends WxMpServiceAbstractImpl<HttpConnect | |||||||
|     try { |     try { | ||||||
|       lock.lock(); |       lock.lock(); | ||||||
|  |  | ||||||
|       if (forceRefresh) { |       if (this.getWxMpConfigStorage().isAccessTokenExpired() || forceRefresh) { | ||||||
|         this.getWxMpConfigStorage().expireAccessToken(); |  | ||||||
|       } |  | ||||||
|  |  | ||||||
|       if (this.getWxMpConfigStorage().isAccessTokenExpired()) { |  | ||||||
|         String url = String.format(WxMpService.GET_ACCESS_TOKEN_URL, |         String url = String.format(WxMpService.GET_ACCESS_TOKEN_URL, | ||||||
|           this.getWxMpConfigStorage().getAppId(), this.getWxMpConfigStorage().getSecret()); |           this.getWxMpConfigStorage().getAppId(), this.getWxMpConfigStorage().getSecret()); | ||||||
|  |  | ||||||
|  | |||||||
| @ -43,11 +43,7 @@ public class WxMpServiceOkHttpImpl extends WxMpServiceAbstractImpl<OkHttpClient, | |||||||
|     try { |     try { | ||||||
|       lock.lock(); |       lock.lock(); | ||||||
|  |  | ||||||
|       if (forceRefresh) { |       if (this.getWxMpConfigStorage().isAccessTokenExpired() || forceRefresh) { | ||||||
|         this.getWxMpConfigStorage().expireAccessToken(); |  | ||||||
|       } |  | ||||||
|  |  | ||||||
|       if (this.getWxMpConfigStorage().isAccessTokenExpired()) { |  | ||||||
|         String url = String.format(WxMpService.GET_ACCESS_TOKEN_URL, |         String url = String.format(WxMpService.GET_ACCESS_TOKEN_URL, | ||||||
|           this.getWxMpConfigStorage().getAppId(), this.getWxMpConfigStorage().getSecret()); |           this.getWxMpConfigStorage().getAppId(), this.getWxMpConfigStorage().getSecret()); | ||||||
|  |  | ||||||
|  | |||||||
		Reference in New Issue
	
	Block a user
	 Binary Wang
					Binary Wang