From e8ff24d4414a9f230cbe31d05aaa44d459941f34 Mon Sep 17 00:00:00 2001 From: lizhiyuan Date: Wed, 30 Sep 2026 15:16:58 +0800 Subject: [PATCH] =?UTF-8?q?feat(pay):=20=E8=A1=A5=E9=BD=90=E5=95=86?= =?UTF-8?q?=E5=AE=B6=E8=BD=AC=E8=B4=A6=E6=94=B6=E6=AC=BE=E6=A0=B7=E5=BC=8F?= =?UTF-8?q?=E5=8F=82=E6=95=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 为 TransferBillsRequest 增加 user_recv_style.type 字段,支持设置收款确认页或红包样式。补充请求体序列化回归测试,验证显式设置和省略参数的行为。 --- .../bean/transfer/TransferBillsRequest.java | 21 +++++++++++++++ ...UserAuthorizationApiCompatibilityTest.java | 27 +++++++++++++++++++ 2 files changed, 48 insertions(+) diff --git a/weixin-java-pay/src/main/java/com/github/binarywang/wxpay/bean/transfer/TransferBillsRequest.java b/weixin-java-pay/src/main/java/com/github/binarywang/wxpay/bean/transfer/TransferBillsRequest.java index 6279482c3..3df4360bf 100644 --- a/weixin-java-pay/src/main/java/com/github/binarywang/wxpay/bean/transfer/TransferBillsRequest.java +++ b/weixin-java-pay/src/main/java/com/github/binarywang/wxpay/bean/transfer/TransferBillsRequest.java @@ -87,6 +87,12 @@ public class TransferBillsRequest implements Serializable { @SerializedName("transfer_scene_report_infos") private List transferSceneReportInfos; + /** + * 用户收款样式;不传时默认展示收款确认页。 + */ + @SerializedName("user_recv_style") + private UserRecvStyle userRecvStyle; + /** * 自动收款授权信息 */ @@ -144,6 +150,21 @@ public static class TransferSceneReportInfo { private String infoContent; } + /** + * 用户收款样式。 + */ + @Data + @Builder(builderMethodName = "newBuilder") + @AllArgsConstructor + @NoArgsConstructor + public static class UserRecvStyle { + /** + * 样式类型:CONFIRM_PAGE 为收款确认页,RED_PACKET 为红包;红包仅支持部分转账场景且单笔金额不超过 200 元。 + */ + @SerializedName("type") + private String type; + } + @Data @Builder(builderMethodName = "newBuilder") @AllArgsConstructor diff --git a/weixin-java-pay/src/test/java/com/github/binarywang/wxpay/service/impl/TransferUserAuthorizationApiCompatibilityTest.java b/weixin-java-pay/src/test/java/com/github/binarywang/wxpay/service/impl/TransferUserAuthorizationApiCompatibilityTest.java index ed4ccc15a..fe4c5de5b 100644 --- a/weixin-java-pay/src/test/java/com/github/binarywang/wxpay/service/impl/TransferUserAuthorizationApiCompatibilityTest.java +++ b/weixin-java-pay/src/test/java/com/github/binarywang/wxpay/service/impl/TransferUserAuthorizationApiCompatibilityTest.java @@ -11,6 +11,8 @@ import com.github.binarywang.wxpay.bean.transfer.UserConfirmAuthorizationResult; import com.github.binarywang.wxpay.exception.WxPayException; import com.github.binarywang.wxpay.service.WxPayService; +import com.google.gson.Gson; +import com.google.gson.JsonObject; import org.testng.Assert; import org.testng.annotations.Test; @@ -41,9 +43,34 @@ public void shouldKeepTransferBillsApiPathUnchanged() throws Exception { Assert.assertEquals(handler.lastPostWithSerialUrl, BASE_URL + "/v3/fund-app/mch-transfer/transfer-bills"); Assert.assertFalse(handler.lastPostWithSerialBody.contains("authorization_info")); + Assert.assertFalse(handler.lastPostWithSerialBody.contains("user_recv_style")); Assert.assertEquals(result.getPackageInfo(), "transfer-package"); } + /** + * 验证发起转账时用户收款样式及类型按微信接口字段名发送。 + */ + public void shouldSendUserRecvStyleInTransferBillsRequest() throws Exception { + RequestCaptureHandler handler = new RequestCaptureHandler(); + TransferServiceImpl transferService = new TransferServiceImpl(handler.createWxPayService()); + + transferService.transferBills(TransferBillsRequest.newBuilder() + .appid("wxf636efh567hg4356") + .outBillNo("plfk2020042014") + .transferSceneId("1000") + .openid("o-MYE42l80oelYMDE34nYD456Xoy") + .transferAmount(100) + .transferRemark("活动奖励") + .userRecvStyle(TransferBillsRequest.UserRecvStyle.newBuilder() + .type("RED_PACKET") + .build()) + .build()); + + JsonObject body = new Gson().fromJson(handler.lastPostWithSerialBody, JsonObject.class); + Assert.assertEquals(handler.lastPostWithSerialUrl, BASE_URL + "/v3/fund-app/mch-transfer/transfer-bills"); + Assert.assertEquals(body.getAsJsonObject("user_recv_style").get("type").getAsString(), "RED_PACKET"); + } + /** * 验证“发起转账并完成免确认收款授权”使用独立接口路径和授权参数. */