修复微信支付,兼容公钥模块

This commit is contained in:
2025-07-29 13:06:56 +08:00
parent 764974b3d1
commit c1a3d674ec
5 changed files with 161 additions and 4 deletions

View File

@@ -44,7 +44,7 @@ public class PaymentCacheService {
if (ObjectUtil.isNotEmpty(payment)) {
log.debug("从缓存获取支付配置成功: {}", primaryKey);
// return payment;
return payment;
}
// 2. 如果 Payment:1* 格式不存在,尝试原有格式
@@ -55,13 +55,14 @@ public class PaymentCacheService {
log.debug("从兜底缓存获取支付配置成功: {}", fallbackKey);
// 将查询结果缓存到 Payment:1* 格式
redisUtil.set(primaryKey, payment);
// return payment;
return payment;
}
// 3. 最后从数据库查询
log.debug("从数据库查询支付配置, payType: {}, tenantId: {}", payType, tenantId);
PaymentParam paymentParam = new PaymentParam();
paymentParam.setType(payType);
paymentParam.setTenantId(tenantId); // 设置租户ID进行过滤
List<Payment> payments = paymentService.listRel(paymentParam);
if (payments.isEmpty()) {

View File

@@ -55,6 +55,9 @@
<if test="param.deleted == null">
AND a.deleted = 0
</if>
<if test="param.tenantId != null">
AND a.tenant_id = #{param.tenantId}
</if>
<if test="param.createTimeStart != null">
AND a.create_time &gt;= #{param.createTimeStart}
</if>

View File

@@ -74,4 +74,8 @@ public class PaymentParam extends BaseParam {
@QueryField(type = QueryType.EQ)
private Integer deleted;
@Schema(description = "租户ID")
@QueryField(type = QueryType.EQ)
private Integer tenantId;
}

View File

@@ -252,6 +252,9 @@ import com.gxwebsoft.common.core.service.PaymentCacheService;
* @return
*/
public Payment getPayment(ShopOrder order) {
// 先清除可能的错误缓存
paymentCacheService.removePaymentConfig(order.getPayType().toString(), order.getTenantId());
Payment payment = paymentCacheService.getPaymentConfig(order.getPayType(), order.getTenantId());
// 添加详细的支付配置检查
@@ -532,8 +535,18 @@ import com.gxwebsoft.common.core.service.PaymentCacheService;
System.out.println("公钥ID: " + payment.getPubKeyId());
try {
// 生产环境直接使用数据库中存储的完整路径
String pubKeyFile = certificateLoader.loadCertificatePath(payment.getPubKey());
// 生产环境处理公钥路径
String pubKeyPath = payment.getPubKey();
// 如果路径不是以 /file 开头,需要添加 /file 前缀
if (!pubKeyPath.startsWith("/file/") && !pubKeyPath.startsWith("file/")) {
pubKeyPath = "file/" + pubKeyPath;
System.out.println("生产环境公钥路径修正: " + payment.getPubKey() + " -> " + pubKeyPath);
} else {
System.out.println("生产环境公钥路径: " + pubKeyPath);
}
String pubKeyFile = certificateLoader.loadCertificatePath(pubKeyPath);
System.out.println("✅ 生产环境公钥文件加载成功: " + pubKeyFile);
config = new RSAPublicKeyConfig.Builder()