From e563f73f8baa8f1d16a552384f697ecb6bf737f5 Mon Sep 17 00:00:00 2001 From: OPGame <1242479791@qq.com> Date: Fri, 9 Aug 2019 19:19:54 +0800 Subject: [PATCH] =?UTF-8?q?=E6=9B=B4=E6=96=B0=E9=9B=86=E7=BE=A4=E6=A8=A1?= =?UTF-8?q?=E5=BC=8F=E5=A4=9A=E6=AC=A1=E9=87=8D=E5=A4=8D=E8=8E=B7=E5=8F=96?= =?UTF-8?q?=E5=BE=AE=E4=BF=A1accessToken=E7=9A=84=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../mp/component/WxMaServiceClusterImpl.java | 26 ++++++++--------- .../mp/component/WxMpServiceClusterImpl.java | 29 +++++++++---------- 2 files changed, 25 insertions(+), 30 deletions(-) diff --git a/yami-shop-mp/src/main/java/com/yami/shop/mp/component/WxMaServiceClusterImpl.java b/yami-shop-mp/src/main/java/com/yami/shop/mp/component/WxMaServiceClusterImpl.java index 954ef3a..4c58a72 100644 --- a/yami-shop-mp/src/main/java/com/yami/shop/mp/component/WxMaServiceClusterImpl.java +++ b/yami-shop-mp/src/main/java/com/yami/shop/mp/component/WxMaServiceClusterImpl.java @@ -15,7 +15,6 @@ import org.redisson.api.RedissonClient; import java.io.IOException; import java.util.concurrent.TimeUnit; -import java.util.concurrent.locks.Lock; /** * WxMaServiceImpl 在集群模式获取accessToken的方式 @@ -40,23 +39,22 @@ public class WxMaServiceClusterImpl extends WxMaServiceImpl { RLock rLock = redissonClient.getLock(REDISSON_LOCK_PREFIX + ":WxMaServiceCluster:getAccessToken"); - boolean doingUpdateAccessToken; - try { - doingUpdateAccessToken = rLock.tryLock(10, TimeUnit.SECONDS); - } catch (InterruptedException e) { - return this.getWxMaConfig().getAccessToken(); - } + boolean lockSuccess; + try { + lockSuccess = rLock.tryLock(10, TimeUnit.SECONDS); + } catch (InterruptedException e) { + return this.getWxMaConfig().getAccessToken(); + } - if (!doingUpdateAccessToken) { - throw new YamiShopBindException("服务器繁忙,请稍后再试"); - } + if (!lockSuccess) { + throw new YamiShopBindException("服务器繁忙,请稍后再试"); + } - if (this.getWxMaConfig().isAccessTokenExpired()) { - return this.getWxMaConfig().getAccessToken(); - } + if (this.getWxMaConfig().isAccessTokenExpired() && !forceRefresh) { + return this.getWxMaConfig().getAccessToken(); + } - try { String url = String.format(WxMaService.GET_ACCESS_TOKEN_URL, this.getWxMaConfig().getAppid(), this.getWxMaConfig().getSecret()); try { diff --git a/yami-shop-mp/src/main/java/com/yami/shop/mp/component/WxMpServiceClusterImpl.java b/yami-shop-mp/src/main/java/com/yami/shop/mp/component/WxMpServiceClusterImpl.java index 3e48fc4..ccfe6d9 100644 --- a/yami-shop-mp/src/main/java/com/yami/shop/mp/component/WxMpServiceClusterImpl.java +++ b/yami-shop-mp/src/main/java/com/yami/shop/mp/component/WxMpServiceClusterImpl.java @@ -40,25 +40,22 @@ public class WxMpServiceClusterImpl extends WxMpServiceImpl { RLock rLock = redissonClient.getLock(REDISSON_LOCK_PREFIX + ":WxMpServiceCluster:getAccessToken"); - boolean doingUpdateAccessToken; - + Object result = null; try { - doingUpdateAccessToken = rLock.tryLock(10, TimeUnit.SECONDS); - } catch (InterruptedException e) { - return this.getWxMpConfigStorage().getAccessToken(); - } - - if (!doingUpdateAccessToken) { - throw new YamiShopBindException("服务器繁忙,请稍后再试"); - } - - if (this.getWxMpConfigStorage().isAccessTokenExpired()) { - return this.getWxMpConfigStorage().getAccessToken(); - } + boolean doingUpdateAccessToken; + try { + doingUpdateAccessToken = rLock.tryLock(10, TimeUnit.SECONDS); + } catch (InterruptedException e) { + return this.getWxMpConfigStorage().getAccessToken(); + } + if (!doingUpdateAccessToken) { + throw new YamiShopBindException("服务器繁忙,请稍后再试"); + } - Object result = null; - try { + if (this.getWxMpConfigStorage().isAccessTokenExpired()) { + return this.getWxMpConfigStorage().getAccessToken(); + } String url = String.format(WxMpService.GET_ACCESS_TOKEN_URL, this.getWxMpConfigStorage().getAppId(), this.getWxMpConfigStorage().getSecret()); try {