From a30695d15a46ef43dc59e4d1c7ddd948d16094a0 Mon Sep 17 00:00:00 2001
From: fwq <582742538@qq.com>
Date: 星期四, 26 十月 2023 11:27:11 +0800
Subject: [PATCH] Merge remote-tracking branch 'origin/master'

---
 src/main/java/com/hx/encryption/PTEncryptionUtil.java |   70 ++++++++++++++++++++++++++---------
 1 files changed, 52 insertions(+), 18 deletions(-)

diff --git a/src/main/java/com/hx/encryption/PTEncryptionUtil.java b/src/main/java/com/hx/encryption/PTEncryptionUtil.java
index 1239213..8d15e1f 100644
--- a/src/main/java/com/hx/encryption/PTEncryptionUtil.java
+++ b/src/main/java/com/hx/encryption/PTEncryptionUtil.java
@@ -1,6 +1,8 @@
 package com.hx.encryption;
 
+import com.hx.util.DateUtil;
 import com.hx.util.MD5Util;
+import com.hx.util.StringUtils;
 
 import java.util.Calendar;
 import java.util.Date;
@@ -12,6 +14,7 @@
  */
 public class PTEncryptionUtil {
 
+
     /*
      * 鏃ユ湡鍔犲瘑
      * date  瑕佸姞瀵嗙殑鏃ユ湡
@@ -19,24 +22,55 @@
     public static String  encryption(Date date){
         Calendar cal=Calendar.getInstance();
         cal.setTime(date);
-        int year = cal.get(Calendar.YEAR);//鑾峰彇骞翠唤
-        int month=cal.get(Calendar.MONTH);//鑾峰彇鏈堜唤
-        int day=cal.get(Calendar.DATE);//鑾峰彇鏃�
-        int hour=cal.get(Calendar.HOUR_OF_DAY);//灏忔椂
-        int minute=cal.get(Calendar.MINUTE);//鍒�
-        int second=cal.get(Calendar.SECOND);//绉�
+        StringBuffer data = new StringBuffer();
+        data.append(cal.get(Calendar.DATE));
+        data.append(cal.get(Calendar.MONTH));
+        data.append(cal.get(Calendar.YEAR));
+        data.append(cal.get(Calendar.SECOND));
+        data.append(cal.get(Calendar.MINUTE));
+        data.append(cal.get(Calendar.HOUR_OF_DAY));
 
-        String yearStr = com.hx.mp.util.MD5Util.MD5Encode(year+"","");
-        String monthStr = com.hx.mp.util.MD5Util.MD5Encode(month+"","");
-        String dayStr = com.hx.mp.util.MD5Util.MD5Encode(day+"","");
-        String hourStr = com.hx.mp.util.MD5Util.MD5Encode(hour+"","");
-        String minuteStr = com.hx.mp.util.MD5Util.MD5Encode(minute+"","");
-        String secondStr = com.hx.mp.util.MD5Util.MD5Encode(second+"","");
-
-        StringBuffer result = new StringBuffer();
-        result.append(yearStr).append("-").append(monthStr).append("-").append(dayStr).append("-")
-                .append(hourStr).append("-").append(minuteStr).append("-").append(secondStr);
-
-        return result.toString();
+        return com.hx.mp.util.MD5Util.MD5Encode(data.toString(),"");
     }
+
+    /**
+     *
+     * @param data 绛惧悕
+     * @param date 鏃堕棿
+     * @param time 鏈夋晥鏃堕棿 绉�
+     * @return
+     */
+    public static PTConstant decode(String data,Date date,Integer time){
+        PTConstant ptConstant = new PTConstant();
+        ptConstant.setSuccess(true);
+        if (StringUtils.isEmpty(data)){
+            ptConstant.setSuccess(false);
+            ptConstant.setErrCode(PTConstant.PT_SIGN_EEMPLY);
+            return ptConstant;
+        }
+        if (null == date){
+            ptConstant.setSuccess(false);
+            ptConstant.setErrCode(PTConstant.PT_TIMELS_EMPLY);
+            return ptConstant;
+        }
+
+        if(!encryption(date).equals(data)){
+            ptConstant.setSuccess(false);
+            ptConstant.setErrCode(PTConstant.PT_SIGN_ERROR);
+            return ptConstant;
+        }
+        if(time == null){
+            ptConstant.setSuccess(true);
+            return ptConstant;
+        }
+        //鏈夋晥鏃堕棿鍒ゆ柇
+        if (DateUtil.calLastedTime(date) > time){
+            ptConstant.setSuccess(false);
+            ptConstant.setErrCode(PTConstant.PT_ORER_TIME);
+            return ptConstant;
+        }
+
+        return ptConstant;
+    }
+
 }

--
Gitblit v1.8.0