1
0
mirror of synced 2026-04-12 12:14:56 +08:00

修复:WxMaXPayQueryOrderResponse 中 leftFee 和 wxOrderId 的 @SerializedName 错误

Agent-Logs-Url: https://github.com/binarywang/WxJava/sessions/cc05bdd4-0035-41f3-bc34-25b260888ce1

Co-authored-by: binarywang <1343140+binarywang@users.noreply.github.com>
This commit is contained in:
copilot-swe-agent[bot]
2026-04-07 09:16:24 +00:00
committed by GitHub
parent a8667547df
commit 3b64bfb2bb
2 changed files with 85 additions and 4 deletions

View File

@@ -56,9 +56,11 @@ public class WxMaXPayQueryOrderResponse extends WxMaBaseResponse implements Seri
@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;
/** 渠道单号,为用户微信支付详情页面上的商户单号 */
@@ -70,7 +72,14 @@ public class WxMaXPayQueryOrderResponse extends WxMaBaseResponse implements Seri
/** 结算时间的秒级时间戳大于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时返回 */

View File

@@ -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 反序列化正确性的单元测试。
*
* <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公司结算中");
}
}