修复V3支付预支付参数packageValue字段与微信官方API不一致问题,添加@SerializedName("package")注解
Agent-Logs-Url: https://github.com/binarywang/WxJava/sessions/4f76043e-c058-4838-8d60-a43a1c878544 Co-authored-by: binarywang <1343140+binarywang@users.noreply.github.com>
This commit is contained in:
committed by
GitHub
parent
bec6109eda
commit
0dfd466ede
@@ -65,6 +65,10 @@ public class TransactionsResult implements Serializable {
|
||||
private String appId;
|
||||
private String timeStamp;
|
||||
private String nonceStr;
|
||||
/**
|
||||
* 由于package为java保留关键字,因此改为packageValue,序列化时会自动转换为package字段名
|
||||
*/
|
||||
@SerializedName("package")
|
||||
private String packageValue;
|
||||
private String signType;
|
||||
private String paySign;
|
||||
@@ -80,6 +84,10 @@ public class TransactionsResult implements Serializable {
|
||||
private String appid;
|
||||
private String partnerid;
|
||||
private String prepayid;
|
||||
/**
|
||||
* 由于package为java保留关键字,因此改为packageValue,序列化时会自动转换为package字段名
|
||||
*/
|
||||
@SerializedName("package")
|
||||
private String packageValue;
|
||||
private String noncestr;
|
||||
private String timestamp;
|
||||
|
||||
@@ -73,6 +73,10 @@ public class CombineTransactionsResult implements Serializable {
|
||||
private String appId;
|
||||
private String timeStamp;
|
||||
private String nonceStr;
|
||||
/**
|
||||
* 由于package为java保留关键字,因此改为packageValue,序列化时会自动转换为package字段名
|
||||
*/
|
||||
@SerializedName("package")
|
||||
private String packageValue;
|
||||
private String signType;
|
||||
private String paySign;
|
||||
@@ -89,6 +93,10 @@ public class CombineTransactionsResult implements Serializable {
|
||||
private String appid;
|
||||
private String partnerid;
|
||||
private String prepayid;
|
||||
/**
|
||||
* 由于package为java保留关键字,因此改为packageValue,序列化时会自动转换为package字段名
|
||||
*/
|
||||
@SerializedName("package")
|
||||
private String packageValue;
|
||||
private String noncestr;
|
||||
private String timestamp;
|
||||
|
||||
@@ -78,6 +78,10 @@ public class WxPayUnifiedOrderV3Result implements Serializable {
|
||||
private String appId;
|
||||
private String timeStamp;
|
||||
private String nonceStr;
|
||||
/**
|
||||
* 由于package为java保留关键字,因此改为packageValue,序列化时会自动转换为package字段名
|
||||
*/
|
||||
@SerializedName("package")
|
||||
private String packageValue;
|
||||
private String signType;
|
||||
private String paySign;
|
||||
@@ -108,6 +112,10 @@ public class WxPayUnifiedOrderV3Result implements Serializable {
|
||||
private String appid;
|
||||
private String partnerId;
|
||||
private String prepayId;
|
||||
/**
|
||||
* 由于package为java保留关键字,因此改为packageValue,序列化时会自动转换为package字段名
|
||||
*/
|
||||
@SerializedName("package")
|
||||
private String packageValue;
|
||||
private String noncestr;
|
||||
private String timestamp;
|
||||
|
||||
@@ -2,6 +2,8 @@ package com.github.binarywang.wxpay.bean.result;
|
||||
|
||||
import com.github.binarywang.wxpay.bean.result.enums.TradeTypeEnum;
|
||||
import com.github.binarywang.wxpay.v3.util.SignUtils;
|
||||
import com.google.gson.Gson;
|
||||
import com.google.gson.JsonObject;
|
||||
import org.testng.Assert;
|
||||
import org.testng.annotations.Test;
|
||||
|
||||
@@ -200,8 +202,55 @@ public class WxPayUnifiedOrderV3ResultTest {
|
||||
}
|
||||
|
||||
/**
|
||||
* 测试getJsapiPayInfo方法的空值验证
|
||||
* 测试JsapiResult序列化为JSON时,packageValue字段名应为package(兼容微信官方API要求)
|
||||
*/
|
||||
@Test
|
||||
public void testJsapiResultJsonSerializationPackageFieldName() throws Exception {
|
||||
String testPrepayId = "wx201410272009395522657a690389285100";
|
||||
String testAppId = "wx8888888888888888";
|
||||
KeyPair keyPair = generateKeyPair();
|
||||
PrivateKey privateKey = keyPair.getPrivate();
|
||||
|
||||
WxPayUnifiedOrderV3Result.JsapiResult jsapiResult =
|
||||
WxPayUnifiedOrderV3Result.getJsapiPayInfo(testPrepayId, testAppId, privateKey);
|
||||
|
||||
// 验证Java字段名仍为packageValue
|
||||
Assert.assertEquals(jsapiResult.getPackageValue(), "prepay_id=" + testPrepayId);
|
||||
|
||||
// 验证JSON序列化后字段名为package(微信官方要求)
|
||||
Gson gson = new Gson();
|
||||
JsonObject jsonObject = gson.toJsonTree(jsapiResult).getAsJsonObject();
|
||||
Assert.assertTrue(jsonObject.has("package"), "JSON中应该包含package字段");
|
||||
Assert.assertFalse(jsonObject.has("packageValue"), "JSON中不应该包含packageValue字段");
|
||||
Assert.assertEquals(jsonObject.get("package").getAsString(), "prepay_id=" + testPrepayId);
|
||||
}
|
||||
|
||||
/**
|
||||
* 测试AppResult序列化为JSON时,packageValue字段名应为package(兼容微信官方API要求)
|
||||
*/
|
||||
@Test
|
||||
public void testAppResultJsonSerializationPackageFieldName() throws Exception {
|
||||
String testPrepayId = "wx201410272009395522657a690389285100";
|
||||
String testAppId = "wx8888888888888888";
|
||||
String testMchId = "1900000109";
|
||||
KeyPair keyPair = generateKeyPair();
|
||||
PrivateKey privateKey = keyPair.getPrivate();
|
||||
|
||||
WxPayUnifiedOrderV3Result.AppResult appResult =
|
||||
WxPayUnifiedOrderV3Result.getAppPayInfo(testPrepayId, testAppId, testMchId, privateKey);
|
||||
|
||||
// 验证Java字段名仍为packageValue
|
||||
Assert.assertEquals(appResult.getPackageValue(), "Sign=WXPay");
|
||||
|
||||
// 验证JSON序列化后字段名为package(微信官方要求)
|
||||
Gson gson = new Gson();
|
||||
JsonObject jsonObject = gson.toJsonTree(appResult).getAsJsonObject();
|
||||
Assert.assertTrue(jsonObject.has("package"), "JSON中应该包含package字段");
|
||||
Assert.assertFalse(jsonObject.has("packageValue"), "JSON中不应该包含packageValue字段");
|
||||
Assert.assertEquals(jsonObject.get("package").getAsString(), "Sign=WXPay");
|
||||
}
|
||||
|
||||
|
||||
@Test(expectedExceptions = IllegalArgumentException.class,
|
||||
expectedExceptionsMessageRegExp = "prepayId, appId 和 privateKey 不能为空")
|
||||
public void testGetJsapiPayInfoWithNullPrepayId() {
|
||||
|
||||
Reference in New Issue
Block a user