Browse Source

feat: 奖缓存优化

xdd 1 tháng trước cách đây
mục cha
commit
5849fb7dd5

+ 2 - 0
fs-service-system/src/main/java/com/fs/store/service/impl/FsStoreOrderServiceImpl.java

@@ -348,6 +348,8 @@ public class FsStoreOrderServiceImpl implements IFsStoreOrderService
               logger.info("该单 {} 推送到物流失败!",fsWxExpressTask);
               fsWxExpressTask.setRetryCount(fsWxExpressTask.getRetryCount() +1);
               fsWxExpressTask.setStatus(3);
+
+
           }
         }
         fsWxExpressTaskMapper.batchUpdate(fsWxExpressTasks);

+ 5 - 0
fs-service-system/src/main/java/com/fs/wx/service/ShippingService.java

@@ -1,5 +1,6 @@
 package com.fs.wx.service;
 
+import cn.hutool.core.util.ObjectUtil;
 import cn.hutool.http.ContentType;
 import cn.hutool.http.Header;
 import cn.hutool.http.HttpRequest;
@@ -91,6 +92,10 @@ public class ShippingService {
 
                 if (!weChatApiResponse.isSuccess()) {
                     log.warn("微信接口返回业务错误: code={}, message={}", weChatApiResponse.getErrcode(), weChatApiResponse.getErrmsg());
+                    if(ObjectUtil.equal(weChatApiResponse.getErrcode(),40001)) {
+                        log.info("token缓存失效,清除token,等待下次执行...");
+                        weChatAuthService.clearToken();
+                    }
                 }
                 return weChatApiResponse;
 

+ 2 - 0
fs-service-system/src/main/java/com/fs/wx/service/WeChatAuthService.java

@@ -1,6 +1,8 @@
 package com.fs.wx.service;
 
 public interface WeChatAuthService {
+    void clearToken();
+
     /**
      * 获取有效的微信小程序 Access Token
      * @param forceRefresh 是否强制刷新,忽略缓存

+ 7 - 0
fs-service-system/src/main/java/com/fs/wx/service/impl/InMemoryWeChatAuthServiceImpl.java

@@ -30,6 +30,13 @@ public class InMemoryWeChatAuthServiceImpl implements WeChatAuthService {
     }
 
 
+    @Override
+    public synchronized void clearToken(){
+        log.info("清除token缓存...");
+        cachedToken = null;
+        expiryTime = 0;
+    }
+
     @Override
     public synchronized String getAccessToken(boolean forceRefresh) {
         long now = System.currentTimeMillis();