🎨 #3838 【微信支付】为starter添加了退款结果回调 URL 的配置支持,允许开发者在配置文件中统一配置退款通知地址

This commit is contained in:
buaazyl
2026-01-09 14:16:06 +08:00
committed by GitHub
parent 2c5a33917e
commit 72fa3b3301
8 changed files with 32 additions and 9 deletions

View File

@@ -133,10 +133,10 @@
**Spring Boot 配置示例:** **Spring Boot 配置示例:**
```properties ```properties
# 使用 HttpClient 5.x推荐MP/CP/Channel/QiDian 模块默认) # 使用 HttpClient 5.x推荐MP/MiniApp/CP/Channel/QiDian 模块默认)
wx.mp.config-storage.http-client-type=HttpComponents wx.mp.config-storage.http-client-type=HttpComponents
# 使用 HttpClient 4.x兼容模式MiniApp 模块默认 # 使用 HttpClient 4.x兼容模式
wx.mp.config-storage.http-client-type=HttpClient wx.mp.config-storage.http-client-type=HttpClient
# 使用 OkHttp # 使用 OkHttp
@@ -153,11 +153,10 @@ wx.mp.config-storage.http-client-type=HTTP_COMPONENTS # 注意使用大写下
``` ```
**注意事项:** **注意事项:**
1. **MiniApp 模块**已提供 `HttpComponents`HttpClient 5.x类型的配置选项但当前默认仍为 HttpClient 4.x如需启用 HttpClient 5.x请确保所使用的集成模块`wx-java-miniapp-spring-boot-starter``wx-java-miniapp-solon-plugin`)版本已支持该选项 1. **MP、MiniApp、Channel、QiDian 模块**已完整支持 HttpClient 5.x默认推荐使用
2. **MP、Channel、QiDian 模块**已完整支持 HttpClient 5.x默认推荐使用 2. **CP 模块**的支持情况取决于具体使用的 Starter 版本,请参考对应模块文档
3. **CP 模块**的支持情况取决于具体使用的 Starter 版本,请参考对应模块文档 3. 如需使用 OkHttp 或 Jodd-http需在项目中添加对应的依赖scope为provided
4. 如需使用 OkHttp 或 Jodd-http需在项目中添加对应的依赖scope为provided 4. HttpClient 4.x 和 HttpClient 5.x 可以共存,按需配置即可
5. HttpClient 4.x 和 HttpClient 5.x 可以共存,按需配置即可
--------------------------------- ---------------------------------

View File

