fix: 微信支付,创建失败,问题修复。

This commit is contained in:
tianyongbao
2026-04-04 00:44:12 +08:00
parent 0b006725bd
commit bb2e0f1987
3 changed files with 25 additions and 7 deletions

View File

@@ -59,13 +59,16 @@ public class WxPayConfiguration {
log.info("使用私钥路径配置: {}", wxPayProperties.getPrivateKeyPath());
}
// 商户证书配置(V3 API必须apiclient_cert.pem
if (wxPayProperties.getPrivateCertContent() != null && !wxPayProperties.getPrivateCertContent().isEmpty()) {
payConfig.setPrivateCertContent(wxPayProperties.getPrivateCertContent().getBytes(java.nio.charset.StandardCharsets.UTF_8));
// 商户证书配置apiclient_cert.pem有真实PEM内容才设置避免占位符导致v3请求构造异常
String privateCertContent = wxPayProperties.getPrivateCertContent();
if (privateCertContent != null && privateCertContent.startsWith("-----BEGIN CERTIFICATE-----")) {
payConfig.setPrivateCertContent(privateCertContent.getBytes(java.nio.charset.StandardCharsets.UTF_8));
log.info("使用商户证书内容配置");
} else if (wxPayProperties.getPrivateCertPath() != null) {
payConfig.setPrivateCertPath(wxPayProperties.getPrivateCertPath());
log.info("使用商户证书路径配置: {}", wxPayProperties.getPrivateCertPath());
} else {
log.info("未配置商户证书,将使用私钥直接签名");
}
WxPayService wxPayService = new WxPayServiceImpl();

View File

@@ -4,6 +4,7 @@ import cn.hutool.core.date.DateUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.intc.common.core.exception.ServiceException;
import com.intc.fishery.constant.DefineDeviceWarnCode;
import com.intc.fishery.domain.Device;
import com.intc.fishery.domain.PayDevice;
import com.intc.fishery.domain.PayOrder;
@@ -313,15 +314,22 @@ public class PayOrderBusinessServiceImpl implements PayOrderBusinessService {
// 计算新的到期时间
Date newDeadTime = calculateNewDeadTime(device.getDeadTime(), payDevice.getAddMonth());
// 更新设备到期时间
// 清除 warnCode 中的「设备到期」标志位(续费后恢复正常状态)
Integer oldWarnCode = device.getWarnCode();
Integer newWarnCode = oldWarnCode != null
? (oldWarnCode & ~DefineDeviceWarnCode.DeviceTimeDead)
: 0;
// 更新设备到期时间,并同步清除到期告警位
deviceMapper.update(null,
new LambdaUpdateWrapper<Device>()
.eq(Device::getId, device.getId())
.set(Device::getDeadTime, newDeadTime)
.set(Device::getWarnCode, newWarnCode)
);
log.info("更新设备到期时间: deviceId={}, serialNum={}, newDeadTime={}",
device.getId(), device.getSerialNum(), newDeadTime);
log.info("续费成功,更新设备到期时间并清除到期告警: deviceId={}, serialNum={}, newDeadTime={}, oldWarnCode={}, newWarnCode={}",
device.getId(), device.getSerialNum(), newDeadTime, oldWarnCode, newWarnCode);
}
}