Skip to content

Commit f795960

Browse files
authored
🎨 #4132 【微信支付】补齐商家转账收款样式参数
1 parent 11bff83 commit f795960

2 files changed

Lines changed: 61 additions & 0 deletions

File tree

‎weixin-java-pay/src/main/java/com/github/binarywang/wxpay/bean/transfer/TransferBillsRequest.java‎

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,25 @@ public class TransferBillsRequest implements Serializable {
8787
@SerializedName("transfer_scene_report_infos")
8888
private List<TransferSceneReportInfo> transferSceneReportInfos;
8989

90+
/**
91+
* 用户收款样式;不传时默认展示收款确认页。
92+
*/
93+
@SerializedName("user_recv_style")
94+
private UserRecvStyle userRecvStyle;
95+
96+
/**
97+
* 保留原有全参构造函数,所有参数语义不变,用户收款样式默认不设置。
98+
*/
99+
public TransferBillsRequest(String appid, String outBillNo, String transferSceneId,
100+
String openid, String userName, Integer transferAmount, String transferRemark,
101+
String notifyUrl, String userRecvPerception,
102+
List<TransferSceneReportInfo> transferSceneReportInfos, AuthorizationInfo authorizationInfo,
103+
String authorizationId, String outAuthorizationNo, String receiptAuthorizationMode) {
104+
this(appid, outBillNo, transferSceneId, openid, userName, transferAmount, transferRemark,
105+
notifyUrl, userRecvPerception, transferSceneReportInfos, null, authorizationInfo,
106+
authorizationId, outAuthorizationNo, receiptAuthorizationMode);
107+
}
108+
90109
/**
91110
* 自动收款授权信息
92111
*/
@@ -144,6 +163,21 @@ public static class TransferSceneReportInfo {
144163
private String infoContent;
145164
}
146165

166+
/**
167+
* 用户收款样式。
168+
*/
169+
@Data
170+
@Builder(builderMethodName = "newBuilder")
171+
@AllArgsConstructor
172+
@NoArgsConstructor
173+
public static class UserRecvStyle {
174+
/**
175+
* 样式类型:CONFIRM_PAGE 为收款确认页,RED_PACKET 为红包;红包仅支持部分转账场景且单笔金额不超过 200 元。
176+
*/
177+
@SerializedName("type")
178+
private String type;
179+
}
180+
147181
@Data
148182
@Builder(builderMethodName = "newBuilder")
149183
@AllArgsConstructor

‎weixin-java-pay/src/test/java/com/github/binarywang/wxpay/service/impl/TransferUserAuthorizationApiCompatibilityTest.java‎

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@
1111
import com.github.binarywang.wxpay.bean.transfer.UserConfirmAuthorizationResult;
1212
import com.github.binarywang.wxpay.exception.WxPayException;
1313
import com.github.binarywang.wxpay.service.WxPayService;
14+
import com.google.gson.Gson;
15+
import com.google.gson.JsonObject;
1416
import org.testng.Assert;
1517
import org.testng.annotations.Test;
1618

@@ -41,9 +43,34 @@ public void shouldKeepTransferBillsApiPathUnchanged() throws Exception {
4143

4244
Assert.assertEquals(handler.lastPostWithSerialUrl, BASE_URL + "/v3/fund-app/mch-transfer/transfer-bills");
4345
Assert.assertFalse(handler.lastPostWithSerialBody.contains("authorization_info"));
46+
Assert.assertFalse(handler.lastPostWithSerialBody.contains("user_recv_style"));
4447
Assert.assertEquals(result.getPackageInfo(), "transfer-package");
4548
}
4649

50+
/**
51+
* 验证发起转账时用户收款样式及类型按微信接口字段名发送。
52+
*/
53+
public void shouldSendUserRecvStyleInTransferBillsRequest() throws Exception {
54+
RequestCaptureHandler handler = new RequestCaptureHandler();
55+
TransferServiceImpl transferService = new TransferServiceImpl(handler.createWxPayService());
56+
57+
transferService.transferBills(TransferBillsRequest.newBuilder()
58+
.appid("wxf636efh567hg4356")
59+
.outBillNo("plfk2020042014")
60+
.transferSceneId("1000")
61+
.openid("o-MYE42l80oelYMDE34nYD456Xoy")
62+
.transferAmount(100)
63+
.transferRemark("活动奖励")
64+
.userRecvStyle(TransferBillsRequest.UserRecvStyle.newBuilder()
65+
.type("RED_PACKET")
66+
.build())
67+
.build());
68+
69+
JsonObject body = new Gson().fromJson(handler.lastPostWithSerialBody, JsonObject.class);
70+
Assert.assertEquals(handler.lastPostWithSerialUrl, BASE_URL + "/v3/fund-app/mch-transfer/transfer-bills");
71+
Assert.assertEquals(body.getAsJsonObject("user_recv_style").get("type").getAsString(), "RED_PACKET");
72+
}
73+
4774
/**
4875
* 验证“发起转账并完成免确认收款授权”使用独立接口路径和授权参数.
4976
*/

0 commit comments

Comments
 (0)