From 7bf9583e3fd56020cbc62a5e87ff5987b8070ca5 Mon Sep 17 00:00:00 2001
From: kaiyu <404897439@qq.com>
Date: Thu, 13 May 2021 16:00:35 +0800
Subject: [PATCH] screen-manage 更改返回菜单vo对象属性名称
---
screen-common/src/main/java/com/moral/util/TokenUtils.java | 92 ++++++++++++++++++++++++++++++++-------------
1 files changed, 65 insertions(+), 27 deletions(-)
diff --git a/screen-common/src/main/java/com/moral/util/TokenUtils.java b/screen-common/src/main/java/com/moral/util/TokenUtils.java
index 5c668f2..9bc1d5e 100644
--- a/screen-common/src/main/java/com/moral/util/TokenUtils.java
+++ b/screen-common/src/main/java/com/moral/util/TokenUtils.java
@@ -1,17 +1,17 @@
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 org.springframework.util.ObjectUtils;
-import java.util.HashMap;
-import java.util.Map;
import java.util.concurrent.TimeUnit;
/**
@@ -24,7 +24,6 @@
@Component
@Slf4j
public class TokenUtils {
-
private static RedisTemplate redisTemplate;
@Autowired
@@ -34,10 +33,20 @@
}
//token��������� ������������
- private static final int validity_time = 60*30;
+ 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,���������������������������������
+ * @Description: ������token, ���������������������������������
* @Param: [uid] type��� ���������������manage ���������������api
* @return: java.lang.String
* @Author: ���������
@@ -54,13 +63,14 @@
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;
} catch (Exception e) {
- log.error("token���������������"+e.getMessage());
- throw new TokenException(Constants.CODE_TOKEN_CREATE_ERROR,Constants.MSG_TOKEN_CREATE_ERROR);
+ log.error("token���������������" + e.getMessage());
+ throw new TokenException(ResponseCodeEnum.TOKEN_CREATE_ERROR.getCode(),
+ ResponseCodeEnum.TOKEN_CREATE_ERROR.getMsg());
}
}
@@ -68,7 +78,7 @@
/**
* @Description: ������token
* @Param: [type, token] type��� ���������������manage ���������������api
- * @return: java.util.Map<java.lang.String , java.lang.Object>
+ * @return: java.util.Map<java.lang.String , java.lang.Object>
* @Author: ���������
* @Date: 2021/3/10
*/
@@ -77,29 +87,33 @@
String[] tokenArray = TokenEncryptUtils.decoded(token).split("/");
//������token������������
if (tokenArray.length != 2) {
- throw new TokenException(Constants.CODE_TOKEN_ERROR,Constants.MSG_TOKEN_ERROR);
+ throw new TokenException(ResponseCodeEnum.TOKEN_INVALID.getCode(),
+ ResponseCodeEnum.TOKEN_INVALID.getMsg());
}
//������token������������
if (!redisTemplate.hasKey(token)) {
- throw new TokenException(Constants.CODE_TOKEN_ERROR,Constants.MSG_TOKEN_ERROR);
+ throw new TokenException(ResponseCodeEnum.TOKEN_INVALID.getCode(),
+ ResponseCodeEnum.TOKEN_INVALID.getMsg());
}
} catch (Exception e) {
- log.error("token���������������token������" + e.getMessage());
- throw new TokenException(Constants.CODE_TOKEN_ERROR,Constants.MSG_TOKEN_ERROR);
+ 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>
+ * @return: java.util.Map<java.lang.String , java.lang.Object>
* @Author: ���������
* @Date: 2021/3/11
*/
public static Object getUserInfoByToken(String token) {
Object userInfo = redisTemplate.opsForValue().get(token);
- if(userInfo==null)
- throw new TokenException(Constants.CODE_TOKEN_ERROR,Constants.MSG_TOKEN_ERROR);
+ if (userInfo == null)
+ throw new TokenException(ResponseCodeEnum.TOKEN_INVALID.getCode(),
+ ResponseCodeEnum.TOKEN_INVALID.getMsg());
return userInfo;
}
@@ -111,18 +125,42 @@
* @Date: 2021/3/11
*/
public static void destoryToken(String uid, String token) {
- redisTemplate.delete("token");
+ redisTemplate.delete(token);
redisTemplate.opsForHash().delete("user_token", uid);
}
/**
- * @Description: token������
- * @Param: [token]
- * @return: void
- * @Author: ���������
- * @Date: 2021/3/11
- */
- public static void extendTokenTime(String token) {
+ * @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
+ * @Author: ���������
+ * @Date: 2021/3/11
+ */
+ public static void extendTokenTime(String token) {
redisTemplate.expire(token, validity_time, TimeUnit.SECONDS);
}
}
--
Gitblit v1.8.0