|
|
@@ -15,7 +15,6 @@ import org.springframework.context.annotation.Configuration;
|
|
|
import org.springframework.core.io.Resource;
|
|
|
import org.springframework.core.io.ResourceLoader;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
-import org.springframework.beans.factory.annotation.Qualifier;
|
|
|
|
|
|
import jakarta.annotation.PostConstruct;
|
|
|
import java.io.IOException;
|
|
|
@@ -73,7 +72,6 @@ public class WxPayConfig {
|
|
|
log.info("初始化微信支付 V3 SDK 配置 - 商户号: {}, AppID: {}", mchId, appId);
|
|
|
|
|
|
try {
|
|
|
- // 读取私钥内容
|
|
|
String privateKeyContent = loadPrivateKey();
|
|
|
|
|
|
Config config = new RSAAutoCertificateConfig.Builder()
|
|
|
@@ -88,8 +86,7 @@ public class WxPayConfig {
|
|
|
} catch (Exception e) {
|
|
|
log.error("微信支付 V3 SDK 配置初始化失败: {}", e.getMessage());
|
|
|
log.warn("微信支付功能将不可用,请检查配置参数和证书文件");
|
|
|
- // 返回 null,下游 Bean 创建时会跳过
|
|
|
- return null;
|
|
|
+ throw new IllegalStateException("微信支付配置初始化失败: " + e.getMessage(), e);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
@@ -98,10 +95,6 @@ public class WxPayConfig {
|
|
|
*/
|
|
|
@Bean
|
|
|
public JsapiServiceExtension jsapiServiceExtension(Config wxPaySdkConfig) {
|
|
|
- if (wxPaySdkConfig == null) {
|
|
|
- log.warn("微信支付 SDK 配置未初始化,JSAPI 服务不可用");
|
|
|
- return null;
|
|
|
- }
|
|
|
return new JsapiServiceExtension.Builder().config(wxPaySdkConfig).build();
|
|
|
}
|
|
|
|
|
|
@@ -110,10 +103,6 @@ public class WxPayConfig {
|
|
|
*/
|
|
|
@Bean
|
|
|
public RefundService wxRefundService(Config wxPaySdkConfig) {
|
|
|
- if (wxPaySdkConfig == null) {
|
|
|
- log.warn("微信支付 SDK 配置未初始化,退款服务不可用");
|
|
|
- return null;
|
|
|
- }
|
|
|
return new RefundService.Builder().config(wxPaySdkConfig).build();
|
|
|
}
|
|
|
|
|
|
@@ -122,11 +111,6 @@ public class WxPayConfig {
|
|
|
*/
|
|
|
@Bean
|
|
|
public NotificationParser wxNotificationParser(Config wxPaySdkConfig) {
|
|
|
- if (wxPaySdkConfig == null) {
|
|
|
- log.warn("微信支付 SDK 配置未初始化,回调通知解析不可用");
|
|
|
- return null;
|
|
|
- }
|
|
|
- // RSAAutoCertificateConfig 实现了 NotificationConfig 接口
|
|
|
return new NotificationParser((NotificationConfig) wxPaySdkConfig);
|
|
|
}
|
|
|
|
|
|
@@ -148,14 +132,13 @@ public class WxPayConfig {
|
|
|
* 自动处理请求签名和响应验签
|
|
|
*/
|
|
|
@Bean
|
|
|
- @ConditionalOnProperty(name = "wechat.pay.mch-id")
|
|
|
- public com.wechat.pay.java.core.http.HttpClient wxPayHttpClient(
|
|
|
- @Qualifier("wxPaySdkConfig") com.wechat.pay.java.core.Config wxPaySdkConfig) {
|
|
|
+ public com.wechat.pay.java.core.http.HttpClient wxPayHttpClient(Config wxPaySdkConfig) {
|
|
|
return new com.wechat.pay.java.core.http.DefaultHttpClientBuilder()
|
|
|
.config(wxPaySdkConfig)
|
|
|
.build();
|
|
|
}
|
|
|
|
|
|
+
|
|
|
@PostConstruct
|
|
|
public void logConfig() {
|
|
|
log.info("微信支付配置加载完成 - AppID: {}, 商户号: {}, 回调地址: {}", appId, mchId, notifyUrl);
|