Browse Source

feat(all): 百得胜工厂

1 增加百得胜工厂数据对接
pre-production
zhaoqiaobo 3 days ago
parent
commit
6306618e5a
  1. 18
      blade-service/logpm-factory-data/logpm-factory-data-paterson/src/main/java/com/logpm/factorydata/paterson/interceptor/FactoryAccountsInterceptor.java

18
blade-service/logpm-factory-data/logpm-factory-data-paterson/src/main/java/com/logpm/factorydata/paterson/interceptor/FactoryAccountsInterceptor.java

@ -1,6 +1,9 @@
package com.logpm.factorydata.paterson.interceptor;
import cn.hutool.core.codec.Base64;
import cn.hutool.core.date.DateTime;
import cn.hutool.core.date.DateUnit;
import cn.hutool.core.date.DateUtil;
import cn.hutool.core.util.ObjectUtil;
import cn.hutool.core.util.StrUtil;
import cn.hutool.crypto.digest.MD5;
@ -35,7 +38,6 @@ import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;
import java.time.Instant;
import java.util.Objects;
import java.util.concurrent.TimeUnit;
@ -93,13 +95,23 @@ public class FactoryAccountsInterceptor implements HandlerInterceptor {
FactoryAuthVO authVO = jpFactoryShipmentService.findFactoryAuth(companyCode);
if (ObjectUtil.isNotEmpty(authVO)) {
Long authTime1 = authVO.getAuthTime();
long secondTimestamp = Instant.now().getEpochSecond();
// 验证时间 不能大于5秒
long secondTimestamp = DateUtil.current();
DateTime currentDate = DateUtil.date();
// 验证时间
if (secondTimestamp - authTime > authTime1) {
log.info("##########preHandle: 时间戳过期");
returnJson(response, JSONObject.toJSONString(R.fail("认证不通过,时间戳过期")));
return false;
}
// 将 authTime 转换为时间并与当前时间比较
DateTime authDateTime = DateUtil.date(authTime * 1000); // 将时间戳转换为 DateTime
// 将 authTime 转换为时间并与当前时间比较
long timeDifferenceInSeconds = DateUtil.between(authDateTime, currentDate, DateUnit.MS);
if (timeDifferenceInSeconds > authTime1) {
log.info("##########preHandle: 认证时间过期");
returnJson(response, JSONObject.toJSONString(R.fail("认证不通过,认证时间过期")));
return false;
}
// 验证签名
String auth = authVO.getAppKey();
String md5Hex = Base64.encode(MD5.create().digestHex(params + auth + authTime)).toUpperCase();

Loading…
Cancel
Save