chenjiahe
2022-03-31 b5bfe58beeeeb8343bdea6a9412f8f6704b67633
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
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;
 
/*
 * @Description: his助手调用 phitab 订单加密工具
 * @Author: wangrenhuang
 * @Date:  2022/2/15-11:20
 */
public class PTEncryptionUtil {
 
 
    /*
     * 日期加密
     * date  要加密的日期
     * */
    public static String  encryption(Date date){
        Calendar cal=Calendar.getInstance();
        cal.setTime(date);
        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));
 
        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;
    }
 
}