| | |
| | | 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; |
| | |
| | | @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); |
| | |
| | | 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(); |
| | | } |
| | | |
| | |
| | | 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(); |
| | | } |
| | | } |