🎨 #3909 【微信支付】修复企业付款请求对象在序列化/取签名参数时因 brandId 为空导致的 NPE
This commit is contained in:
@@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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");
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user