From 021962cf0957d6332e33f7f32d6ae92d0cc9f12c Mon Sep 17 00:00:00 2001
From: liukangdong <898885815@qq.com>
Date: 星期四, 10 十月 2024 15:55:32 +0800
Subject: [PATCH] ll
---
server/system_service/src/main/java/com/doumee/core/utils/DESUtil.java | 58 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1 files changed, 58 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..ca03698 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;
@@ -7,8 +14,11 @@
import javax.crypto.spec.DESKeySpec;
import javax.crypto.spec.IvParameterSpec;
import java.io.*;
+import java.net.URLDecoder;
+import java.net.URLEncoder;
import java.security.Key;
import java.util.Base64;
+import java.util.concurrent.TimeUnit;
public class DESUtil {
@@ -169,4 +179,52 @@
}
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);
+ try{
+ encrypt = URLEncoder.encode(encrypt,"UTF-8");
+ }catch (Exception e){
+ throw new BusinessException(ResponseStatus.SERVER_ERROR.getCode(),"鐢熸垚鍔犲瘑鐮佸け璐�!");
+ }
+ 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