From 29fc101ccd5165a1c3d762ba3a240b1a0ab4ddfe Mon Sep 17 00:00:00 2001
From: k94314517 <8417338+k94314517@user.noreply.gitee.com>
Date: 星期二, 10 九月 2024 13:08:27 +0800
Subject: [PATCH] 代码初始化

---
 server/system_service/src/main/java/com/doumee/core/utils/DESUtil.java |   51 +++++++++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 51 insertions(+), 0 deletions(-)

diff --git a/server/system_service/src/main/java/com/doumee/core/utils/DESUtil.java b/server/system_service/src/main/java/com/doumee/core/utils/DESUtil.java
index 3486129..959cc6e 100644
--- a/server/system_service/src/main/java/com/doumee/core/utils/DESUtil.java
+++ b/server/system_service/src/main/java/com/doumee/core/utils/DESUtil.java
@@ -1,5 +1,12 @@
 package com.doumee.core.utils;
 
+import com.alibaba.fastjson.JSONObject;
+import com.doumee.core.constants.ResponseStatus;
+import com.doumee.core.exception.BusinessException;
+import org.apache.commons.lang3.StringUtils;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.data.redis.core.RedisTemplate;
+
 import javax.crypto.Cipher;
 import javax.crypto.CipherInputStream;
 import javax.crypto.CipherOutputStream;
@@ -9,6 +16,7 @@
 import java.io.*;
 import java.security.Key;
 import java.util.Base64;
+import java.util.concurrent.TimeUnit;
 
 public class DESUtil {
 
@@ -169,4 +177,47 @@
         }
         return null;
     }
+
+
+    /**
+     * 娴峰悍鍔犲瘑
+     * @param userName
+     * @param hour
+     * @return
+     */
+    public static  String generateTokenToHk(String userName,Integer hour, RedisTemplate<String,Object> redisTemplate){
+         long currentTimeMillis = System.currentTimeMillis() + 1000*60*60*hour;
+         String encrypt = DESUtil.encrypt("12345678",currentTimeMillis + "_" + userName );
+         redisTemplate.opsForValue().set(Constants.REDIS_HK_TOKEN_KEY+encrypt, encrypt,1000*60*60*hour, TimeUnit.MILLISECONDS);
+         return encrypt;
+    }
+
+
+    /**
+     * 娴峰悍瑙g爜
+     * @param token
+     * @return
+     */
+    public static String verifyHkToken(String token){
+        String decrypt = DESUtil.decrypt("12345678",token);
+        if(StringUtils.isBlank(decrypt)){
+            throw new BusinessException(ResponseStatus.NOT_ALLOWED.getCode(),"token瑙f瀽澶辫触");
+        }
+        try{
+            Integer index_ = decrypt.indexOf("_");
+            long currentTimeMillis = Long.valueOf(decrypt.substring(Constants.ZERO,index_));
+            if(currentTimeMillis<=System.currentTimeMillis()){
+                throw new BusinessException(ResponseStatus.NOT_ALLOWED.getCode(),"token宸茶繃鏈�");
+            }
+            String userName = decrypt.substring(index_+Constants.ONE);
+            return userName ;
+        }catch (Exception e){
+            throw new BusinessException(ResponseStatus.NOT_ALLOWED.getCode(),"token瑙f瀽澶辫触");
+        }
+
+    }
+
+
+
+
 }
\ No newline at end of file

--
Gitblit v1.9.3