| | |
| | | import com.xiaopeng.common.core.exception.auth.NotLoginException; |
| | | import com.xiaopeng.api.vo.account.LoginUser; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.beans.factory.annotation.Value; |
| | | import org.springframework.stereotype.Component; |
| | | import com.xiaopeng.common.core.constant.CacheConstants; |
| | | import com.xiaopeng.common.core.constant.SecurityConstants; |
| | |
| | | public class TokenService { |
| | | @Autowired |
| | | private RedisService redisService; |
| | | |
| | | @Value("${token.secret}") |
| | | private String secret; |
| | | |
| | | protected static final long MILLIS_SECOND = 1000; |
| | | |
| | |
| | | claimsMap.put(SecurityConstants.DETAILS_USERNAME, userName); |
| | | // 接口返回信息 |
| | | Map<String, Object> rspMap = new HashMap<String, Object>(); |
| | | rspMap.put("access_token", JwtUtils.createToken(claimsMap)); |
| | | rspMap.put("access_token", JwtUtils.createToken(claimsMap, secret)); |
| | | rspMap.put("expires_in", expireTime); |
| | | return rspMap; |
| | | } |
| | |
| | | claimsMap.put(SecurityConstants.DETAILS_USERNAME, userName); |
| | | // 接口返回信息 |
| | | Map<String, Object> rspMap = new HashMap<String, Object>(); |
| | | rspMap.put("access_token", JwtUtils.createToken(claimsMap)); |
| | | rspMap.put("access_token", JwtUtils.createToken(claimsMap, secret)); |
| | | rspMap.put("expires_in", expireTime); |
| | | return rspMap; |
| | | } |
| | |
| | | LoginUser user = null; |
| | | try { |
| | | if (StringUtils.isNotEmpty(token)) { |
| | | String userkey = JwtUtils.getUserKey(token); |
| | | String userkey = JwtUtils.getUserKey(token, secret); |
| | | user = redisService.getCacheObject(getTokenKey(userkey)); |
| | | return user; |
| | | } |
| | |
| | | LoginOperationUser user = null; |
| | | try { |
| | | if (StringUtils.isNotEmpty(token)) { |
| | | String userkey = JwtUtils.getOperationUserKey(token); |
| | | String userkey = JwtUtils.getOperationUserKey(token, secret); |
| | | user = redisService.getCacheObject(getTokenKey(userkey)); |
| | | return user; |
| | | } |
| | |
| | | */ |
| | | public void delLoginUser(String token) { |
| | | if (StringUtils.isNotEmpty(token)) { |
| | | String userkey = JwtUtils.getUserKey(token); |
| | | String userkey = JwtUtils.getUserKey(token, secret); |
| | | redisService.deleteObject(getTokenKey(userkey)); |
| | | } |
| | | } |
| | |
| | | private String getUserKey(Long userid) { |
| | | return ACCESS_TOKEN + userid; |
| | | } |
| | | |
| | | public String getSecret() { |
| | | return secret; |
| | | } |
| | | } |