提交 | 用户 | age
|
826b66
|
1 |
package com.hx.encryption; |
C |
2 |
|
|
3 |
import com.hx.util.DateUtil; |
|
4 |
import com.hx.util.MD5Util; |
|
5 |
import com.hx.util.StringUtils; |
|
6 |
|
|
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 |
|
|
17 |
|
|
18 |
/* |
|
19 |
* 日期加密 |
|
20 |
* date 要加密的日期 |
|
21 |
* */ |
|
22 |
public static String encryption(Date date){ |
|
23 |
Calendar cal=Calendar.getInstance(); |
|
24 |
cal.setTime(date); |
|
25 |
StringBuffer data = new StringBuffer(); |
|
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)); |
|
32 |
|
|
33 |
return com.hx.mp.util.MD5Util.MD5Encode(data.toString(),""); |
|
34 |
} |
|
35 |
|
|
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 |
|
|
76 |
} |