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();