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 @@ -838,6 +838,34 @@ public enum WxMaErrorMsgEnum {
*/
CODE_89424(89424, "授权次数到达上限"),

/**
* 微信小程序虚拟支付错误码
*
* @see <a href="https://developers.weixin.qq.com/miniprogram/dev/server/API/VirtualPayment/api_query_order.html">虚拟支付 API 文档</a>
*/
CODE_268490001(268490001, "openid错误"),
CODE_268490002(268490002, "请求参数字段错误,具体看errmsg"),
CODE_268490003(268490003, "签名错误"),
CODE_268490004(268490004, "重复操作(赠送和代币支付和充值广告金相关接口会返回,表示之前的操作已经成功)"),
CODE_268490005(268490005, "订单已经通过cancel_currency_pay接口退款,不支持再退款"),
CODE_268490006(268490006, "代币的退款/支付操作金额不足"),
CODE_268490007(268490007, "图片或文字存在敏感内容,禁止使用"),
CODE_268490008(268490008, "代币未发布,不允许进行代币操作"),
CODE_268490009(268490009, "用户session_key不存在或已过期,请重新登录"),
CODE_268490011(268490011, "数据生成中,请稍后调用本接口获取"),
CODE_268490012(268490012, "批量任务运行中,请等待完成后才能再次运行"),
CODE_268490013(268490013, "禁止对核销状态的单进行退款"),
CODE_268490014(268490014, "退款操作进行中,稍后可以使用相同参数重试"),
CODE_268490015(268490015, "频率限制"),
CODE_268490016(268490016, "退款的left_fee字段与实际不符,请通过query_order接口查询确认"),
CODE_268490018(268490018, "广告金充值账户行业id不匹配"),
CODE_268490019(268490019, "广告金充值账户id已绑定其他appid"),
CODE_268490020(268490020, "广告金充值账户主体名称错误"),
CODE_268490021(268490021, "账户未完成进件"),
CODE_268490022(268490022, "广告金充值账户无效"),
CODE_268490023(268490023, "广告金余额不足"),
CODE_268490024(268490024, "广告金充值金额必须大于0"),

;

private final int code;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
package me.chanjar.weixin.common.error;

import org.testng.annotations.Test;

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

/**
* 微信小程序错误码枚举测试
*
* @author GitHub Copilot
Comment on lines +11 to +12
Copy link

Copilot AI Apr 8, 2026

Choose a reason for hiding this comment

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

该测试类的文件头 Javadoc 增加了 @author GitHub Copilot,但同包下已有测试类(如 WxErrorTest.java)通常不写作者信息;同时把工具名作为作者也容易造成归属信息不准确。建议删除该 author 行或改为实际贡献者/按项目惯例处理。

Suggested change
*
* @author GitHub Copilot

Copilot uses AI. Check for mistakes.
*/
@Test
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

weixin-java-common/src/test/java/me/chanjar/weixin/common/error/WxMaErrorMsgEnumTest.java:14 This module’s surefire config runs TestNG via src/test/resources/testng.xml, and this new test class isn’t listed there, so it may never execute in CI. Consider adding it to the suite (or switching the suite to package scanning) so the new assertions actually run.

Severity: medium

Fix This in Augment

🤖 Was this useful? React with 👍 or 👎, or 🚀 if it prevented an incident/outage.

public class WxMaErrorMsgEnumTest {

public void testFindMsgByCodeForExistingCode() {
String msg = WxMaErrorMsgEnum.findMsgByCode(40001);
assertNotNull(msg);
}
Comment on lines +17 to +20
Copy link

Copilot AI Apr 8, 2026

Choose a reason for hiding this comment

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

testFindMsgByCodeForExistingCode() 目前只断言返回值非空,无法验证返回的文案是否与枚举映射正确(例如误映射到其它错误码也会通过)。建议对一个稳定的已知错误码断言精确的期望消息,或直接复用/覆盖到本次新增的虚拟支付错误码用例中。

Copilot uses AI. Check for mistakes.

public void testFindMsgByCodeForNonExistingCode() {
String msg = WxMaErrorMsgEnum.findMsgByCode(999999);
assertNull(msg);
}

/**
* 验证微信小程序虚拟支付错误码
*/
public void testVirtualPaymentErrorCodes() {
assertEquals(WxMaErrorMsgEnum.findMsgByCode(268490001), "openid错误");
assertEquals(WxMaErrorMsgEnum.findMsgByCode(268490002), "请求参数字段错误,具体看errmsg");
assertEquals(WxMaErrorMsgEnum.findMsgByCode(268490003), "签名错误");
assertEquals(WxMaErrorMsgEnum.findMsgByCode(268490004), "重复操作(赠送和代币支付和充值广告金相关接口会返回,表示之前的操作已经成功)");
assertEquals(WxMaErrorMsgEnum.findMsgByCode(268490005), "订单已经通过cancel_currency_pay接口退款,不支持再退款");
assertEquals(WxMaErrorMsgEnum.findMsgByCode(268490006), "代币的退款/支付操作金额不足");
assertEquals(WxMaErrorMsgEnum.findMsgByCode(268490007), "图片或文字存在敏感内容,禁止使用");
assertEquals(WxMaErrorMsgEnum.findMsgByCode(268490008), "代币未发布,不允许进行代币操作");
assertEquals(WxMaErrorMsgEnum.findMsgByCode(268490009), "用户session_key不存在或已过期,请重新登录");
assertEquals(WxMaErrorMsgEnum.findMsgByCode(268490011), "数据生成中,请稍后调用本接口获取");
assertEquals(WxMaErrorMsgEnum.findMsgByCode(268490012), "批量任务运行中,请等待完成后才能再次运行");
assertEquals(WxMaErrorMsgEnum.findMsgByCode(268490013), "禁止对核销状态的单进行退款");
assertEquals(WxMaErrorMsgEnum.findMsgByCode(268490014), "退款操作进行中,稍后可以使用相同参数重试");
assertEquals(WxMaErrorMsgEnum.findMsgByCode(268490015), "频率限制");
assertEquals(WxMaErrorMsgEnum.findMsgByCode(268490016), "退款的left_fee字段与实际不符,请通过query_order接口查询确认");
assertEquals(WxMaErrorMsgEnum.findMsgByCode(268490018), "广告金充值账户行业id不匹配");
assertEquals(WxMaErrorMsgEnum.findMsgByCode(268490019), "广告金充值账户id已绑定其他appid");
assertEquals(WxMaErrorMsgEnum.findMsgByCode(268490020), "广告金充值账户主体名称错误");
assertEquals(WxMaErrorMsgEnum.findMsgByCode(268490021), "账户未完成进件");
assertEquals(WxMaErrorMsgEnum.findMsgByCode(268490022), "广告金充值账户无效");
assertEquals(WxMaErrorMsgEnum.findMsgByCode(268490023), "广告金余额不足");
assertEquals(WxMaErrorMsgEnum.findMsgByCode(268490024), "广告金充值金额必须大于0");
}

/**
* 验证虚拟支付错误码中不存在的编号(如268490010、268490017)返回null
*/
public void testVirtualPaymentMissingCodes() {
assertNull(WxMaErrorMsgEnum.findMsgByCode(268490010));
assertNull(WxMaErrorMsgEnum.findMsgByCode(268490017));
}
}