Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,11 @@ public static class OrderInfo {
@SerializedName("token")
private String token;

@SerializedName("leftFee")
private Long leftFee; //支付单类型时表示此单经过退款还剩余的金额,单位分
@SerializedName("wxOrderId")
/** 支付单类型时表示此单经过退款还剩余的金额,单位分 */
@SerializedName("left_fee")
private Long leftFee;
/** 微信内部单号 */
@SerializedName("wx_order_id")
private String wxOrderId;

/** 渠道单号,为用户微信支付详情页面上的商户单号 */
Expand All @@ -70,7 +72,14 @@ public static class OrderInfo {
/** 结算时间的秒级时间戳,大于0表示结算成功 */
@SerializedName("sett_time")
private Long settTime;
/** 结算状态:0-未开始结算 1-结算中 2-结算成功 3-待结算(与0相同) */
/**
* 结算状态:
* 0-未开始结算
* 1-结算中
* 2-结算成功
* 3-待结算(与0相同)
* 4-苹果iOS订单,Apple公司结算中
*/
@SerializedName("sett_state")
private Integer settState;
/** 虚拟支付技术服务费,单位为分;sett_state = 2时返回 */
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
package cn.binarywang.wx.miniapp.bean.xpay;

import cn.binarywang.wx.miniapp.json.WxMaGsonBuilder;
import org.testng.annotations.Test;

import static org.testng.Assert.assertEquals;
import static org.testng.Assert.assertNotNull;

/**
* 验证 {@link WxMaXPayQueryOrderResponse} GSON 反序列化正确性的单元测试。
Copy link

Copilot AI Apr 7, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

类注释里写的是“GSON 反序列化”,项目中其余位置通常使用库名“Gson”(与 WxMaGsonBuilder 命名一致)。建议将这里的“GSON”改为“Gson”,避免专有名词大小写不一致。

Suggested change
* 验证 {@link WxMaXPayQueryOrderResponse} GSON 反序列化正确性的单元测试
* 验证 {@link WxMaXPayQueryOrderResponse} Gson 反序列化正确性的单元测试

Copilot uses AI. Check for mistakes.
*
* <p>修复说明:{@link WxMaXPayQueryOrderResponse.OrderInfo} 中 {@code leftFee} 和 {@code wxOrderId}
* 字段的 {@code @SerializedName} 使用了驼峰命名({@code "leftFee"}、{@code "wxOrderId"}),
* 而微信小程序接口实际返回的 JSON key 为下划线分割形式({@code "left_fee"}、{@code "wx_order_id"}),
* 导致这两个字段无法正确反序列化。
*
* @author GitHub Copilot
*/
public class WxMaXPayQueryOrderResponseTest {

private static final String JSON_WITH_SNAKE_CASE_KEYS =
"{"
+ "\"errcode\":0,"
+ "\"errmsg\":\"ok\","
+ "\"order\":{"
+ "\"order_id\":\"order123\","
+ "\"status\":1,"
+ "\"left_fee\":500,"
+ "\"wx_order_id\":\"wx_inner_order_456\","
+ "\"sett_state\":4"
+ "}"
+ "}";

/**
* 验证 left_fee(下划线形式)能正确反序列化到 leftFee 字段。
*/
@Test
public void testLeftFeeDeserializedFromSnakeCaseKey() {
WxMaXPayQueryOrderResponse response = WxMaGsonBuilder.create()
.fromJson(JSON_WITH_SNAKE_CASE_KEYS, WxMaXPayQueryOrderResponse.class);

assertNotNull(response.getOrder(), "order 字段不应为 null");
assertEquals(response.getOrder().getLeftFee(), Long.valueOf(500L),
"left_fee 应正确反序列化为 leftFee 字段");
}

/**
* 验证 wx_order_id(下划线形式)能正确反序列化到 wxOrderId 字段。
*/
@Test
public void testWxOrderIdDeserializedFromSnakeCaseKey() {
WxMaXPayQueryOrderResponse response = WxMaGsonBuilder.create()
.fromJson(JSON_WITH_SNAKE_CASE_KEYS, WxMaXPayQueryOrderResponse.class);

assertNotNull(response.getOrder(), "order 字段不应为 null");
assertEquals(response.getOrder().getWxOrderId(), "wx_inner_order_456",
"wx_order_id 应正确反序列化为 wxOrderId 字段");
}

/**
* 验证 sett_state = 4(苹果iOS订单)能正确反序列化。
*/
@Test
public void testSettStateAppleOrderValue() {
WxMaXPayQueryOrderResponse response = WxMaGsonBuilder.create()
.fromJson(JSON_WITH_SNAKE_CASE_KEYS, WxMaXPayQueryOrderResponse.class);

assertNotNull(response.getOrder(), "order 字段不应为 null");
assertEquals(response.getOrder().getSettState(), Integer.valueOf(4),
"sett_state = 4 表示苹果iOS订单,Apple公司结算中");
}
}