封装第三方接口对外提供服务 时间的处理

封装时间检查的接口

timestampValidDate(timestamp);

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;

}





根据不同的返回码来处理



//timestamp验证
Integer timestampResult = commonService.timestampValidDate(timestamp);
if(timestampResult == ConstantConfig.TIMESTAMP_VALIDDATE_FORMAT_ERROR){
ResponseUtil.responseObject2App(response, map, ResponseUtil.STATUS_ERROR_PARAM, "timestamp format  error" ,callback);
return;
}

if(timestampResult == ConstantConfig.TIMESTAMP_VALIDDATE_TIME_OUT){
ResponseUtil.responseObject2App(response, map, ResponseUtil.STATUS_TIME_OUT, "Time must be within 5 minutes" ,callback);
return;
}
if(timestampResult == ConstantConfig.TIMESTAMP_VALIDDATE_SYSTEM_ERROR){
ResponseUtil.responseObject2App(response, map, ResponseUtil.STATUS_FAIL, "system error" ,callback);
return;
}

阅读更多
版权声明: https://blog.csdn.net/yz18931904/article/details/80697310
个人分类: 对外提供接口
上一篇目前为止时间都是13位的
下一篇对外提供接口的规则定制 限制 约束 签名的设计
想对作者说点什么? 我来说一句

没有更多推荐了,返回首页

关闭
关闭
关闭