From 726b056fc2d3b51acdeb0b5fbaf74c8886acc2ac Mon Sep 17 00:00:00 2001
From: kaiyu <404897439@qq.com>
Date: Fri, 23 Apr 2021 14:49:40 +0800
Subject: [PATCH] screen-manage                 更新时间格式

---
 screen-common/src/main/java/com/moral/util/TokenUtils.java |   74 ++++++++++++++++++++++++++----------
 1 files changed, 53 insertions(+), 21 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 cafd03b..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,18 +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;
 
 /**
@@ -25,7 +24,6 @@
 @Component
 @Slf4j
 public class TokenUtils {
-
     private static RedisTemplate redisTemplate;
 
     @Autowired
@@ -35,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: ���������
@@ -55,12 +63,12 @@
                 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());
+            log.error("token���������������" + e.getMessage());
             throw new TokenException(ResponseCodeEnum.TOKEN_CREATE_ERROR.getCode(),
                     ResponseCodeEnum.TOKEN_CREATE_ERROR.getMsg());
         }
@@ -70,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
      */
@@ -88,22 +96,22 @@
                         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>
+     * @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)
+        if (userInfo == null)
             throw new TokenException(ResponseCodeEnum.TOKEN_INVALID.getCode(),
                     ResponseCodeEnum.TOKEN_INVALID.getMsg());
         return userInfo;
@@ -122,13 +130,37 @@
     }
 
     /**
-    * @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