1
0
mirror of synced 2026-03-22 12:45:04 +08:00

🎨 #3909 【微信支付】修复企业付款请求对象在序列化/取签名参数时因 brandId 为空导致的 NPE

This commit is contained in:
Copilot
2026-03-07 15:59:31 +08:00
committed by GitHub
parent d06da07be9
commit e2120d6a42
2 changed files with 35 additions and 1 deletions

View File

@@ -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);
}
}

View File

@@ -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<String, String> 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<String, String> params = request.getSignParams();
assertThat(params).containsEntry("brand_id", "1234");
}
}