| | |
| | | import org.springframework.beans.factory.annotation.Qualifier; |
| | | import org.springframework.data.redis.core.RedisTemplate; |
| | | import org.springframework.stereotype.Component; |
| | | import org.springframework.util.ObjectUtils; |
| | | |
| | | |
| | | import java.util.concurrent.TimeUnit; |
| | |
| | | public static Object hget(String uid){ |
| | | return redisTemplate.opsForHash().get("user_token",uid); |
| | | } |
| | | |
| | | /** |
| | | * @Description: 生成token,并且将用户信息存入缓存 |
| | | * @Param: [uid] type: 后台取值:manage 前台取值:api |
| | |
| | | redisTemplate.delete(oldToken); |
| | | //新token写入到value中 |
| | | redisTemplate.opsForValue().set(token, userInfo); |
| | | redisTemplate.expire(token, validity_time, TimeUnit.SECONDS); |
| | | //redisTemplate.expire(token, validity_time, TimeUnit.SECONDS); |
| | | //新token写入到Hash中 |
| | | redisTemplate.opsForHash().put("user_token", uid, token); |
| | | return token; |
| | |
| | | ResponseCodeEnum.TOKEN_INVALID.getMsg()); |
| | | } |
| | | } catch (Exception e) { |
| | | log.error("token工具类校验token异常" + e.getMessage()); |
| | | throw new TokenException(ResponseCodeEnum.TOKEN_INVALID.getCode(), |
| | | ResponseCodeEnum.TOKEN_INVALID.getMsg()); |
| | | } |
| | | } |
| | | |
| | | |
| | | /** |
| | | * @Description: 通过token获取用户信息 前台使用 |
| | | * @Description: 通过token获取用户信息 |
| | | * @Param: [token] |
| | | * @return: java.util.Map<java.lang.String , java.lang.Object> |
| | | * @Author: 陈凯裕 |
| | |
| | | } |
| | | |
| | | /** |
| | | * @Description: 销毁token |
| | | * @Param: [token] |
| | | * @return: void |
| | | * @Author: 陈凯裕 |
| | | * @Date: 2021/4/1 |
| | | */ |
| | | public static void destoryToken(String token) { |
| | | destoryToken(getUidByToken(token), token); |
| | | } |
| | | |
| | | /** |
| | | * @Description: 根据TOKEN获取Id |
| | | * @Param: [token] |
| | | * @return: void |
| | | * @Author: 陈凯裕 |
| | | * @Date: 2021/4/1 |
| | | */ |
| | | public static String getUidByToken(String token) { |
| | | String[] string = TokenEncryptUtils.decoded(token).split("/"); |
| | | return string[0]; |
| | | } |
| | | |
| | | |
| | | /** |
| | | * @Description: token延长 |
| | | * @Param: [token] |
| | | * @return: void |