From c8896cb30c2b470aec9409fe39eb3638821d4adb Mon Sep 17 00:00:00 2001 From: OPGames <1242479791@qq.com> Date: Mon, 12 Aug 2019 00:38:14 +0800 Subject: [PATCH] =?UTF-8?q?=E6=9B=B4=E6=96=B0=E5=88=B0=E6=9C=80=E6=96=B0?= =?UTF-8?q?=E7=9A=84wxjava=E5=B7=A5=E5=85=B7=EF=BC=8C=E5=B9=B6=E4=BF=AE?= =?UTF-8?q?=E5=A4=8D=E7=94=B1=E4=BA=8E=E6=9C=AA=E6=8F=92=E5=85=A5=E5=BE=AE?= =?UTF-8?q?=E4=BF=A1access=5Ftoken=E5=AF=BC=E8=87=B4=E6=A0=88=E6=BA=A2?= =?UTF-8?q?=E5=87=BA=E5=92=8Chttpclient=E8=BF=9E=E6=8E=A5=E5=85=B3?= =?UTF-8?q?=E9=97=AD=E7=9A=84=E4=B8=A5=E9=87=8D=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pom.xml | 2 +- .../yami/shop/mp/component/WxMaInRedisConfig.java | 4 ++-- .../shop/mp/component/WxMaServiceClusterImpl.java | 5 +++-- .../shop/mp/component/WxMpInRedisConfigStorage.java | 4 ++-- .../shop/mp/component/WxMpServiceClusterImpl.java | 13 ++++++------- 5 files changed, 14 insertions(+), 14 deletions(-) diff --git a/pom.xml b/pom.xml index c283450..087c548 100644 --- a/pom.xml +++ b/pom.xml @@ -32,7 +32,7 @@ 1.11.3 3.17 7.2.18 - 3.4.0 + 3.5.0 1.5.4 2.9.2 1.9.3 diff --git a/yami-shop-mp/src/main/java/com/yami/shop/mp/component/WxMaInRedisConfig.java b/yami-shop-mp/src/main/java/com/yami/shop/mp/component/WxMaInRedisConfig.java index d89efd6..236f96a 100644 --- a/yami-shop-mp/src/main/java/com/yami/shop/mp/component/WxMaInRedisConfig.java +++ b/yami-shop-mp/src/main/java/com/yami/shop/mp/component/WxMaInRedisConfig.java @@ -10,7 +10,7 @@ package com.yami.shop.mp.component; -import cn.binarywang.wx.miniapp.config.WxMaInMemoryConfig; +import cn.binarywang.wx.miniapp.config.impl.WxMaDefaultConfigImpl; import com.yami.shop.common.annotation.RedisLock; import com.yami.shop.common.util.RedisUtil; import com.yami.shop.mp.config.bean.WxMiniApp; @@ -29,7 +29,7 @@ import java.util.concurrent.locks.Lock; * @author LGH */ @Component -public class WxMaInRedisConfig extends WxMaInMemoryConfig { +public class WxMaInRedisConfig extends WxMaDefaultConfigImpl { private static final String ACCESS_TOKEN_KEY = "wxMa:access_token:"; 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 3ebbd5f..a36601c 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 @@ -4,6 +4,7 @@ import cn.binarywang.wx.miniapp.api.WxMaService; import cn.binarywang.wx.miniapp.api.impl.WxMaServiceImpl; import cn.hutool.http.HttpUtil; import com.yami.shop.common.exception.YamiShopBindException; +import lombok.extern.slf4j.Slf4j; import me.chanjar.weixin.common.bean.WxAccessToken; import me.chanjar.weixin.common.error.WxError; import me.chanjar.weixin.common.error.WxErrorException; @@ -16,9 +17,9 @@ import java.util.concurrent.TimeUnit; * WxMaServiceImpl 在集群模式获取accessToken的方式 * @author LGH */ +@Slf4j public class WxMaServiceClusterImpl extends WxMaServiceImpl { - private static final String REDISSON_LOCK_PREFIX = "redisson_lock:"; private RedissonClient redissonClient; @@ -47,7 +48,7 @@ public class WxMaServiceClusterImpl extends WxMaServiceImpl { throw new YamiShopBindException("服务器繁忙,请稍后再试"); } - if (this.getWxMaConfig().isAccessTokenExpired() && !forceRefresh) { + if (!this.getWxMaConfig().isAccessTokenExpired()) { return this.getWxMaConfig().getAccessToken(); } diff --git a/yami-shop-mp/src/main/java/com/yami/shop/mp/component/WxMpInRedisConfigStorage.java b/yami-shop-mp/src/main/java/com/yami/shop/mp/component/WxMpInRedisConfigStorage.java index cf9f384..481cba7 100644 --- a/yami-shop-mp/src/main/java/com/yami/shop/mp/component/WxMpInRedisConfigStorage.java +++ b/yami-shop-mp/src/main/java/com/yami/shop/mp/component/WxMpInRedisConfigStorage.java @@ -14,7 +14,7 @@ import com.yami.shop.common.annotation.RedisLock; import com.yami.shop.common.util.RedisUtil; import com.yami.shop.mp.config.bean.WxMp; import me.chanjar.weixin.common.bean.WxAccessToken; -import me.chanjar.weixin.mp.api.WxMpInMemoryConfigStorage; +import me.chanjar.weixin.mp.config.impl.WxMpDefaultConfigImpl; import me.chanjar.weixin.mp.enums.TicketType; import org.springframework.stereotype.Component; @@ -26,7 +26,7 @@ import org.springframework.stereotype.Component; * @author LGH */ @Component -public class WxMpInRedisConfigStorage extends WxMpInMemoryConfigStorage { +public class WxMpInRedisConfigStorage extends WxMpDefaultConfigImpl { private static final String ACCESS_TOKEN_KEY = "wxMp:access_token:"; 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 5eec0ec..bae99df 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 @@ -6,18 +6,19 @@ import me.chanjar.weixin.common.WxType; import me.chanjar.weixin.common.bean.WxAccessToken; import me.chanjar.weixin.common.error.WxError; import me.chanjar.weixin.common.error.WxErrorException; -import me.chanjar.weixin.mp.api.WxMpService; -import me.chanjar.weixin.mp.api.impl.WxMpServiceImpl; +import me.chanjar.weixin.mp.api.impl.WxMpServiceHttpClientImpl; import org.redisson.api.RLock; import org.redisson.api.RedissonClient; import java.util.concurrent.TimeUnit; +import static me.chanjar.weixin.mp.enums.WxMpApiUrl.Other.GET_ACCESS_TOKEN_URL; + /** * WxMpServiceImpl 在集群模式获取accessToken的方式 * @author LGH */ -public class WxMpServiceClusterImpl extends WxMpServiceImpl { +public class WxMpServiceClusterImpl extends WxMpServiceHttpClientImpl { private static final String REDISSON_LOCK_PREFIX = "redisson_lock:"; @@ -48,12 +49,10 @@ public class WxMpServiceClusterImpl extends WxMpServiceImpl { throw new YamiShopBindException("服务器繁忙,请稍后再试"); } - if (this.getWxMpConfigStorage().isAccessTokenExpired()) { + if (!this.getWxMpConfigStorage().isAccessTokenExpired()) { return this.getWxMpConfigStorage().getAccessToken(); } - - String url = String.format(WxMpService.GET_ACCESS_TOKEN_URL, - this.getWxMpConfigStorage().getAppId(), this.getWxMpConfigStorage().getSecret()); + String url = String.format(GET_ACCESS_TOKEN_URL.getUrl(this.getWxMpConfigStorage()), this.getWxMpConfigStorage().getAppId(), this.getWxMpConfigStorage().getSecret()); String resultContent = HttpUtil.get(url); WxError error = WxError.fromJson(resultContent, WxType.MP);