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;
|
}
|
|
}
|