puzhibing
2024-08-17 1b43670626f48266efb898ec7cd7deedcab9ba10
ruoyi-common/ruoyi-common-security/src/main/java/com/ruoyi/common/security/service/TokenService.java
@@ -5,6 +5,7 @@
import java.util.concurrent.TimeUnit;
import javax.servlet.http.HttpServletRequest;
import com.ruoyi.common.core.exception.user.UserAppletException;
import com.ruoyi.system.api.model.LoginUserApplet;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
@@ -35,6 +36,7 @@
    protected static final long MILLIS_MINUTE = 60 * MILLIS_SECOND;
    private final static long expireTime = CacheConstants.EXPIRATION;
    private final static long expireAppletTime = CacheConstants.EXPIRATION_APPLET;
    private final static String ACCESS_TOKEN = CacheConstants.LOGIN_TOKEN_KEY;
@@ -71,7 +73,7 @@
     */
    public Map<String, Object> createTokenApplet(LoginUserApplet loginUser) {
        String token = IdUtils.fastUUID();
        Integer userId = loginUser.getUserid();
        Long userId = loginUser.getUserId();
        String name = loginUser.getName();
        loginUser.setToken(token);
        loginUser.setIpaddr(IpUtils.getIpAddr());
@@ -84,11 +86,15 @@
        // 接口返回信息
        Map<String, Object> rspMap = new HashMap<String, Object>();
        rspMap.put("access_token", JwtUtils.createToken(claimsMap));
        rspMap.put("expires_in", expireTime);
        rspMap.put("expires_in", expireAppletTime);
        return rspMap;
    }
    public LoginUserApplet getLoginUserApplet() {
        return getLoginUserAppletToken(ServletUtils.getRequest());
        LoginUserApplet loginUserAppletToken = getLoginUserAppletToken(ServletUtils.getRequest());
        if (loginUserAppletToken == null){
            throw new UserAppletException("登录失效,请重新登录!", 401);
        }
        return loginUserAppletToken;
    }
    public LoginUserApplet getLoginUserAppletToken(HttpServletRequest request) {
        // 获取请求携带的令牌
@@ -104,8 +110,8 @@
        LoginUserApplet user = null;
        try {
            if (StringUtils.isNotEmpty(token)) {
                String userkey = JwtUtils.getUserKeyApplet(token);
                user = redisService.getCacheObject(getTokenKey(userkey));
                String userKey = JwtUtils.getUserKeyApplet(token);
                user = redisService.getCacheObject(getTokenKey(userKey));
                return user;
            }
        } catch (Exception e) {