| | |
| | | ResponseCodeEnum.TOKEN_CREATE_ERROR.getMsg()); |
| | | } |
| | | } |
| | | public static String getTokenApp(String uid, Object userInfo) { |
| | | //生成加密token |
| | | try { |
| | | //生成token |
| | | String token = TokenEncryptUtils.encoded(uid + "/" + System.currentTimeMillis() / 1000); |
| | | //查询旧的token |
| | | String oldToken = (String) redisTemplate.opsForHash().get("user_token", uid); |
| | | if (oldToken != null) |
| | | redisTemplate.delete(oldToken); |
| | | //新token写入到value中 |
| | | getRefreshTokenApp(token,userInfo); |
| | | //redisTemplate.expire(token, validity_time, TimeUnit.SECONDS); |
| | | //新token写入到Hash中 |
| | | redisTemplate.opsForHash().put("user_token", uid, token); |
| | | return token; |
| | | } catch (Exception e) { |
| | | log.error("token生成异常:" + e.getMessage()); |
| | | throw new TokenException(ResponseCodeEnum.TOKEN_CREATE_ERROR.getCode(), |
| | | ResponseCodeEnum.TOKEN_CREATE_ERROR.getMsg()); |
| | | } |
| | | } |
| | | |
| | | public static void getRefreshTokenApp(String token, Object userInfo) { |
| | | redisTemplate.opsForValue().set(token, userInfo); |
| | | } |
| | | |
| | | /** |
| | | * @Description: 校验token |
| | |
| | | * @Date: 2021/5/21 |
| | | */ |
| | | public static String getTokenById(Integer id) { |
| | | return (String)redisTemplate.opsForHash().get("user_token", String.valueOf(id)); |
| | | return (String) getTokenById(id.toString()); |
| | | } |
| | | |
| | | public static String getTokenById(String id) { |
| | | return (String)redisTemplate.opsForHash().get("user_token", String.valueOf(id)); |
| | | } |
| | | |
| | | |