Jelajahi Sumber

feat: 奖缓存优化

xdd 1 bulan lalu
induk
melakukan
6e6631e31b

+ 3 - 1
fs-service-system/src/main/java/com/fs/wx/service/impl/InMemoryWeChatAuthServiceImpl.java

@@ -77,7 +77,7 @@ public class InMemoryWeChatAuthServiceImpl implements WeChatAuthService {
                 }
 
                 long expiresInSeconds = responseJson.getLong("expires_in", 7200L);
-                expiryTime = now + (expiresInSeconds - 300) * 1000;
+                expiryTime = now + (expiresInSeconds - 120) * 1000;
                 log.info("获取accessToken获取成功 {}",cachedToken);
                 return cachedToken;
             } else {
@@ -86,6 +86,8 @@ public class InMemoryWeChatAuthServiceImpl implements WeChatAuthService {
                 throw new RuntimeException("Failed to fetch access token: " + errorMsg);
             }
         } catch (Exception e) {
+            cachedToken = null;
+            expiryTime = 0;
             log.error("Error fetching access token from URL: {}", url, e);
             throw new RuntimeException("Error fetching access token: " + e.getMessage(), e);
         }finally {