Skip to content

Conversation

Copy link
Contributor

Copilot AI commented Nov 28, 2025

问题分析

用户报告调用 createOrderV3 时日志显示额外请求了 complaint-notifications 接口并返回"数据查询结果为空"错误。经分析,这不是 SDK 的 bug

根因

如维护者评论所指:用户代码可能序列化了 WxPayService 对象。

  • createOrderV3 方法链中不存在任何对 complaint-notifications 的调用
  • ComplaintServiceImpl 仅在显式调用时发起请求
  • BaseWxPayServiceImpl 服务初始化只创建对象,不触发 API 调用

用户代码中使用了 AopContext.currentProxy()JSON.toJSONString(),某些序列化库会触发所有 getter 方法,导致意外调用 getComplaintsService() 及相关方法。

建议用户

// ❌ 避免
JSON.toJSONString(wxPayService);
log.info("{}", wxPayService);

// ✅ 正确用法
WxPayUnifiedOrderV3Result.JsapiResult result = wxPayService.createOrderV3(TradeTypeEnum.JSAPI, request);
log.info("jsapiResult: {}", JSON.toJSONString(result)); // 序列化结果对象,不是 service

结论

无需代码修改。建议关闭 issue 并告知用户检查代码实现。

Original prompt

This section details on the original issue you should resolve

<issue_title>调用微信支付createOrderV3接口,出现:数据查询结果为空 报错</issue_title>
<issue_description>调用微信支付v3下单接口,支付单生成了,但是出现调用https://api.mch.weixin.qq.com/v3/merchant-service/complaint-notifications接口记录,并提示:数据查询结果为空

WxJava 模块名: weixin-java-pay
WxJava 版本号:4.5.3.B
代码:
private R createWxOrder(UnionBaseRequest request, PayConfig payConfig) throws WxPayException {
WxPayService wxPayService = new WxPayServiceImpl();
WxPayConfig wxPayConfig = new WxPayConfig();
wxPayConfig.setAppId(request.getSubAppId());
wxPayConfig.setMchId(payConfig.getMchId());
wxPayConfig.setApiV3Key(payConfig.getApiV3Key());
if (StringUtils.isNotBlank(payConfig.getPrivateCertContent())) {
wxPayConfig.setPrivateCertContent(payConfig.getPrivateCertContent().getBytes());
}
if (StringUtils.isNotBlank(payConfig.getPrivateKeyContent())) {
wxPayConfig.setPrivateKeyContent(payConfig.getPrivateKeyContent().getBytes());
}
wxPayConfig.setPrivateKeyPath(payConfig.getPrivateKeyPath());
wxPayConfig.setPrivateCertPath(payConfig.getPrivateCertPath());
wxPayService.setConfig(wxPayConfig);

  WxPayUnifiedOrderV3Request v3Request = new WxPayUnifiedOrderV3Request();

  String orderDesc = request.getOrderDesc();

  v3Request.setDescription(orderDesc);
  String merOrderId = request.getMerOrderId();
  if (StringUtils.isNotEmpty(merOrderId) && merOrderId.startsWith(UnionPayConstants.ORDER_ID_PREFIX)) {
  	merOrderId = merOrderId.replace(UnionPayConstants.ORDER_ID_PREFIX, "");
  }
  v3Request.setOutTradeNo(merOrderId);
  v3Request.setNotifyUrl(wxPayConfigProperties.getNotifyUrl() + "/" + payConfig.getTenantId());

  WxPayUnifiedOrderV3Request.Amount amount = new WxPayUnifiedOrderV3Request.Amount();
  amount.setTotal(request.getTotalAmount().intValue());
  amount.setCurrency("CNY");
  v3Request.setAmount(amount);

  WxPayUnifiedOrderV3Request.Payer payer = new WxPayUnifiedOrderV3Request.Payer();
  payer.setOpenid(request.getOpenId());
  v3Request.setPayer(payer);

  v3Request.setAttach(request.getSubAppId());
  v3Request.setTimeExpire(DateUtil.format(DateUtil.parse(request.getExpireTime(), "yyyy-MM-dd HH:mm:ss"), "yyyy-MM-dd'T'HH:mm:ssXXX"));

  WxPayUnifiedOrderV3Result.JsapiResult jsapiResult = ((UnionPayController) AopContext.currentProxy()).createOrderV3(v3Request, wxPayService);
  log.info("微信支付jsapiResult:{}", JSON.toJSONString(jsapiResult));
  JSONObject miniPayRequest = new JSONObject();
  JSONObject payParam = new JSONObject();
  payParam.put("appId", jsapiResult.getAppId());
  payParam.put("timeStamp", jsapiResult.getTimeStamp());
  payParam.put("package", jsapiResult.getPackageValue());
  payParam.put("paySign", jsapiResult.getPaySign());
  payParam.put("signType", jsapiResult.getSignType());
  payParam.put("nonceStr", jsapiResult.getNonceStr());
  miniPayRequest.put("miniPayRequest", payParam);

  String miniPayUrl = payConfig.getMiniPayUrl();
  if (StringUtils.isNotEmpty(miniPayUrl)) {
  	try {
  		miniPayUrl = miniPayUrl + "?payDataStr=" + URLEncoder.encode(payParam.toJSONString(), StandardCharsets.UTF_8.toString());
  	} catch (UnsupportedEncodingException e) {
  		log.error("", e);
  	}
  	miniPayRequest.put("miniPayUrl", miniPayUrl);
  }

  return R.ok(miniPayRequest);

}

@auditlog(obsType = "现金(微信)", stage = "付款(拉起)")
public WxPayUnifiedOrderV3Result.JsapiResult createOrderV3(WxPayUnifiedOrderV3Request v3Request, WxPayService wxPayService) throws WxPayException {
return wxPayService.createOrderV3(TradeTypeEnum.JSAPI, v3Request);
}

日志:
日志

</issue_description>

Comments on the Issue (you are @copilot in this section)

@binarywang 为什么要序列化service对象?

Custom agent used: 自定义的
需要用中文


💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

Copilot AI changed the title [WIP] Fix createOrderV3 API error: data query result is empty 分析:createOrderV3 调用时触发 complaint-notifications 请求不是 SDK 问题 Nov 28, 2025
Copilot AI requested a review from binarywang November 28, 2025 14:03
Copilot finished work on behalf of binarywang November 28, 2025 14:03
@binarywang binarywang closed this Nov 28, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

调用微信支付createOrderV3接口,出现:数据查询结果为空 报错

2 participants