业务场景 给定的url有可能被别人盗取,这个时候给定10分钟的有效时间,超过这个范围,签名是无效的,保证了安全性
public Integer timestampValidDate (Long timestamp){
String timestampTmp = timestamp.toString();//timestamp精确到秒,长度是10位
if(timestampTmp.length() != 10){
logger.error("ERROR->CommonServiceImpl-->timestampValidDate|ERROR = timestamp length error|param:timestamp = "+timestamp);
return ConstantConfig.TIMESTAMP_VALIDDATE_FORMAT_ERROR;
}
Long nowTimestamp = System.currentTimeMillis()/1000;
Long startTimestamp = nowTimestamp - 300;
Long endTimestamp = nowTimestamp + 300;
if(startTimestamp == null || endTimestamp == null){
logger.error("ERROR->CommonServiceImpl-->timestampValidDate|ERROR = startTimestamp or endTimestamp is null|"
+"param:"+"startTimestamp="+startTimestamp+"|endTimestamp="+endTimestamp);
return ConstantConfig.TIMESTAMP_VALIDDATE_SYSTEM_ERROR;
}
if(timestamp > startTimestamp && timestamp < endTimestamp){
return ConstantConfig.TIMESTAMP_VALIDDATE_SUCCESS;
}
return ConstantConfig.TIMESTAMP_VALIDDATE_TIME_OUT;
}