Skip to content

Commit 72fa3b3

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

File tree

8 files changed

+32
-9
lines changed

8 files changed

+32
-9
lines changed

README.md

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -133,10 +133,10 @@
133133
**Spring Boot 配置示例:**
134134

135135
```properties
136-
# 使用 HttpClient 5.x(推荐,MP/CP/Channel/QiDian 模块默认)
136+
# 使用 HttpClient 5.x(推荐,MP/MiniApp/CP/Channel/QiDian 模块默认)
137137
wx.mp.config-storage.http-client-type=HttpComponents
138138

139-
# 使用 HttpClient 4.x(兼容模式,MiniApp 模块默认
139+
# 使用 HttpClient 4.x(兼容模式)
140140
wx.mp.config-storage.http-client-type=HttpClient
141141

142142
# 使用 OkHttp
@@ -153,11 +153,10 @@ wx.mp.config-storage.http-client-type=HTTP_COMPONENTS # 注意使用大写下
153153
```
154154

155155
**注意事项:**
156-
1. **MiniApp 模块**已提供 `HttpComponents`(HttpClient 5.x)类型的配置选项,但当前默认仍为 HttpClient 4.x;如需启用 HttpClient 5.x,请确保所使用的集成模块(如 `wx-java-miniapp-spring-boot-starter``wx-java-miniapp-solon-plugin`)版本已支持该选项
157-
2. **MP、Channel、QiDian 模块**已完整支持 HttpClient 5.x,默认推荐使用
158-
3. **CP 模块**的支持情况取决于具体使用的 Starter 版本,请参考对应模块文档
159-
4. 如需使用 OkHttp 或 Jodd-http,需在项目中添加对应的依赖(scope为provided)
160-
5. HttpClient 4.x 和 HttpClient 5.x 可以共存,按需配置即可
156+
1. **MP、MiniApp、Channel、QiDian 模块**已完整支持 HttpClient 5.x,默认推荐使用
157+
2. **CP 模块**的支持情况取决于具体使用的 Starter 版本,请参考对应模块文档
158+
3. 如需使用 OkHttp 或 Jodd-http,需在项目中添加对应的依赖(scope为provided)
159+
4. HttpClient 4.x 和 HttpClient 5.x 可以共存,按需配置即可
161160

162161

163162
---------------------------------

