Skip to content

Commit 1eeb095

Browse files
authored
🎨 #3918 【微信支付】服务商退款(V3)请求对象补齐缺失字段 (sp_appid 和 sub_appid)
1 parent cd15fd7 commit 1eeb095

File tree

3 files changed

+87
-3
lines changed

3 files changed

+87
-3
lines changed

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

Lines changed: 26 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,15 +11,38 @@
1111
* 微信支付服务商退款请求
1212
* 文档见:https://pay.weixin.qq.com/wiki/doc/apiv3_partner/apis/chapter4_1_9.shtml
1313
*
14-
* @author Pursuer
15-
* @version 1.0
16-
* @date 2023/3/2
1714
*/
1815
@Data
1916
@NoArgsConstructor
2017
@Accessors(chain = true)
2118
public class WxPayPartnerRefundV3Request extends WxPayRefundV3Request implements Serializable {
2219
private static final long serialVersionUID = -1L;
20+
/**
21+
* <pre>
22+
* 字段名:服务商应用ID
23+
* 变量名:sp_appid
24+
* 是否必填:是
25+
* 类型:string[1, 32]
26+
* 描述:
27+
* 服务商申请的公众号或移动应用appid。
28+
* 示例值:wx8888888888888888
29+
* </pre>
30+
*/
31+
@SerializedName(value = "sp_appid")
32+
private String spAppid;
33+
/**
34+
* <pre>
35+
* 字段名:子商户应用ID
36+
* 变量名:sub_appid
37+
* 是否必填:否
38+
* 类型:string[1, 32]
39+
* 描述:
40+
* 子商户申请的公众号或移动应用appid。如果传了sub_appid,那sub_appid对应的订单必须存在。
41+
* 示例值:wx8888888888888888
42+
* </pre>
43+
*/
44+
@SerializedName(value = "sub_appid")
45+
private String subAppid;
2346
/**
2447
* <pre>
2548
* 字段名:退款资金来源

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
@@ -404,6 +404,12 @@ public WxPayRefundV3Result refundV3(WxPayRefundV3Request request) throws WxPayEx
404404

405405
@Override
406406
public WxPayRefundV3Result partnerRefundV3(WxPayPartnerRefundV3Request request) throws WxPayException {
407+
if (StringUtils.isBlank(request.getSpAppid())) {
408+
request.setSpAppid(this.getConfig().getAppId());
409+
}
410+
if (StringUtils.isBlank(request.getSubAppid()) && StringUtils.isNotBlank(this.getConfig().getSubAppId())) {
411+
request.setSubAppid(this.getConfig().getSubAppId());
412+
}
407413
if (StringUtils.isBlank(request.getNotifyUrl())) {
408414
request.setNotifyUrl(this.getConfig().getRefundNotifyUrl());
409415
}
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
package com.github.binarywang.wxpay.bean.request;
2+
3+
import com.google.gson.Gson;
4+
import com.google.gson.JsonObject;
5+
import org.testng.annotations.Test;
6+
7+
import static org.assertj.core.api.Assertions.assertThat;
8+
9+
/**
10+
* {@link WxPayPartnerRefundV3Request} 单元测试
11+
*
12+
*/
13+
public class WxPayPartnerRefundV3RequestTest {
14+
15+
@Test
16+
public void testSpAppidAndSubAppidSerialization() {
17+
WxPayPartnerRefundV3Request request = new WxPayPartnerRefundV3Request();
18+
request.setSpAppid("wx8888888888888888");
19+
request.setSubAppid("wxd678efh567hg6999");
20+
request.setSubMchid("1230000109");
21+
request.setOutRefundNo("1217752501201407033233368018");
22+
request.setFundsAccount("AVAILABLE");
23+
24+
Gson gson = new Gson();
25+
String json = gson.toJson(request);
26+
JsonObject jsonObject = gson.fromJson(json, JsonObject.class);
27+
28+
assertThat(jsonObject.has("sp_appid")).isTrue();
29+
assertThat(jsonObject.get("sp_appid").getAsString()).isEqualTo("wx8888888888888888");
30+
assertThat(jsonObject.has("sub_appid")).isTrue();
31+
assertThat(jsonObject.get("sub_appid").getAsString()).isEqualTo("wxd678efh567hg6999");
32+
assertThat(jsonObject.has("sub_mchid")).isTrue();
33+
assertThat(jsonObject.get("sub_mchid").getAsString()).isEqualTo("1230000109");
34+
assertThat(jsonObject.has("out_refund_no")).isTrue();
35+
assertThat(jsonObject.get("out_refund_no").getAsString()).isEqualTo("1217752501201407033233368018");
36+
assertThat(jsonObject.has("funds_account")).isTrue();
37+
assertThat(jsonObject.get("funds_account").getAsString()).isEqualTo("AVAILABLE");
38+
}
39+
40+
@Test
41+
public void testSubAppidIsOptional() {
42+
WxPayPartnerRefundV3Request request = new WxPayPartnerRefundV3Request();
43+
request.setSpAppid("wx8888888888888888");
44+
request.setSubMchid("1230000109");
45+
request.setOutRefundNo("1217752501201407033233368018");
46+
47+
Gson gson = new Gson();
48+
String json = gson.toJson(request);
49+
JsonObject jsonObject = gson.fromJson(json, JsonObject.class);
50+
51+
assertThat(jsonObject.has("sp_appid")).isTrue();
52+
assertThat(jsonObject.get("sp_appid").getAsString()).isEqualTo("wx8888888888888888");
53+
assertThat(jsonObject.has("sub_appid")).isFalse();
54+
}
55+
}

0 commit comments

Comments
 (0)