| | |
| | | package com.moral.util; |
| | | |
| | | import com.moral.constant.Constants; |
| | | import com.moral.constant.ResponseCodeEnum; |
| | | import com.moral.exception.TokenException; |
| | | import com.sun.org.apache.bcel.internal.classfile.ConstantString; |
| | | |
| | | import lombok.extern.slf4j.Slf4j; |
| | | |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.beans.factory.annotation.Qualifier; |
| | | import org.springframework.data.redis.core.RedisTemplate; |
| | | import org.springframework.stereotype.Component; |
| | | |
| | | |
| | | import java.util.HashMap; |
| | | import java.util.Map; |
| | | import java.util.concurrent.TimeUnit; |
| | | |
| | | /** |
| | |
| | | @Component |
| | | @Slf4j |
| | | public class TokenUtils { |
| | | |
| | | private static RedisTemplate redisTemplate; |
| | | |
| | | @Autowired |
| | |
| | | //token有效期 单位:秒 |
| | | private static final int validity_time = 60*30; |
| | | |
| | | //判断user_token里有没有用户的token |
| | | public static boolean hHasKey(String uid){ |
| | | return redisTemplate.opsForHash().hasKey("user_token",uid); |
| | | } |
| | | |
| | | //根据用户id获取token |
| | | public static Object hget(String uid){ |
| | | return redisTemplate.opsForHash().get("user_token",uid); |
| | | } |
| | | /** |
| | | * @Description: 生成token,并且将用户信息存入缓存 |
| | | * @Param: [uid] type: 后台取值:manage 前台取值:api |
| | |
| | | } |
| | | |
| | | /** |
| | | * @Description: token延长 |
| | | * @Param: [token] |
| | | * @return: void |
| | | * @Author: 陈凯裕 |
| | | * @Date: 2021/3/11 |
| | | */ |
| | | * @Description: token延长 |
| | | * @Param: [token] |
| | | * @return: void |
| | | * @Author: 陈凯裕 |
| | | * @Date: 2021/3/11 |
| | | */ |
| | | public static void extendTokenTime(String token) { |
| | | redisTemplate.expire(token, validity_time, TimeUnit.SECONDS); |
| | | } |