From 7ee466ebc953bb5640bcf42f2b8e2a87aa471c21 Mon Sep 17 00:00:00 2001
From: MrShi <1878285526@qq.com>
Date: 星期三, 15 四月 2026 20:12:21 +0800
Subject: [PATCH] Merge branch 'master' of http://139.186.142.91:10010/r/productDev/gtzxinglijicun
---
server/services/src/main/java/com/doumee/config/jwt/JwtTokenUtil.java | 36 ++++++++++++++++++++++++++++++++----
1 files changed, 32 insertions(+), 4 deletions(-)
diff --git a/server/services/src/main/java/com/doumee/config/jwt/JwtTokenUtil.java b/server/services/src/main/java/com/doumee/config/jwt/JwtTokenUtil.java
index 8e361d5..aab481a 100644
--- a/server/services/src/main/java/com/doumee/config/jwt/JwtTokenUtil.java
+++ b/server/services/src/main/java/com/doumee/config/jwt/JwtTokenUtil.java
@@ -18,10 +18,7 @@
import javax.annotation.Resource;
import java.io.IOException;
-import java.util.Date;
-import java.util.HashMap;
-import java.util.Map;
-import java.util.Objects;
+import java.util.*;
import java.util.concurrent.TimeUnit;
@Component
@@ -34,12 +31,18 @@
public static final String MEMBER_INFO = "MEMBER_INFO";
+ public static final String SHOP_ID = "SHOP_ID";
+
+ public static final String SHOP_INFO = "SHOP_INFO";
+
@Resource
private RedisTemplate<String,Object> redisTemplate;
@Resource
private JwtProperties jwtProperties;
+ //redis杩囨湡鏃堕棿
+ private static final Integer redisExpire = 365;
/**
* 鐢熸垚token浠ょ墝
*
@@ -67,6 +70,31 @@
}
+
+ /**
+ * 鐢熸垚token淇℃伅锛堝悓涓�鐢ㄦ埛浠呬繚鐣欎竴涓湁鏁坱oken锛�
+ * @param userId
+ * @param userType 鐢ㄦ埛绫诲瀷 0=浼氬憳锛�1=鍙告満锛�2=搴楅摵
+ * @param userInfo
+ * @param redisTemplate
+ * @return
+ */
+ public static String generateTokenForRedis(Integer userId, Integer userType, String userInfo, RedisTemplate<String,Object> redisTemplate) {
+ // 鍒犻櫎璇ョ敤鎴蜂箣鍓嶇櫥褰曠殑token
+ String userTokenMappingKey = Constants.REDIS_TOKEN_KEY + "user_" + userType + "_" + userId;
+ String oldToken = (String) redisTemplate.opsForValue().get(userTokenMappingKey);
+ if (StringUtils.isNotBlank(oldToken)) {
+ redisTemplate.delete(Constants.REDIS_TOKEN_KEY + oldToken);
+ }
+ // 鐢熸垚鏂皌oken
+ String tokenKey = userType +""+ UUID.randomUUID() + "_" + userId;
+ redisTemplate.opsForValue().set(Constants.REDIS_TOKEN_KEY + tokenKey, userInfo, redisExpire, TimeUnit.DAYS);
+ // 璁板綍鐢ㄦ埛涓巘oken鐨勬槧灏勫叧绯�
+ redisTemplate.opsForValue().set(userTokenMappingKey, tokenKey, redisExpire, TimeUnit.DAYS);
+ return tokenKey;
+ }
+
+
/**
* 鍒锋柊浠ょ墝
*
--
Gitblit v1.9.3