fix: 微信支付,改为http。
This commit is contained in:
@@ -1,81 +1,19 @@
|
||||
package com.intc.weixin.config;
|
||||
|
||||
import com.github.binarywang.wxpay.config.WxPayConfig;
|
||||
import com.github.binarywang.wxpay.service.WxPayService;
|
||||
import com.github.binarywang.wxpay.service.impl.WxPayServiceImpl;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
|
||||
/**
|
||||
* 微信支付配置
|
||||
* 微信支付配置(原生HTTP实现,无需SDK Bean)
|
||||
* 配置参数通过 WxPayProperties 和 WxMaProperties 自动注入
|
||||
*
|
||||
* @author intc
|
||||
*/
|
||||
@Slf4j
|
||||
@Configuration
|
||||
@RequiredArgsConstructor
|
||||
@ConditionalOnProperty(prefix = "wx.pay", name = "mch-id")
|
||||
public class WxPayConfiguration {
|
||||
|
||||
private final WxPayProperties wxPayProperties;
|
||||
private final WxMaProperties wxMaProperties;
|
||||
|
||||
@Bean
|
||||
public WxPayService wxPayService() {
|
||||
WxPayConfig payConfig = new WxPayConfig();
|
||||
|
||||
// 基础配置
|
||||
payConfig.setAppId(wxMaProperties.getAppId());
|
||||
payConfig.setMchId(wxPayProperties.getMchId());
|
||||
|
||||
// V2配置
|
||||
if (wxPayProperties.getMchKey() != null) {
|
||||
payConfig.setMchKey(wxPayProperties.getMchKey());
|
||||
}
|
||||
|
||||
// V3配置
|
||||
if (wxPayProperties.getApiV3Key() != null) {
|
||||
payConfig.setApiV3Key(wxPayProperties.getApiV3Key());
|
||||
}
|
||||
|
||||
if (wxPayProperties.getCertSerialNo() != null) {
|
||||
payConfig.setCertSerialNo(wxPayProperties.getCertSerialNo());
|
||||
}
|
||||
|
||||
// 证书配置
|
||||
if (wxPayProperties.getKeyPath() != null) {
|
||||
payConfig.setKeyPath(wxPayProperties.getKeyPath());
|
||||
}
|
||||
|
||||
// 私钥配置:优先使用privateContent,避免文件不存在的问题
|
||||
if (wxPayProperties.getPrivateContent() != null && !wxPayProperties.getPrivateContent().isEmpty()) {
|
||||
payConfig.setPrivateKeyContent(wxPayProperties.getPrivateContent().getBytes(java.nio.charset.StandardCharsets.UTF_8));
|
||||
log.info("使用私钥内容配置");
|
||||
} else if (wxPayProperties.getPrivateKeyPath() != null) {
|
||||
payConfig.setPrivateKeyPath(wxPayProperties.getPrivateKeyPath());
|
||||
log.info("使用私钥路径配置: {}", wxPayProperties.getPrivateKeyPath());
|
||||
}
|
||||
|
||||
// 商户证书配置(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();
|
||||
wxPayService.setConfig(payConfig);
|
||||
|
||||
log.info("微信支付服务初始化完成,商户号: {}", wxPayProperties.getMchId());
|
||||
|
||||
return wxPayService;
|
||||
}
|
||||
// 原生HTTP实现,无需初始化SDK的WxPayService Bean
|
||||
// 配置参数自动注入到 WxPayProperties 和 WxMaProperties
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user