From 6306618e5aa9ed532c14dc4b0b3690d5b8163165 Mon Sep 17 00:00:00 2001 From: zhaoqiaobo <583671871@qq.com> Date: Wed, 2 Apr 2025 15:05:21 +0800 Subject: [PATCH] =?UTF-8?q?feat(all):=20=E7=99=BE=E5=BE=97=E8=83=9C?= =?UTF-8?q?=E5=B7=A5=E5=8E=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 1 增加百得胜工厂数据对接 --- .../FactoryAccountsInterceptor.java | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/blade-service/logpm-factory-data/logpm-factory-data-paterson/src/main/java/com/logpm/factorydata/paterson/interceptor/FactoryAccountsInterceptor.java b/blade-service/logpm-factory-data/logpm-factory-data-paterson/src/main/java/com/logpm/factorydata/paterson/interceptor/FactoryAccountsInterceptor.java index 7097255c3..3b7abf9f9 100644 --- a/blade-service/logpm-factory-data/logpm-factory-data-paterson/src/main/java/com/logpm/factorydata/paterson/interceptor/FactoryAccountsInterceptor.java +++ b/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();