@@ -47,6 +47,7 @@ public class WxPayAutoConfiguration {
payConfig.setKeyPath(StringUtils.trimToNull(this.properties.getKeyPath())); payConfig.setKeyPath(StringUtils.trimToNull(this.properties.getKeyPath()));
payConfig.setUseSandboxEnv(this.properties.isUseSandboxEnv()); payConfig.setUseSandboxEnv(this.properties.isUseSandboxEnv());
payConfig.setNotifyUrl(StringUtils.trimToNull(this.properties.getNotifyUrl())); payConfig.setNotifyUrl(StringUtils.trimToNull(this.properties.getNotifyUrl()));
payConfig.setRefundNotifyUrl(StringUtils.trimToNull(this.properties.getRefundNotifyUrl()));
//以下是apiv3以及支付分相关 //以下是apiv3以及支付分相关
payConfig.setServiceId(StringUtils.trimToNull(this.properties.getServiceId())); payConfig.setServiceId(StringUtils.trimToNull(this.properties.getServiceId()));
payConfig.setPayScoreNotifyUrl(StringUtils.trimToNull(this.properties.getPayScoreNotifyUrl())); payConfig.setPayScoreNotifyUrl(StringUtils.trimToNull(this.properties.getPayScoreNotifyUrl()));

View File

@@ -87,6 +87,11 @@ public class WxPayProperties {
*/ */
private String notifyUrl; private String notifyUrl;
/**
* 退款结果异步回调地址通知url必须为直接可访问的url不能携带参数.
*/
private String refundNotifyUrl;
/** /**
* 微信支付分授权回调地址 * 微信支付分授权回调地址
*/ */

View File

@@ -51,6 +51,7 @@ public class WxPayAutoConfiguration {
payConfig.setKeyPath(StringUtils.trimToNull(this.properties.getKeyPath())); payConfig.setKeyPath(StringUtils.trimToNull(this.properties.getKeyPath()));
payConfig.setUseSandboxEnv(this.properties.isUseSandboxEnv()); payConfig.setUseSandboxEnv(this.properties.isUseSandboxEnv());
payConfig.setNotifyUrl(StringUtils.trimToNull(this.properties.getNotifyUrl())); payConfig.setNotifyUrl(StringUtils.trimToNull(this.properties.getNotifyUrl()));
payConfig.setRefundNotifyUrl(StringUtils.trimToNull(this.properties.getRefundNotifyUrl()));
//以下是apiv3以及支付分相关 //以下是apiv3以及支付分相关
payConfig.setServiceId(StringUtils.trimToNull(this.properties.getServiceId())); payConfig.setServiceId(StringUtils.trimToNull(this.properties.getServiceId()));
payConfig.setPayScoreNotifyUrl(StringUtils.trimToNull(this.properties.getPayScoreNotifyUrl())); payConfig.setPayScoreNotifyUrl(StringUtils.trimToNull(this.properties.getPayScoreNotifyUrl()));

View File

@@ -64,6 +64,11 @@ public class WxPayProperties {
*/ */
private String notifyUrl; private String notifyUrl;
/**
* 退款结果异步回调地址通知url必须为直接可访问的url不能携带参数
*/
private String refundNotifyUrl;
/** /**
* 微信支付分回调地址 * 微信支付分回调地址
*/ */

View File

@@ -230,7 +230,9 @@ public class WxPayRefundRequest extends BaseWxPayRequest {
if (StringUtils.isBlank(this.getOpUserId())) { if (StringUtils.isBlank(this.getOpUserId())) {
this.setOpUserId(config.getMchId()); this.setOpUserId(config.getMchId());
} }
if (StringUtils.isBlank(this.getNotifyUrl())) {
this.setNotifyUrl(config.getRefundNotifyUrl());
}
super.checkAndSign(config); super.checkAndSign(config);
} }

View File

@@ -97,9 +97,13 @@ public class WxPayConfig {
*/ */
private String subMchId; private String subMchId;
/** /**
* 微信支付异步回地址通知url必须为直接可访问的url不能携带参数. * 微信支付异步回地址通知url必须为直接可访问的url不能携带参数.
*/ */
private String notifyUrl; private String notifyUrl;
/**
* 退款结果异步回调地址通知url必须为直接可访问的url不能携带参数.
*/
private String refundNotifyUrl;
/** /**
* 交易类型. * 交易类型.
* <pre> * <pre>

View File

@@ -263,6 +263,9 @@ public abstract class BaseWxPayServiceImpl implements WxPayService {
@Override @Override
public WxPayRefundV3Result refundV3(WxPayRefundV3Request request) throws WxPayException { public WxPayRefundV3Result refundV3(WxPayRefundV3Request request) throws WxPayException {
if (StringUtils.isBlank(request.getNotifyUrl())) {
request.setNotifyUrl(this.getConfig().getRefundNotifyUrl());
}
String url = String.format("%s/v3/refund/domestic/refunds", this.getPayBaseUrl()); String url = String.format("%s/v3/refund/domestic/refunds", this.getPayBaseUrl());
String response = this.postV3WithWechatpaySerial(url, GSON.toJson(request)); String response = this.postV3WithWechatpaySerial(url, GSON.toJson(request));
return GSON.fromJson(response, WxPayRefundV3Result.class); return GSON.fromJson(response, WxPayRefundV3Result.class);
@@ -270,6 +273,9 @@ public abstract class BaseWxPayServiceImpl implements WxPayService {
@Override @Override
public WxPayRefundV3Result partnerRefundV3(WxPayPartnerRefundV3Request request) throws WxPayException { public WxPayRefundV3Result partnerRefundV3(WxPayPartnerRefundV3Request request) throws WxPayException {
if (StringUtils.isBlank(request.getNotifyUrl())) {
request.setNotifyUrl(this.getConfig().getRefundNotifyUrl());
}
if (StringUtils.isBlank(request.getSubMchid())) { if (StringUtils.isBlank(request.getSubMchid())) {
request.setSubMchid(this.getConfig().getSubMchId()); request.setSubMchid(this.getConfig().getSubMchId());
} }