From e2120d6a42c172dc4d503efc5d0d086e833f5c81 Mon Sep 17 00:00:00 2001 From: Copilot <198982749+Copilot@users.noreply.github.com> Date: Sat, 7 Mar 2026 15:59:31 +0800 Subject: [PATCH] =?UTF-8?q?:art:=20#3909=20=E3=80=90=E5=BE=AE=E4=BF=A1?= =?UTF-8?q?=E6=94=AF=E4=BB=98=E3=80=91=E4=BF=AE=E5=A4=8D=E4=BC=81=E4=B8=9A?= =?UTF-8?q?=E4=BB=98=E6=AC=BE=E8=AF=B7=E6=B1=82=E5=AF=B9=E8=B1=A1=E5=9C=A8?= =?UTF-8?q?=E5=BA=8F=E5=88=97=E5=8C=96/=E5=8F=96=E7=AD=BE=E5=90=8D?= =?UTF-8?q?=E5=8F=82=E6=95=B0=E6=97=B6=E5=9B=A0=20brandId=20=E4=B8=BA?= =?UTF-8?q?=E7=A9=BA=E5=AF=BC=E8=87=B4=E7=9A=84=20NPE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../wxpay/bean/entpay/EntPayRequest.java | 4 ++- .../wxpay/bean/entpay/EntPayRequestTest.java | 32 +++++++++++++++++++ 2 files changed, 35 insertions(+), 1 deletion(-) diff --git a/weixin-java-pay/src/main/java/com/github/binarywang/wxpay/bean/entpay/EntPayRequest.java b/weixin-java-pay/src/main/java/com/github/binarywang/wxpay/bean/entpay/EntPayRequest.java index fb7c37b21..65ed82ad8 100644 --- a/weixin-java-pay/src/main/java/com/github/binarywang/wxpay/bean/entpay/EntPayRequest.java +++ b/weixin-java-pay/src/main/java/com/github/binarywang/wxpay/bean/entpay/EntPayRequest.java @@ -249,7 +249,9 @@ public class EntPayRequest extends BaseWxPayRequest { map.put("desc", description); map.put("spbill_create_ip", spbillCreateIp); map.put("scene", scene); - map.put("brand_id", brandId.toString()); + if (brandId != null) { + map.put("brand_id", brandId.toString()); + } map.put("finder_template_id", finderTemplateId); } } diff --git a/weixin-java-pay/src/test/java/com/github/binarywang/wxpay/bean/entpay/EntPayRequestTest.java b/weixin-java-pay/src/test/java/com/github/binarywang/wxpay/bean/entpay/EntPayRequestTest.java index b6f68b81c..402c74d38 100644 --- a/weixin-java-pay/src/test/java/com/github/binarywang/wxpay/bean/entpay/EntPayRequestTest.java +++ b/weixin-java-pay/src/test/java/com/github/binarywang/wxpay/bean/entpay/EntPayRequestTest.java @@ -2,6 +2,10 @@ package com.github.binarywang.wxpay.bean.entpay; import org.testng.annotations.Test; +import java.util.Map; + +import static org.assertj.core.api.Assertions.assertThat; + /** * . * @@ -14,4 +18,32 @@ public class EntPayRequestTest { public void testToString() { System.out.println(EntPayRequest.newBuilder().mchId("123").build().toString()); } + + /** + * 测试 brandId 为 null 时,getSignParams() 不抛出 NullPointerException. + */ + @Test + public void testGetSignParamsWithNullBrandId() { + EntPayRequest request = EntPayRequest.newBuilder() + .mchId("123") + .amount(100) + .brandId(null) + .build(); + Map params = request.getSignParams(); + assertThat(params).doesNotContainKey("brand_id"); + } + + /** + * 测试 brandId 不为 null 时,getSignParams() 正确包含 brand_id. + */ + @Test + public void testGetSignParamsWithNonNullBrandId() { + EntPayRequest request = EntPayRequest.newBuilder() + .mchId("123") + .amount(100) + .brandId(1234) + .build(); + Map params = request.getSignParams(); + assertThat(params).containsEntry("brand_id", "1234"); + } }