From ba9473268f3fab5bbd85efe68ddb052f32a299c5 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Fri, 5 Dec 2025 08:15:20 +0000 Subject: [PATCH 1/4] Initial plan From 2ab4caf5e162820b00f71074be0c13a056be5145 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Fri, 5 Dec 2025 08:20:07 +0000 Subject: [PATCH 2/4] =?UTF-8?q?=E5=9C=A8JsapiResult=E4=B8=AD=E6=B7=BB?= =?UTF-8?q?=E5=8A=A0prepayId=E5=AD=97=E6=AE=B5=E5=B9=B6=E6=8F=90=E4=BE=9B?= =?UTF-8?q?=E9=9D=99=E6=80=81=E5=B7=A5=E5=8E=82=E6=96=B9=E6=B3=95=E5=AE=9E?= =?UTF-8?q?=E7=8E=B0=E8=A7=A3=E8=80=A6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: binarywang <1343140+binarywang@users.noreply.github.com> --- .../result/WxPayUnifiedOrderV3Result.java | 89 +++++++++++++++++++ 1 file changed, 89 insertions(+) diff --git a/weixin-java-pay/src/main/java/com/github/binarywang/wxpay/bean/result/WxPayUnifiedOrderV3Result.java b/weixin-java-pay/src/main/java/com/github/binarywang/wxpay/bean/result/WxPayUnifiedOrderV3Result.java index 309fb8e752..dc929a2cdb 100644 --- a/weixin-java-pay/src/main/java/com/github/binarywang/wxpay/bean/result/WxPayUnifiedOrderV3Result.java +++ b/weixin-java-pay/src/main/java/com/github/binarywang/wxpay/bean/result/WxPayUnifiedOrderV3Result.java @@ -81,6 +81,19 @@ public static class JsapiResult implements Serializable { private String packageValue; private String signType; private String paySign; + /** + *
+ * 字段名:预支付交易会话标识 + * 变量名:prepay_id + * 是否必填:否(用户可选存储) + * 类型:string[1,64] + * 描述: + * 预支付交易会话标识。用于后续接口调用中使用,该值有效期为2小时 + * 此字段用于支持用户存储prepay_id,以便复用和重新生成支付签名 + * 示例值:wx201410272009395522657a690389285100 + *+ */ + private String prepayId; private String getSignStr() { return String.format("%s\n%s\n%s\n%s\n", appId, timeStamp, nonceStr, packageValue); @@ -113,6 +126,7 @@ public
+ * 根据已有的prepay_id生成JSAPI支付所需的参数对象(解耦版本) + * 应用场景: + * 1. 用户已经通过createPartnerOrderV3或unifiedPartnerOrderV3获取了prepay_id + * 2. 用户希望存储prepay_id用于后续复用 + * 3. 支付失败后,使用存储的prepay_id重新生成支付签名信息 + * + * 使用示例: + * // 步骤1:创建订单并获取prepay_id + * WxPayUnifiedOrderV3Result result = wxPayService.unifiedPartnerOrderV3(TradeTypeEnum.JSAPI, request); + * String prepayId = result.getPrepayId(); + * // 存储prepayId到数据库... + * + * // 步骤2:需要支付时,使用存储的prepay_id生成支付信息 + * WxPayUnifiedOrderV3Result.JsapiResult payInfo = WxPayUnifiedOrderV3Result.getJsapiPayInfo( + * prepayId, appId, wxPayService.getConfig().getPrivateKey() + * ); + *+ * + * @param prepayId 预支付交易会话标识 + * @param appId 应用ID + * @param privateKey 商户私钥,用于签名 + * @return JSAPI支付所需的参数对象 + */ + public static JsapiResult getJsapiPayInfo(String prepayId, String appId, PrivateKey privateKey) { + String timestamp = String.valueOf(System.currentTimeMillis() / 1000); + String nonceStr = SignUtils.genRandomStr(); + JsapiResult jsapiResult = new JsapiResult(); + jsapiResult.setAppId(appId).setTimeStamp(timestamp) + .setPackageValue("prepay_id=" + prepayId).setNonceStr(nonceStr) + .setPrepayId(prepayId) + //签名类型,默认为RSA,仅支持RSA。 + .setSignType("RSA").setPaySign(SignUtils.sign(jsapiResult.getSignStr(), privateKey)); + return jsapiResult; + } + + /** + *
+ * 根据已有的prepay_id生成APP支付所需的参数对象(解耦版本) + * 应用场景: + * 1. 用户已经通过createPartnerOrderV3或unifiedPartnerOrderV3获取了prepay_id + * 2. 用户希望存储prepay_id用于后续复用 + * 3. 支付失败后,使用存储的prepay_id重新生成支付签名信息 + * + * 使用示例: + * // 步骤1:创建订单并获取prepay_id + * WxPayUnifiedOrderV3Result result = wxPayService.unifiedPartnerOrderV3(TradeTypeEnum.APP, request); + * String prepayId = result.getPrepayId(); + * // 存储prepayId到数据库... + * + * // 步骤2:需要支付时,使用存储的prepay_id生成支付信息 + * WxPayUnifiedOrderV3Result.AppResult payInfo = WxPayUnifiedOrderV3Result.getAppPayInfo( + * prepayId, appId, mchId, wxPayService.getConfig().getPrivateKey() + * ); + *+ * + * @param prepayId 预支付交易会话标识 + * @param appId 应用ID + * @param mchId 商户号 + * @param privateKey 商户私钥,用于签名 + * @return APP支付所需的参数对象 + */ + public static AppResult getAppPayInfo(String prepayId, String appId, String mchId, PrivateKey privateKey) { + String timestamp = String.valueOf(System.currentTimeMillis() / 1000); + String nonceStr = SignUtils.genRandomStr(); + AppResult appResult = new AppResult(); + appResult.setAppid(appId).setPrepayId(prepayId).setPartnerId(mchId) + .setNoncestr(nonceStr).setTimestamp(timestamp) + //暂填写固定值Sign=WXPay + .setPackageValue("Sign=WXPay") + .setSign(SignUtils.sign(appResult.getSignStr(), privateKey)); + return appResult; + } } From 28e0c16e943bcbbd6c093728ae2ca486299243ac Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Fri, 5 Dec 2025 08:25:52 +0000 Subject: [PATCH 3/4] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E6=96=87=E6=A1=A3?= =?UTF-8?q?=E6=B3=A8=E9=87=8A=E9=94=99=E8=AF=AF=E5=B9=B6=E6=B7=BB=E5=8A=A0?= =?UTF-8?q?=E6=B5=8B=E8=AF=95=E7=94=A8=E4=BE=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: binarywang <1343140+binarywang@users.noreply.github.com> --- .../result/WxPayUnifiedOrderV3Result.java | 2 +- .../result/WxPayUnifiedOrderV3ResultTest.java | 201 ++++++++++++++++++ 2 files changed, 202 insertions(+), 1 deletion(-) create mode 100644 weixin-java-pay/src/test/java/com/github/binarywang/wxpay/bean/result/WxPayUnifiedOrderV3ResultTest.java diff --git a/weixin-java-pay/src/main/java/com/github/binarywang/wxpay/bean/result/WxPayUnifiedOrderV3Result.java b/weixin-java-pay/src/main/java/com/github/binarywang/wxpay/bean/result/WxPayUnifiedOrderV3Result.java index dc929a2cdb..47445ff376 100644 --- a/weixin-java-pay/src/main/java/com/github/binarywang/wxpay/bean/result/WxPayUnifiedOrderV3Result.java +++ b/weixin-java-pay/src/main/java/com/github/binarywang/wxpay/bean/result/WxPayUnifiedOrderV3Result.java @@ -58,7 +58,7 @@ public class WxPayUnifiedOrderV3Result implements Serializable { /** *
* 字段名:二维码链接(NATIVE支付 会返回)
- * 变量名:h5_url
+ * 变量名:code_url
* 是否必填:是
* 类型:string[1,512]
* 描述:
diff --git a/weixin-java-pay/src/test/java/com/github/binarywang/wxpay/bean/result/WxPayUnifiedOrderV3ResultTest.java b/weixin-java-pay/src/test/java/com/github/binarywang/wxpay/bean/result/WxPayUnifiedOrderV3ResultTest.java
new file mode 100644
index 0000000000..afcca2924c
--- /dev/null
+++ b/weixin-java-pay/src/test/java/com/github/binarywang/wxpay/bean/result/WxPayUnifiedOrderV3ResultTest.java
@@ -0,0 +1,201 @@
+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 org.testng.Assert;
+import org.testng.annotations.Test;
+
+import java.security.KeyPair;
+import java.security.KeyPairGenerator;
+import java.security.PrivateKey;
+
+/**
+ *
+ * WxPayUnifiedOrderV3Result 测试类
+ * 主要测试prepayId字段和静态工厂方法的解耦功能
+ *
+ *
+ * @author copilot
+ */
+public class WxPayUnifiedOrderV3ResultTest {
+
+ /**
+ * 生成测试用的RSA密钥对
+ */
+ private KeyPair generateKeyPair() throws Exception {
+ KeyPairGenerator keyPairGenerator = KeyPairGenerator.getInstance("RSA");
+ keyPairGenerator.initialize(2048);
+ return keyPairGenerator.generateKeyPair();
+ }
+
+ /**
+ * 测试JsapiResult中的prepayId字段是否正确设置
+ */
+ @Test
+ public void testJsapiResultWithPrepayId() throws Exception {
+ // 准备测试数据
+ String testPrepayId = "wx201410272009395522657a690389285100";
+ String testAppId = "wx8888888888888888";
+ KeyPair keyPair = generateKeyPair();
+ PrivateKey privateKey = keyPair.getPrivate();
+
+ // 创建WxPayUnifiedOrderV3Result对象
+ WxPayUnifiedOrderV3Result result = new WxPayUnifiedOrderV3Result();
+ result.setPrepayId(testPrepayId);
+
+ // 调用getPayInfo生成JsapiResult
+ WxPayUnifiedOrderV3Result.JsapiResult jsapiResult =
+ result.getPayInfo(TradeTypeEnum.JSAPI, testAppId, null, privateKey);
+
+ // 验证prepayId字段是否正确设置
+ Assert.assertNotNull(jsapiResult.getPrepayId(), "prepayId不应为null");
+ Assert.assertEquals(jsapiResult.getPrepayId(), testPrepayId, "prepayId应该与设置的值相同");
+
+ // 验证其他字段
+ Assert.assertEquals(jsapiResult.getAppId(), testAppId);
+ Assert.assertNotNull(jsapiResult.getTimeStamp());
+ Assert.assertNotNull(jsapiResult.getNonceStr());
+ Assert.assertEquals(jsapiResult.getPackageValue(), "prepay_id=" + testPrepayId);
+ Assert.assertEquals(jsapiResult.getSignType(), "RSA");
+ Assert.assertNotNull(jsapiResult.getPaySign());
+ }
+
+ /**
+ * 测试使用静态工厂方法生成JsapiResult(解耦场景)
+ */
+ @Test
+ public void testGetJsapiPayInfoStaticMethod() throws Exception {
+ // 准备测试数据
+ String testPrepayId = "wx201410272009395522657a690389285100";
+ String testAppId = "wx8888888888888888";
+ KeyPair keyPair = generateKeyPair();
+ PrivateKey privateKey = keyPair.getPrivate();
+
+ // 使用静态工厂方法生成JsapiResult
+ WxPayUnifiedOrderV3Result.JsapiResult jsapiResult =
+ WxPayUnifiedOrderV3Result.getJsapiPayInfo(testPrepayId, testAppId, privateKey);
+
+ // 验证prepayId字段
+ Assert.assertNotNull(jsapiResult.getPrepayId(), "prepayId不应为null");
+ Assert.assertEquals(jsapiResult.getPrepayId(), testPrepayId, "prepayId应该与输入的值相同");
+
+ // 验证其他字段
+ Assert.assertEquals(jsapiResult.getAppId(), testAppId);
+ Assert.assertNotNull(jsapiResult.getTimeStamp());
+ Assert.assertNotNull(jsapiResult.getNonceStr());
+ Assert.assertEquals(jsapiResult.getPackageValue(), "prepay_id=" + testPrepayId);
+ Assert.assertEquals(jsapiResult.getSignType(), "RSA");
+ Assert.assertNotNull(jsapiResult.getPaySign());
+ }
+
+ /**
+ * 测试使用静态工厂方法生成AppResult(解耦场景)
+ */
+ @Test
+ public void testGetAppPayInfoStaticMethod() throws Exception {
+ // 准备测试数据
+ String testPrepayId = "wx201410272009395522657a690389285100";
+ String testAppId = "wx8888888888888888";
+ String testMchId = "1900000109";
+ KeyPair keyPair = generateKeyPair();
+ PrivateKey privateKey = keyPair.getPrivate();
+
+ // 使用静态工厂方法生成AppResult
+ WxPayUnifiedOrderV3Result.AppResult appResult =
+ WxPayUnifiedOrderV3Result.getAppPayInfo(testPrepayId, testAppId, testMchId, privateKey);
+
+ // 验证prepayId字段
+ Assert.assertNotNull(appResult.getPrepayId(), "prepayId不应为null");
+ Assert.assertEquals(appResult.getPrepayId(), testPrepayId, "prepayId应该与输入的值相同");
+
+ // 验证其他字段
+ Assert.assertEquals(appResult.getAppid(), testAppId);
+ Assert.assertEquals(appResult.getPartnerId(), testMchId);
+ Assert.assertNotNull(appResult.getTimestamp());
+ Assert.assertNotNull(appResult.getNoncestr());
+ Assert.assertEquals(appResult.getPackageValue(), "Sign=WXPay");
+ Assert.assertNotNull(appResult.getSign());
+ }
+
+ /**
+ * 测试解耦场景:先获取prepayId,后续再生成支付信息
+ */
+ @Test
+ public void testDecoupledScenario() throws Exception {
+ // 模拟场景:先创建订单获取prepayId
+ String testPrepayId = "wx201410272009395522657a690389285100";
+ String testAppId = "wx8888888888888888";
+ KeyPair keyPair = generateKeyPair();
+ PrivateKey privateKey = keyPair.getPrivate();
+
+ // 步骤1:模拟从创建订单接口获取prepayId
+ WxPayUnifiedOrderV3Result orderResult = new WxPayUnifiedOrderV3Result();
+ orderResult.setPrepayId(testPrepayId);
+
+ // 获取prepayId用于存储
+ String storedPrepayId = orderResult.getPrepayId();
+ Assert.assertEquals(storedPrepayId, testPrepayId);
+
+ // 步骤2:后续支付失败时,使用存储的prepayId重新生成支付信息
+ WxPayUnifiedOrderV3Result.JsapiResult newPayInfo =
+ WxPayUnifiedOrderV3Result.getJsapiPayInfo(storedPrepayId, testAppId, privateKey);
+
+ // 验证重新生成的支付信息
+ Assert.assertEquals(newPayInfo.getPrepayId(), storedPrepayId);
+ Assert.assertEquals(newPayInfo.getPackageValue(), "prepay_id=" + storedPrepayId);
+ Assert.assertNotNull(newPayInfo.getPaySign());
+ }
+
+ /**
+ * 测试多次生成支付信息,签名应该不同(因为timestamp和nonceStr每次都不同)
+ */
+ @Test
+ public void testMultipleGenerationsHaveDifferentSignatures() throws Exception {
+ String testPrepayId = "wx201410272009395522657a690389285100";
+ String testAppId = "wx8888888888888888";
+ KeyPair keyPair = generateKeyPair();
+ PrivateKey privateKey = keyPair.getPrivate();
+
+ // 生成第一次支付信息
+ WxPayUnifiedOrderV3Result.JsapiResult result1 =
+ WxPayUnifiedOrderV3Result.getJsapiPayInfo(testPrepayId, testAppId, privateKey);
+
+ // 等待一秒确保timestamp不同
+ Thread.sleep(1000);
+
+ // 生成第二次支付信息
+ WxPayUnifiedOrderV3Result.JsapiResult result2 =
+ WxPayUnifiedOrderV3Result.getJsapiPayInfo(testPrepayId, testAppId, privateKey);
+
+ // prepayId应该相同
+ Assert.assertEquals(result1.getPrepayId(), result2.getPrepayId());
+
+ // 但是timestamp、nonceStr和签名应该不同
+ Assert.assertNotEquals(result1.getTimeStamp(), result2.getTimeStamp(), "timestamp应该不同");
+ Assert.assertNotEquals(result1.getNonceStr(), result2.getNonceStr(), "nonceStr应该不同");
+ Assert.assertNotEquals(result1.getPaySign(), result2.getPaySign(), "签名应该不同");
+ }
+
+ /**
+ * 测试AppResult中的prepayId字段
+ */
+ @Test
+ public void testAppResultWithPrepayId() throws Exception {
+ String testPrepayId = "wx201410272009395522657a690389285100";
+ String testAppId = "wx8888888888888888";
+ String testMchId = "1900000109";
+ KeyPair keyPair = generateKeyPair();
+ PrivateKey privateKey = keyPair.getPrivate();
+
+ WxPayUnifiedOrderV3Result result = new WxPayUnifiedOrderV3Result();
+ result.setPrepayId(testPrepayId);
+
+ // 调用getPayInfo生成AppResult
+ WxPayUnifiedOrderV3Result.AppResult appResult =
+ result.getPayInfo(TradeTypeEnum.APP, testAppId, testMchId, privateKey);
+
+ // 验证prepayId字段
+ Assert.assertNotNull(appResult.getPrepayId(), "prepayId不应为null");
+ Assert.assertEquals(appResult.getPrepayId(), testPrepayId, "prepayId应该与设置的值相同");
+ }
+}
From 070a159776681cab4e67c01982d0d9c4aa785637 Mon Sep 17 00:00:00 2001
From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com>
Date: Sun, 21 Dec 2025 09:30:57 +0000
Subject: [PATCH 4/4] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E5=8F=82=E6=95=B0?=
=?UTF-8?q?=E6=A0=A1=E9=AA=8C=E5=92=8C=E6=8F=90=E5=8F=96=E9=87=8D=E5=A4=8D?=
=?UTF-8?q?=E4=BB=A3=E7=A0=81=E4=B8=BA=E7=A7=81=E6=9C=89=E6=96=B9=E6=B3=95?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
Co-authored-by: binarywang <1343140+binarywang@users.noreply.github.com>
---
.../result/WxPayUnifiedOrderV3Result.java | 67 ++++++++++++-------
.../result/WxPayUnifiedOrderV3ResultTest.java | 66 ++++++++++++++++++
2 files changed, 108 insertions(+), 25 deletions(-)
diff --git a/weixin-java-pay/src/main/java/com/github/binarywang/wxpay/bean/result/WxPayUnifiedOrderV3Result.java b/weixin-java-pay/src/main/java/com/github/binarywang/wxpay/bean/result/WxPayUnifiedOrderV3Result.java
index 47445ff376..5b60f3b520 100644
--- a/weixin-java-pay/src/main/java/com/github/binarywang/wxpay/bean/result/WxPayUnifiedOrderV3Result.java
+++ b/weixin-java-pay/src/main/java/com/github/binarywang/wxpay/bean/result/WxPayUnifiedOrderV3Result.java
@@ -119,27 +119,13 @@ private String getSignStr() {
}
public T getPayInfo(TradeTypeEnum tradeType, String appId, String mchId, PrivateKey privateKey) {
- String timestamp = String.valueOf(System.currentTimeMillis() / 1000);
- String nonceStr = SignUtils.genRandomStr();
switch (tradeType) {
case JSAPI:
- JsapiResult jsapiResult = new JsapiResult();
- jsapiResult.setAppId(appId).setTimeStamp(timestamp)
- .setPackageValue("prepay_id=" + this.prepayId).setNonceStr(nonceStr)
- .setPrepayId(this.prepayId)
- //签名类型,默认为RSA,仅支持RSA。
- .setSignType("RSA").setPaySign(SignUtils.sign(jsapiResult.getSignStr(), privateKey));
- return (T) jsapiResult;
+ return (T) buildJsapiResult(this.prepayId, appId, privateKey);
case H5:
return (T) this.h5Url;
case APP:
- AppResult appResult = new AppResult();
- appResult.setAppid(appId).setPrepayId(this.prepayId).setPartnerId(mchId)
- .setNoncestr(nonceStr).setTimestamp(timestamp)
- //暂填写固定值Sign=WXPay
- .setPackageValue("Sign=WXPay")
- .setSign(SignUtils.sign(appResult.getSignStr(), privateKey));
- return (T) appResult;
+ return (T) buildAppResult(this.prepayId, appId, mchId, privateKey);
case NATIVE:
return (T) this.codeUrl;
default:
@@ -173,15 +159,10 @@ public T getPayInfo(TradeTypeEnum tradeType, String appId, String mchId, Pri
* @return JSAPI支付所需的参数对象
*/
public static JsapiResult getJsapiPayInfo(String prepayId, String appId, PrivateKey privateKey) {
- String timestamp = String.valueOf(System.currentTimeMillis() / 1000);
- String nonceStr = SignUtils.genRandomStr();
- JsapiResult jsapiResult = new JsapiResult();
- jsapiResult.setAppId(appId).setTimeStamp(timestamp)
- .setPackageValue("prepay_id=" + prepayId).setNonceStr(nonceStr)
- .setPrepayId(prepayId)
- //签名类型,默认为RSA,仅支持RSA。
- .setSignType("RSA").setPaySign(SignUtils.sign(jsapiResult.getSignStr(), privateKey));
- return jsapiResult;
+ if (prepayId == null || appId == null || privateKey == null) {
+ throw new IllegalArgumentException("prepayId, appId 和 privateKey 不能为空");
+ }
+ return buildJsapiResult(prepayId, appId, privateKey);
}
/**
@@ -211,6 +192,42 @@ public static JsapiResult getJsapiPayInfo(String prepayId, String appId, Private
* @return APP支付所需的参数对象
*/
public static AppResult getAppPayInfo(String prepayId, String appId, String mchId, PrivateKey privateKey) {
+ if (prepayId == null || appId == null || mchId == null || privateKey == null) {
+ throw new IllegalArgumentException("prepayId, appId, mchId 和 privateKey 不能为空");
+ }
+ return buildAppResult(prepayId, appId, mchId, privateKey);
+ }
+
+ /**
+ * 构建JSAPI支付结果对象
+ *
+ * @param prepayId 预支付交易会话标识
+ * @param appId 应用ID
+ * @param privateKey 商户私钥,用于签名
+ * @return JSAPI支付所需的参数对象
+ */
+ private static JsapiResult buildJsapiResult(String prepayId, String appId, PrivateKey privateKey) {
+ String timestamp = String.valueOf(System.currentTimeMillis() / 1000);
+ String nonceStr = SignUtils.genRandomStr();
+ JsapiResult jsapiResult = new JsapiResult();
+ jsapiResult.setAppId(appId).setTimeStamp(timestamp)
+ .setPackageValue("prepay_id=" + prepayId).setNonceStr(nonceStr)
+ .setPrepayId(prepayId)
+ //签名类型,默认为RSA,仅支持RSA。
+ .setSignType("RSA").setPaySign(SignUtils.sign(jsapiResult.getSignStr(), privateKey));
+ return jsapiResult;
+ }
+
+ /**
+ * 构建APP支付结果对象
+ *
+ * @param prepayId 预支付交易会话标识
+ * @param appId 应用ID
+ * @param mchId 商户号
+ * @param privateKey 商户私钥,用于签名
+ * @return APP支付所需的参数对象
+ */
+ private static AppResult buildAppResult(String prepayId, String appId, String mchId, PrivateKey privateKey) {
String timestamp = String.valueOf(System.currentTimeMillis() / 1000);
String nonceStr = SignUtils.genRandomStr();
AppResult appResult = new AppResult();
diff --git a/weixin-java-pay/src/test/java/com/github/binarywang/wxpay/bean/result/WxPayUnifiedOrderV3ResultTest.java b/weixin-java-pay/src/test/java/com/github/binarywang/wxpay/bean/result/WxPayUnifiedOrderV3ResultTest.java
index afcca2924c..2e824b0e00 100644
--- a/weixin-java-pay/src/test/java/com/github/binarywang/wxpay/bean/result/WxPayUnifiedOrderV3ResultTest.java
+++ b/weixin-java-pay/src/test/java/com/github/binarywang/wxpay/bean/result/WxPayUnifiedOrderV3ResultTest.java
@@ -198,4 +198,70 @@ public void testAppResultWithPrepayId() throws Exception {
Assert.assertNotNull(appResult.getPrepayId(), "prepayId不应为null");
Assert.assertEquals(appResult.getPrepayId(), testPrepayId, "prepayId应该与设置的值相同");
}
+
+ /**
+ * 测试getJsapiPayInfo方法的空值验证
+ */
+ @Test(expectedExceptions = IllegalArgumentException.class,
+ expectedExceptionsMessageRegExp = "prepayId, appId 和 privateKey 不能为空")
+ public void testGetJsapiPayInfoWithNullPrepayId() {
+ WxPayUnifiedOrderV3Result.getJsapiPayInfo(null, "appId", null);
+ }
+
+ /**
+ * 测试getJsapiPayInfo方法的空值验证 - appId为null
+ */
+ @Test(expectedExceptions = IllegalArgumentException.class,
+ expectedExceptionsMessageRegExp = "prepayId, appId 和 privateKey 不能为空")
+ public void testGetJsapiPayInfoWithNullAppId() throws Exception {
+ KeyPair keyPair = generateKeyPair();
+ WxPayUnifiedOrderV3Result.getJsapiPayInfo("prepayId", null, keyPair.getPrivate());
+ }
+
+ /**
+ * 测试getJsapiPayInfo方法的空值验证 - privateKey为null
+ */
+ @Test(expectedExceptions = IllegalArgumentException.class,
+ expectedExceptionsMessageRegExp = "prepayId, appId 和 privateKey 不能为空")
+ public void testGetJsapiPayInfoWithNullPrivateKey() {
+ WxPayUnifiedOrderV3Result.getJsapiPayInfo("prepayId", "appId", null);
+ }
+
+ /**
+ * 测试getAppPayInfo方法的空值验证 - prepayId为null
+ */
+ @Test(expectedExceptions = IllegalArgumentException.class,
+ expectedExceptionsMessageRegExp = "prepayId, appId, mchId 和 privateKey 不能为空")
+ public void testGetAppPayInfoWithNullPrepayId() {
+ WxPayUnifiedOrderV3Result.getAppPayInfo(null, "appId", "mchId", null);
+ }
+
+ /**
+ * 测试getAppPayInfo方法的空值验证 - appId为null
+ */
+ @Test(expectedExceptions = IllegalArgumentException.class,
+ expectedExceptionsMessageRegExp = "prepayId, appId, mchId 和 privateKey 不能为空")
+ public void testGetAppPayInfoWithNullAppId() throws Exception {
+ KeyPair keyPair = generateKeyPair();
+ WxPayUnifiedOrderV3Result.getAppPayInfo("prepayId", null, "mchId", keyPair.getPrivate());
+ }
+
+ /**
+ * 测试getAppPayInfo方法的空值验证 - mchId为null
+ */
+ @Test(expectedExceptions = IllegalArgumentException.class,
+ expectedExceptionsMessageRegExp = "prepayId, appId, mchId 和 privateKey 不能为空")
+ public void testGetAppPayInfoWithNullMchId() throws Exception {
+ KeyPair keyPair = generateKeyPair();
+ WxPayUnifiedOrderV3Result.getAppPayInfo("prepayId", "appId", null, keyPair.getPrivate());
+ }
+
+ /**
+ * 测试getAppPayInfo方法的空值验证 - privateKey为null
+ */
+ @Test(expectedExceptions = IllegalArgumentException.class,
+ expectedExceptionsMessageRegExp = "prepayId, appId, mchId 和 privateKey 不能为空")
+ public void testGetAppPayInfoWithNullPrivateKey() {
+ WxPayUnifiedOrderV3Result.getAppPayInfo("prepayId", "appId", "mchId", null);
+ }
}