From 580f4d3c2ca9eee53eee95a4de2f6610b790780a Mon Sep 17 00:00:00 2001
From: rk <94314517@qq.com>
Date: 星期四, 12 二月 2026 18:24:13 +0800
Subject: [PATCH] 小程序   接口开发

---
 server/dmmall_service/src/main/java/com/doumee/config/Jwt/JwtTokenUtil.java |   45 +++++++++++++++++++++++++++++++++------------
 1 files changed, 33 insertions(+), 12 deletions(-)

diff --git a/server/dmmall_service/src/main/java/com/doumee/config/Jwt/JwtTokenUtil.java b/server/dmmall_service/src/main/java/com/doumee/config/Jwt/JwtTokenUtil.java
index e368861..8ceb003 100644
--- a/server/dmmall_service/src/main/java/com/doumee/config/Jwt/JwtTokenUtil.java
+++ b/server/dmmall_service/src/main/java/com/doumee/config/Jwt/JwtTokenUtil.java
@@ -16,11 +16,20 @@
 package com.doumee.config.Jwt;
 
 
+import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
+import com.doumee.core.constants.ResponseStatus;
+import com.doumee.core.exception.BusinessException;
+import com.doumee.dao.business.model.Member;
+import com.doumee.service.business.impl.MemberServiceImpl;
 import io.jsonwebtoken.*;
 import org.apache.commons.lang3.StringUtils;
+import org.springframework.data.redis.core.RedisTemplate;
 
 import java.util.Date;
 import java.util.Map;
+import java.util.Objects;
+import java.util.UUID;
+import java.util.concurrent.TimeUnit;
 
 /**
  * <p>鍚庡彴绯荤粺jwt token宸ュ叿绫�</p>
@@ -43,11 +52,14 @@
     public static final String HEADER_KEY = "token";
     //鍙栧�煎悕绉�
     public static final String UserId_Name = "AppUserId";
+    //鍙栧�煎悕绉�
+    public static final String ShopId_Name = "AppShopId";
     //鍔犲瘑瀵嗛挜
     private final static String jwtSecret = "MhAjU9poLf8ko54K25XBDtonaL33vtt1";
     //杩囨湡鏃堕棿(s) 86400L=1澶� 604800L=7澶�
     private static final long expire = 86400L;
-
+    //redis杩囨湡鏃堕棿
+    private static final Integer redisExpire = 365;
     /**
      * 鐢熸垚token,鏍规嵁userId鍜岄粯璁よ繃鏈熸椂闂�
      */
@@ -56,6 +68,23 @@
         final Date expirationDate = new Date(System.currentTimeMillis() + expiredSeconds * 1000);
         return generateToken(jwtPayLoad.getMemberId(), expirationDate, jwtPayLoad.toMap());
     }
+
+
+    /**
+     * 鐢熸垚token,鏍规嵁userId鍜岄粯璁よ繃鏈熸椂闂�
+     */
+    public static String generateTokenForRedis(Integer userId, Integer userType, String userInfo, RedisTemplate<String,Object> redisTemplate) {
+        String tokenKey =  userType +""+UUID.randomUUID() + "_" + userId;
+        redisTemplate.opsForValue().set(tokenKey,userInfo,redisExpire, TimeUnit.DAYS);
+        return tokenKey;
+    }
+
+    public void loginOut(RedisTemplate<String,Object> redisTemplate,String token){
+        redisTemplate.delete(token);
+    }
+
+
+
 
     /**
      * 楠岃瘉token鏄惁澶辨晥
@@ -69,14 +98,6 @@
         }
     }
 
-    /**
-     * 鐢熸垚token,鏍规嵁userId鍜岄粯璁よ繃鏈熸椂闂�
-     */
-    public static String generateTokenOld(JwtPayLoad jwtPayLoad) {
-        Long expiredSeconds = getExpireSeconds();
-        final Date expirationDate = new Date(System.currentTimeMillis() + expiredSeconds * 1000);
-        return generateToken(jwtPayLoad.getMemberId(), expirationDate, jwtPayLoad.toMap());
-    }
 
     /**
      * 鑾峰彇jwt鐨刾ayload閮ㄥ垎
@@ -126,14 +147,14 @@
     /**
      * 鐢熸垚token,鏍规嵁userId鍜岃繃鏈熸椂闂�
      */
-    public static String generateToken(Integer userId, Date exppiredDate, Map<String, Object> claims) {
+    public static String generateToken(String userId, Date exppiredDate, Map<String, Object> claims) {
 
         final Date createdDate = new Date();
         String secret = getJwtSecret();
 
         if (claims == null) {
             return Jwts.builder()
-                    .setSubject(userId.toString())
+                    .setSubject(userId)
                     .setIssuedAt(createdDate)
                     .setExpiration(exppiredDate)
                     .signWith(SignatureAlgorithm.HS512, secret)
@@ -141,7 +162,7 @@
         } else {
             return Jwts.builder()
                     .setClaims(claims)
-                    .setSubject(userId.toString())
+                    .setSubject(userId)
                     .setIssuedAt(createdDate)
                     .setExpiration(exppiredDate)
                     .signWith(SignatureAlgorithm.HS512, secret)

--
Gitblit v1.9.3