Skip to content

Commit e8ff24d

Browse files
author
lizhiyuan
committed
feat(pay): 补齐商家转账收款样式参数
为 TransferBillsRequest 增加 user_recv_style.type 字段,支持设置收款确认页或红包样式。补充请求体序列化回归测试,验证显式设置和省略参数的行为。
1 parent 58af116 commit e8ff24d

2 files changed

Lines changed: 48 additions & 0 deletions

File tree

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

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,12 @@ 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+
9096
/**
9197
* 自动收款授权信息
9298
*/
@@ -144,6 +150,21 @@ public static class TransferSceneReportInfo {
144150
private String infoContent;
145151
}
146152

153+
/**
154+
* 用户收款样式。
155+
*/
156+
@Data
157+
@Builder(builderMethodName = "newBuilder")
158+
@AllArgsConstructor
159+
@NoArgsConstructor
160+
public static class UserRecvStyle {
161+
/**
162+
* 样式类型:CONFIRM_PAGE 为收款确认页,RED_PACKET 为红包;红包仅支持部分转账场景且单笔金额不超过 200 元。
163+
*/
164+
@SerializedName("type")
165+
private String type;
166+
}
167+
147168
@Data
148169
@Builder(builderMethodName = "newBuilder")
149170
@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)