Browse Source

fix(cert): 修复生产环境证书路径拼接问题

- 更新了 CertificateProperties 和 ShopOrderController 中的证书路径拼接逻辑
-增加了对数据库中存储路径的特殊处理,支持不同格式的路径拼接
- 优化了日志输出,增加了证书路径的相关信息
pan
科技小王子 1 month ago
parent
commit
a45bf916ec
  1. 16
      src/main/java/com/gxwebsoft/common/core/config/CertificateProperties.java
  2. 21
      src/main/java/com/gxwebsoft/shop/controller/ShopOrderController.java

16
src/main/java/com/gxwebsoft/common/core/config/CertificateProperties.java

@ -155,8 +155,24 @@ public class CertificateProperties {
* @return 完整路径
*/
public String getWechatPayCertPath(String 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);
}
}
/**
* 获取支付宝证书路径

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

Loading…
Cancel
Save