From 601e7ddfd4e8e6b51d12708c00783d13c7522e0e Mon Sep 17 00:00:00 2001
From: 张天森 <1292933220@qq.com>
Date: 星期六, 24 九月 2022 10:06:06 +0800
Subject: [PATCH] update

---
 springcloud_k8s_panzhihuazhihuishequ/common/src/main/java/com/panzhihua/common/utlis/WxXCXTempSend.java |   28 ++++++----------------------
 1 files changed, 6 insertions(+), 22 deletions(-)

diff --git a/springcloud_k8s_panzhihuazhihuishequ/common/src/main/java/com/panzhihua/common/utlis/WxXCXTempSend.java b/springcloud_k8s_panzhihuazhihuishequ/common/src/main/java/com/panzhihua/common/utlis/WxXCXTempSend.java
index c19972e..05275be 100644
--- a/springcloud_k8s_panzhihuazhihuishequ/common/src/main/java/com/panzhihua/common/utlis/WxXCXTempSend.java
+++ b/springcloud_k8s_panzhihuazhihuishequ/common/src/main/java/com/panzhihua/common/utlis/WxXCXTempSend.java
@@ -42,6 +42,8 @@
     private static String APP_IMAGE_NAME = "5.jpg";
     @Resource
     private RedisTemplate redisTemplate;
+    @Resource
+    private StringRedisTemplate stringRedisTemplate;
     UserService userService;
 
     private static WxXCXTempSend wxXCXTempSend;
@@ -92,35 +94,16 @@
      * @return
      */
     public String getAccessToken() throws Exception {
-         String appid=this.getAppId();
          String accessToken = "";
-         Boolean aBoolean = wxXCXTempSend.redisTemplate.hasKey(SecurityConstants.APPLETS_ACCESS_TOKEN+"_"+appid);
-         ValueOperations<String, String> valueOperations = wxXCXTempSend.redisTemplate.opsForValue();
-         if(aBoolean){
-         Long expireTime = Long.parseLong(valueOperations.get(SecurityConstants.APPLETS_ACCESS_TOKEN_TIME+"_"+appid));
-         if(expireTime <= System.currentTimeMillis()){
-             wxXCXTempSend.redisTemplate.delete(SecurityConstants.APPLETS_ACCESS_TOKEN+"_"+appid);//如果过期则删除
-             wxXCXTempSend.redisTemplate.delete(SecurityConstants.APPLETS_ACCESS_TOKEN_TIME+"_"+appid);//如果过期则删除
-
-         valueOperations.set(SecurityConstants.APPLETS_ACCESS_TOKEN+"_"+appid, getAppAccessToken(appid));
-         valueOperations.set(SecurityConstants.APPLETS_ACCESS_TOKEN_TIME+"_"+appid, System.currentTimeMillis() + 1100000 + "");
-         }else{
-         accessToken = valueOperations.get(SecurityConstants.APPLETS_ACCESS_TOKEN+"_"+appid);
-         }
-         }else{
-         accessToken = getAppAccessToken(appid);
-         valueOperations.set(SecurityConstants.APPLETS_ACCESS_TOKEN+"_"+appid, accessToken);
-         valueOperations.set(SecurityConstants.APPLETS_ACCESS_TOKEN_TIME+"_"+appid, System.currentTimeMillis() + 1100000 + "");
-         }
+         accessToken=wxXCXTempSend.stringRedisTemplate.boundValueOps("access_token:access_token:"+this.getAppId()).get();
         return accessToken;
     }
 
-    public String getAppAccessToken(String appid) throws Exception {
-        R<SysAppConfigVO> sysAppConfigVOR=userService.selectByAppid(appid);
+    public String getAppAccessToken() throws Exception {
         String accessToken = "0";
         try {
             log.info("获取微信token参数:appid=" + APP_ID + ",appSecret=" + APP_SECRET);
-            String accessTokenUrl = ACCESS_TOKEN_URL + "&appid=" + sysAppConfigVOR.getData().getAppId() + "&secret=" + sysAppConfigVOR.getData().getSecret();
+            String accessTokenUrl = ACCESS_TOKEN_URL + "&appid=" + APP_ID + "&secret=" + APP_SECRET;
             String result = HttpClientUtil.httpGet(accessTokenUrl, null, null);
             Map<String, Object> resultMap = JSON.parseObject(result, Map.class);
             if (resultMap.containsKey("access_token")) {
@@ -277,6 +260,7 @@
     public void init() {
         wxXCXTempSend = this;
         wxXCXTempSend.redisTemplate = this.redisTemplate;
+        wxXCXTempSend.stringRedisTemplate=this.stringRedisTemplate;
     }
 
 }

--
Gitblit v1.7.1