nidapeng
2024-04-26 48467740fa3144b073f9b679c3a9764f75e206b1
server/system_gateway/src/main/java/com/doumee/config/jwt/JwtTokenUtil.java
@@ -2,6 +2,7 @@
import com.alibaba.fastjson.JSONObject;
import com.doumee.core.model.LoginUserInfo;
import com.doumee.core.utils.Constants;
import io.jsonwebtoken.Jwts;
import io.jsonwebtoken.SignatureAlgorithm;
import org.springframework.beans.factory.annotation.Autowired;
@@ -96,7 +97,7 @@
            claims.setLoginDate(new Date());
            refreshedToken = generateTokenDo(claims);
            if(refreshedToken!=null){
                redisTemplate.delete(token);//删除老的token
                redisTemplate.delete(Constants.REDIS_TOKEN_KEY+token);//删除老的token
            }
        } catch (Exception e) {
            refreshedToken = null;
@@ -131,7 +132,7 @@
                .setExpiration(expirationDate)
                .signWith(SignatureAlgorithm.HS512, jwtProperties.getSecret())
                .compact();
        redisTemplate.opsForValue().set(token,JSONObject.toJSONString(userInfo),jwtProperties.getExpiration(), TimeUnit.MILLISECONDS);
        redisTemplate.opsForValue().set(Constants.REDIS_TOKEN_KEY+token,JSONObject.toJSONString(userInfo),jwtProperties.getExpiration(), TimeUnit.MILLISECONDS);
        return token;
    }
@@ -144,7 +145,7 @@
    private LoginUserInfo getClaimsFromToken(String token) {
        LoginUserInfo claims;
        try {
            String userInfo = (String) redisTemplate.opsForValue().get(token);
            String userInfo = (String) redisTemplate.opsForValue().get(Constants.REDIS_TOKEN_KEY+token);
            claims = JSONObject.toJavaObject(JSONObject.parseObject(userInfo),LoginUserInfo.class);
        } catch (Exception e) {
            claims = null;