1 changed files with 0 additions and 38 deletions
			
			
		| @ -1,38 +0,0 @@ | |||
| package com.epmet.util; | |||
| 
 | |||
| import com.epmet.commons.tools.exception.EpmetErrorCode; | |||
| import com.epmet.commons.tools.exception.RenException; | |||
| import com.epmet.commons.tools.security.dto.BaseTokenDto; | |||
| import com.epmet.commons.tools.utils.CpUserDetailRedis; | |||
| import com.epmet.jwt.JwtTokenUtils; | |||
| import io.jsonwebtoken.Claims; | |||
| import org.springframework.stereotype.Component; | |||
| 
 | |||
| /** | |||
|  * @Description | |||
|  * @ClassName UserTokenValidateUtil | |||
|  * @Auth wangc | |||
|  * @Date 2020-05-21 17:47 | |||
|  */ | |||
| @Component | |||
| public class UserTokenValidateUtil { | |||
|     public BaseTokenDto getBaseTokenDto(String token, JwtTokenUtils jwtTokenUtils) { | |||
|         //是否过期
 | |||
|         Claims claims = jwtTokenUtils.getClaimByToken(token); | |||
|         if (claims == null || jwtTokenUtils.isTokenExpired(claims.getExpiration())) { | |||
|             throw new RenException(EpmetErrorCode.ERR401.getCode()); | |||
|         } | |||
|         //获取用户ID
 | |||
|         String app = (String) claims.get("app"); | |||
|         String client = (String) claims.get("client"); | |||
|         String userId = (String) claims.get("userId"); | |||
|         return new BaseTokenDto(app, client, userId, token); | |||
|     } | |||
| 
 | |||
|     public <T> T getLoginUserInfoByToken(String token, JwtTokenUtils jwtTokenUtils, CpUserDetailRedis cpUserDetailRedis, Class<T> clz) { | |||
|         BaseTokenDto baseTokenDto = getBaseTokenDto(token, jwtTokenUtils); | |||
|         //查询Redis
 | |||
|         return cpUserDetailRedis.get(baseTokenDto.getApp(), baseTokenDto.getClient(), baseTokenDto.getUserId(), clz); | |||
|     } | |||
| 
 | |||
| } | |||
					Loading…
					
					
				
		Reference in new issue