chenjiahe
2022-03-31 b5bfe58beeeeb8343bdea6a9412f8f6704b67633
提交 | 用户 | age
135164 1 package com.hx.encryption;
W 2
1ffbaa 3 import com.hx.util.DateUtil;
135164 4 import com.hx.util.MD5Util;
1ffbaa 5 import com.hx.util.StringUtils;
135164 6
W 7 import java.util.Calendar;
8 import java.util.Date;
9
10 /*
11  * @Description: his助手调用 phitab 订单加密工具
12  * @Author: wangrenhuang
13  * @Date:  2022/2/15-11:20
14  */
15 public class PTEncryptionUtil {
16
1ffbaa 17
135164 18     /*
W 19      * 日期加密
20      * date  要加密的日期
21      * */
22     public static String  encryption(Date date){
23         Calendar cal=Calendar.getInstance();
24         cal.setTime(date);
1ffbaa 25         StringBuffer data = new StringBuffer();
W 26         data.append(cal.get(Calendar.DATE));
27         data.append(cal.get(Calendar.MONTH));
28         data.append(cal.get(Calendar.YEAR));
29         data.append(cal.get(Calendar.SECOND));
30         data.append(cal.get(Calendar.MINUTE));
31         data.append(cal.get(Calendar.HOUR_OF_DAY));
135164 32
1ffbaa 33         return com.hx.mp.util.MD5Util.MD5Encode(data.toString(),"");
135164 34     }
1ffbaa 35
W 36     /**
37      *
38      * @param data 签名
39      * @param date 时间
40      * @param time 有效时间 秒
41      * @return
42      */
43     public static PTConstant decode(String data,Date date,Integer time){
44         PTConstant ptConstant = new PTConstant();
45         ptConstant.setSuccess(true);
46         if (StringUtils.isEmpty(data)){
47             ptConstant.setSuccess(false);
48             ptConstant.setErrCode(PTConstant.PT_SIGN_EEMPLY);
49             return ptConstant;
50         }
51         if (null == date){
52             ptConstant.setSuccess(false);
53             ptConstant.setErrCode(PTConstant.PT_TIMELS_EMPLY);
54             return ptConstant;
55         }
56
57         if(!encryption(date).equals(data)){
58             ptConstant.setSuccess(false);
59             ptConstant.setErrCode(PTConstant.PT_SIGN_ERROR);
60             return ptConstant;
61         }
62         if(time == null){
63             ptConstant.setSuccess(true);
64             return ptConstant;
65         }
66         //有效时间判断
67         if (DateUtil.calLastedTime(date) > time){
68             ptConstant.setSuccess(false);
69             ptConstant.setErrCode(PTConstant.PT_ORER_TIME);
70             return ptConstant;
71         }
72
73         return ptConstant;
74     }
75
135164 76 }