From a45bf916ec670efa4c96271fc90393189b4a486c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=B5=B5=E5=BF=A0=E6=9E=97?= <170083662@qq.com> Date: Sat, 30 Aug 2025 23:03:10 +0800 Subject: [PATCH] =?UTF-8?q?fix(cert):=20=E4=BF=AE=E5=A4=8D=E7=94=9F?= =?UTF-8?q?=E4=BA=A7=E7=8E=AF=E5=A2=83=E8=AF=81=E4=B9=A6=E8=B7=AF=E5=BE=84?= =?UTF-8?q?=E6=8B=BC=E6=8E=A5=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 更新了 CertificateProperties 和 ShopOrderController 中的证书路径拼接逻辑 -增加了对数据库中存储路径的特殊处理,支持不同格式的路径拼接 - 优化了日志输出,增加了证书路径的相关信息 --- .../core/config/CertificateProperties.java | 18 +++++++++++++++- .../shop/controller/ShopOrderController.java | 21 +++++++++++++++---- 2 files changed, 34 insertions(+), 5 deletions(-) diff --git a/src/main/java/com/gxwebsoft/common/core/config/CertificateProperties.java b/src/main/java/com/gxwebsoft/common/core/config/CertificateProperties.java index 6da6bdc..d8cbb5e 100644 --- a/src/main/java/com/gxwebsoft/common/core/config/CertificateProperties.java +++ b/src/main/java/com/gxwebsoft/common/core/config/CertificateProperties.java @@ -155,7 +155,23 @@ public class CertificateProperties { * @return 完整路径 */ public String getWechatPayCertPath(String fileName) { - return getCertificatePath(wechatPay.getCertDir(), fileName); + // 生产环境特殊处理:数据库中存储的路径需要拼接到 /file/ 目录下 + if (loadMode == LoadMode.VOLUME) { + // 修复路径拼接逻辑:数据库中存储的路径如果已经包含 /file,则直接拼接 + if (fileName.startsWith("/file/")) { + // 路径已经包含 /file/ 前缀,直接拼接到根路径 + return certRootPath + fileName; + } else if (fileName.startsWith("file/")) { + // 路径包含 file/ 前缀,添加根路径和斜杠 + return certRootPath + "/" + fileName; + } else { + // 路径不包含 file 前缀,添加完整的 /file/ 前缀 + return certRootPath + "/file/" + fileName; + } + } else { + // 开发环境和文件系统模式使用原有逻辑 + return getCertificatePath(wechatPay.getCertDir(), fileName); + } } /** diff --git a/src/main/java/com/gxwebsoft/shop/controller/ShopOrderController.java b/src/main/java/com/gxwebsoft/shop/controller/ShopOrderController.java index b43425b..3d425ce 100644 --- a/src/main/java/com/gxwebsoft/shop/controller/ShopOrderController.java +++ b/src/main/java/com/gxwebsoft/shop/controller/ShopOrderController.java @@ -368,12 +368,25 @@ public class ShopOrderController extends BaseController { } else { // 生产环境 - 使用自动证书配置 final String certRootPath = certConfig.getCertRootPath(); - final String certBasePath = certRootPath + "/file"; + logger.info("生产环境证书根路径: {}", certRootPath); String privateKeyRelativePath = payment.getApiclientKey(); - String privateKeyFullPath = privateKeyRelativePath.startsWith("/") - ? certBasePath + privateKeyRelativePath - : certBasePath + "/" + privateKeyRelativePath; + logger.info("数据库中的私钥相对路径: {}", privateKeyRelativePath); + + // 修复路径拼接逻辑:数据库中存储的路径如果已经包含 /file,则直接拼接 + String privateKeyFullPath; + if (privateKeyRelativePath.startsWith("/file/")) { + // 路径已经包含 /file/ 前缀,直接拼接到根路径 + privateKeyFullPath = certRootPath + privateKeyRelativePath; + } else if (privateKeyRelativePath.startsWith("file/")) { + // 路径包含 file/ 前缀,添加根路径和斜杠 + privateKeyFullPath = certRootPath + "/" + privateKeyRelativePath; + } else { + // 路径不包含 file 前缀,添加完整的 /file/ 前缀 + privateKeyFullPath = certRootPath + "/file/" + privateKeyRelativePath; + } + + logger.info("生产环境私钥完整路径: {}", privateKeyFullPath); String privateKey = certificateLoader.loadCertificatePath(privateKeyFullPath); String apiV3Key = payment.getApiKey();