You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
66 lines
1.6 KiB
66 lines
1.6 KiB
4 years ago
|
package com.tptj.demo.hg.parameter.decode;
|
||
|
|
||
|
import com.fr.intelli.record.Focus;
|
||
|
import com.fr.record.analyzer.EnableMetrics;
|
||
|
import com.fr.stable.CodeUtils;
|
||
|
import com.fr.stable.StringUtils;
|
||
|
|
||
|
/**
|
||
|
* @author 秃破天际
|
||
|
* @version 10.0
|
||
|
* Created by 秃破天际 on 2021/7/11
|
||
|
**/
|
||
|
@EnableMetrics
|
||
|
public class Sign {
|
||
|
private String md5;
|
||
|
private long timestamp;
|
||
|
private long timeout;
|
||
|
|
||
|
private Sign(String md5, long timestamp, long timeout) {
|
||
|
this.md5 = md5;
|
||
|
this.timestamp = timestamp;
|
||
|
this.timeout = timeout;
|
||
|
}
|
||
|
|
||
|
private final static Sign EMPTY = new Sign(StringUtils.EMPTY,0,0);
|
||
|
|
||
|
/**
|
||
|
* 解析签名
|
||
|
* @param sign
|
||
|
* @return
|
||
|
*/
|
||
|
public static Sign parse( String sign ){
|
||
|
try{
|
||
|
String md5 = sign.substring(0,32);
|
||
|
long timestamp = Long.parseLong( sign.substring(33,46) );
|
||
|
long timeout = Long.parseLong( sign.substring(47) );
|
||
|
return new Sign(md5,timestamp,timeout);
|
||
|
}catch(Exception e){
|
||
|
|
||
|
}
|
||
|
return EMPTY;
|
||
|
}
|
||
|
|
||
|
/**
|
||
|
* 检验超时
|
||
|
* @return
|
||
|
*/
|
||
|
public boolean isTimeout(){
|
||
|
long crt = System.currentTimeMillis();
|
||
|
return crt < timestamp || crt - timestamp > timeout;
|
||
|
}
|
||
|
|
||
|
/**
|
||
|
* 验签
|
||
|
* @param data
|
||
|
* @param secret
|
||
|
* @return
|
||
|
*/
|
||
|
@Focus(id = "com.tptj.demo.hg.parameter.decode.v10",text = "Parameter Decode")
|
||
|
public boolean check( String data, String secret ){
|
||
|
String source = data+secret+timestamp+timeout;
|
||
|
String md5 = CodeUtils.md5Encode(source, StringUtils.EMPTY,"MD5");
|
||
|
return StringUtils.equals(md5,this.md5);
|
||
|
}
|
||
|
}
|