fix(cert): 修复生产环境证书路径拼接问题
- 更新了 CertificateProperties 和 ShopOrderController 中的证书路径拼接逻辑 -增加了对数据库中存储路径的特殊处理,支持不同格式的路径拼接 - 优化了日志输出,增加了证书路径的相关信息
This commit is contained in:
@@ -155,7 +155,23 @@ public class CertificateProperties {
|
|||||||
* @return 完整路径
|
* @return 完整路径
|
||||||
*/
|
*/
|
||||||
public String getWechatPayCertPath(String fileName) {
|
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);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -368,12 +368,25 @@ public class ShopOrderController extends BaseController {
|
|||||||
} else {
|
} else {
|
||||||
// 生产环境 - 使用自动证书配置
|
// 生产环境 - 使用自动证书配置
|
||||||
final String certRootPath = certConfig.getCertRootPath();
|
final String certRootPath = certConfig.getCertRootPath();
|
||||||
final String certBasePath = certRootPath + "/file";
|
logger.info("生产环境证书根路径: {}", certRootPath);
|
||||||
|
|
||||||
String privateKeyRelativePath = payment.getApiclientKey();
|
String privateKeyRelativePath = payment.getApiclientKey();
|
||||||
String privateKeyFullPath = privateKeyRelativePath.startsWith("/")
|
logger.info("数据库中的私钥相对路径: {}", privateKeyRelativePath);
|
||||||
? certBasePath + privateKeyRelativePath
|
|
||||||
: certBasePath + "/" + 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 privateKey = certificateLoader.loadCertificatePath(privateKeyFullPath);
|
||||||
String apiV3Key = payment.getApiKey();
|
String apiV3Key = payment.getApiKey();
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user