solon-plugins/wx-java-pay-solon-plugin/src/main/java/com/binarywang/solon/wxjava/pay/config/WxPayAutoConfiguration.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ public WxPayService wxPayService() {
4747
payConfig.setKeyPath(StringUtils.trimToNull(this.properties.getKeyPath()));
4848
payConfig.setUseSandboxEnv(this.properties.isUseSandboxEnv());
4949
payConfig.setNotifyUrl(StringUtils.trimToNull(this.properties.getNotifyUrl()));
50+
payConfig.setRefundNotifyUrl(StringUtils.trimToNull(this.properties.getRefundNotifyUrl()));
5051
//以下是apiv3以及支付分相关
5152
payConfig.setServiceId(StringUtils.trimToNull(this.properties.getServiceId()));
5253
payConfig.setPayScoreNotifyUrl(StringUtils.trimToNull(this.properties.getPayScoreNotifyUrl()));

solon-plugins/wx-java-pay-solon-plugin/src/main/java/com/binarywang/solon/wxjava/pay/properties/WxPayProperties.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,11 @@ public class WxPayProperties {
8787
*/
8888
private String notifyUrl;
8989

90+
/**
91+
* 退款结果异步回调地址,通知url必须为直接可访问的url,不能携带参数.
92+
*/
93+
private String refundNotifyUrl;
94+
9095
/**
9196
* 微信支付分授权回调地址
9297
*/

spring-boot-starters/wx-java-pay-spring-boot-starter/src/main/java/com/binarywang/spring/starter/wxjava/pay/config/WxPayAutoConfiguration.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ public WxPayService wxPayService() {
5151
payConfig.setKeyPath(StringUtils.trimToNull(this.properties.getKeyPath()));
5252
payConfig.setUseSandboxEnv(this.properties.isUseSandboxEnv());
5353
payConfig.setNotifyUrl(StringUtils.trimToNull(this.properties.getNotifyUrl()));
54+
payConfig.setRefundNotifyUrl(StringUtils.trimToNull(this.properties.getRefundNotifyUrl()));
5455
//以下是apiv3以及支付分相关
5556
payConfig.setServiceId(StringUtils.trimToNull(this.properties.getServiceId()));
5657
payConfig.setPayScoreNotifyUrl(StringUtils.trimToNull(this.properties.getPayScoreNotifyUrl()));

spring-boot-starters/wx-java-pay-spring-boot-starter/src/main/java/com/binarywang/spring/starter/wxjava/pay/properties/WxPayProperties.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,11 @@ public class WxPayProperties {
6464
*/
6565
private String notifyUrl;
6666

67+
/**
68+
* 退款结果异步回调地址,通知url必须为直接可访问的url,不能携带参数
69+
*/
70+
private String refundNotifyUrl;
71+
6772
/**
6873
* 微信支付分回调地址
6974
*/

weixin-java-pay/src/main/java/com/github/binarywang/wxpay/bean/request/WxPayRefundRequest.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -230,7 +230,9 @@ public void checkAndSign(WxPayConfig config) throws WxPayException {
230230
if (StringUtils.isBlank(this.getOpUserId())) {
231231
this.setOpUserId(config.getMchId());
232232
}
233-
233+
if (StringUtils.isBlank(this.getNotifyUrl())) {
234+
this.setNotifyUrl(config.getRefundNotifyUrl());
235+
}
234236
super.checkAndSign(config);
235237
}
236238

weixin-java-pay/src/main/java/com/github/binarywang/wxpay/config/WxPayConfig.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,9 +97,13 @@ public class WxPayConfig {
9797
*/
9898
private String subMchId;
9999
/**
100-
* 微信支付异步回掉地址,通知url必须为直接可访问的url,不能携带参数.
100+
* 微信支付异步回调地址,通知url必须为直接可访问的url,不能携带参数.
101101
*/
102102
private String notifyUrl;
103+
/**
104+
* 退款结果异步回调地址,通知url必须为直接可访问的url,不能携带参数.
105+
*/
106+
private String refundNotifyUrl;
103107
/**
104108
* 交易类型.
105109
* <pre>

weixin-java-pay/src/main/java/com/github/binarywang/wxpay/service/impl/BaseWxPayServiceImpl.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -263,13 +263,19 @@ public WxPayRefundResult refundV2(WxPayRefundRequest request) throws WxPayExcept
263263

264264
@Override
265265
public WxPayRefundV3Result refundV3(WxPayRefundV3Request request) throws WxPayException {
266+
if (StringUtils.isBlank(request.getNotifyUrl())) {
267+
request.setNotifyUrl(this.getConfig().getRefundNotifyUrl());
268+
}
266269
String url = String.format("%s/v3/refund/domestic/refunds", this.getPayBaseUrl());
267270
String response = this.postV3WithWechatpaySerial(url, GSON.toJson(request));
268271
return GSON.fromJson(response, WxPayRefundV3Result.class);
269272
}
270273

271274
@Override
272275
public WxPayRefundV3Result partnerRefundV3(WxPayPartnerRefundV3Request request) throws WxPayException {
276+
if (StringUtils.isBlank(request.getNotifyUrl())) {
277+
request.setNotifyUrl(this.getConfig().getRefundNotifyUrl());
278+
}
273279
if (StringUtils.isBlank(request.getSubMchid())) {
274280
request.setSubMchid(this.getConfig().getSubMchId());
275281
}

0 commit comments

Comments
 (0)