zhanghua
2023-09-08 7ef4892f9f24f941aca37e6b3991b808a0aca619
ycl-common/src/main/java/com/ycl/utils/auth/UserAuthUtil.java
@@ -8,6 +8,7 @@
import com.ycl.utils.JwtTokenUtil;
import com.ycl.utils.common.LiveTimeMillisecond;
import com.ycl.utils.common.NetworkUtil;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;
import javax.annotation.Resource;
@@ -25,6 +26,8 @@
    @Resource
    private RedisService redisService;
    @Value("${jwt.tokenHead}")
    private String tokenHead;
    public void saveUser(Long userId, String token, String redisKey) {
        redisService.set(redisKey.concat(userId.toString()), token, LiveTimeMillisecond.s2592000.time);
@@ -41,7 +44,8 @@
        if (StrUtil.isBlank(accessToken)) {
            throw new ApiException(ResultCode.NOT_LOGGED);
        }
        AuthInfo authInfo = jwtTokenUtil.parseToken(accessToken);
        String authToken = accessToken.substring(this.tokenHead.length());// The part after "Bearer "
        AuthInfo authInfo = jwtTokenUtil.parseToken(authToken);
        return authInfo.getUserId();
    }
@@ -56,7 +60,9 @@
        if (StrUtil.isBlank(accessToken)) {
            throw new ApiException(ResultCode.NOT_LOGGED);
        }
        AuthInfo authInfo = jwtTokenUtil.parseToken(accessToken);
        String authToken = accessToken.substring(this.tokenHead.length());// The part after "Bearer "
        AuthInfo authInfo = jwtTokenUtil.parseToken(authToken);
//        AuthInfo authInfo = jwtTokenUtil.parseToken(accessToken);
        return authInfo.getUsername();
    }
}