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"); + } + /** * 验证“发起转账并完成免确认收款授权”使用独立接口路径和授权参数. */