Skip to content

fix: WxPayPartnerRefundV3Request 缺少 sp_appid 和 sub_appid 字段#3918

Merged
binarywang merged 3 commits intodevelopfrom
copilot/add-sp-appid-parameter
Mar 10, 2026
Merged

fix: WxPayPartnerRefundV3Request 缺少 sp_appid 和 sub_appid 字段#3918
binarywang merged 3 commits intodevelopfrom
copilot/add-sp-appid-parameter

Conversation

Copy link
Contributor

Copilot AI commented Mar 10, 2026

WxPayPartnerRefundV3Request 缺少微信服务商退款 API 要求的 sp_appid(必填)和 sub_appid(选填)字段,导致无法构造合法的退款请求。

变更

  • WxPayPartnerRefundV3Request:新增两个字段
    • spAppidsp_appid(必填):服务商应用 ID
    • subAppidsub_appid(选填):子商户应用 ID
WxPayPartnerRefundV3Request request = new WxPayPartnerRefundV3Request()
  .setSpAppid("wx8888888888888888")   // 新增,必填
  .setSubAppid("wxd678efh567hg6999") // 新增,选填
  .setSubMchid("1230000109")
  .setOutRefundNo("1217752501201407033233368018");
  • BaseWxPayServiceImpl.partnerRefundV3():与 unifiedPartnerOrderV3 等同类服务商接口保持一致,在请求未显式设置时自动从配置补齐字段:

    • sp_appid:未设置时从 config.getAppId() 自动填充(必填)
    • sub_appid:未设置且配置中存在非空值时才自动填充(选填,避免向微信 API 发送空字符串)
  • WxPayPartnerRefundV3RequestTest:新增序列化测试,覆盖有/无 sub_appid 两种场景,验证 JSON key 名称正确映射;所有断言在 getAsString() 前先通过 has() 检查 key 是否存在,提升测试失败时的可读性。

Original prompt

This section details on the original issue you should resolve

<issue_title>服务商退款实体对像,缺少sp_appid参数</issue_title>
<issue_description>版本:4.8.0

java对像:WxPayPartnerRefundV3Request
set参数中没有sp_appid,访参数在微信文档中是必传的

Image</issue_description>

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

Custom agent used: 全部用中文
需要用中文,包括PR标题和分析总结过程


💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.

Co-authored-by: binarywang <1343140+binarywang@users.noreply.github.com>
Copilot AI changed the title [WIP] Add sp_appid parameter to WxPayPartnerRefundV3Request fix: WxPayPartnerRefundV3Request 缺少 sp_appid 和 sub_appid 字段 Mar 10, 2026
@binarywang binarywang marked this pull request as ready for review March 10, 2026 03:21
Copilot AI review requested due to automatic review settings March 10, 2026 03:21
Repository owner deleted a comment from chatgpt-codex-connector bot Mar 10, 2026
@augmentcode
Copy link

augmentcode bot commented Mar 10, 2026

🤖 Augment PR Summary

Summary: 修复服务商退款 V3 请求对象缺失字段问题,使其可按微信 API 规范构造合法请求。

Changes:

  • WxPayPartnerRefundV3Request 新增 sp_appid(必填)与 sub_appid(选填)字段,并通过 @SerializedName 完成 JSON key 映射
  • 新增 WxPayPartnerRefundV3RequestTest,验证包含/不包含 sub_appid 时的序列化输出

Technical Notes: 新增字段直接影响请求体 JSON,缺失或 key 不匹配会触发微信侧参数校验失败。

🤖 Was this summary useful? React with 👍 or 👎

Copy link

@augmentcode augmentcode bot left a comment

Choose a reason for hiding this comment

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

Review completed. 2 suggestions posted.

Fix All in Augment

Comment augment review to trigger a new review at any time.

* 示例值:wx8888888888888888
* </pre>
*/
@SerializedName(value = "sp_appid")
Copy link

Choose a reason for hiding this comment

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

sp_appid 在微信服务商退款接口里是必填项,但目前 WxPayService#partnerRefundV3 只会兜底补 sub_mchid/notify_url,如果调用方遗漏 spAppid 仍会发出不合法请求并被微信侧拒绝;建议确认是否需要在调用链上做同样的兜底或校验。

Severity: medium

Fix This in Augment

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

request.setOutRefundNo("1217752501201407033233368018");
request.setFundsAccount("AVAILABLE");

Gson gson = new Gson();
Copy link

Choose a reason for hiding this comment

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

这里使用 new Gson() 做序列化断言,可能与生产路径里统一使用的 Gson 配置(例如 BaseWxPayServiceImpl 内的 GsonBuilder 实例)在未来发生偏离,导致单测与真实请求不一致;建议确认是否应复用项目内同一套 Gson 构建方式。

Severity: low

Other Locations
  • weixin-java-pay/src/test/java/com/github/binarywang/wxpay/bean/request/WxPayPartnerRefundV3RequestTest.java:43

Fix This in Augment

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

Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

本 PR 针对微信支付 服务商退款(V3)请求对象补齐缺失字段,使 SDK 能构造符合接口要求的请求参数,并通过单元测试验证序列化后的 JSON key 映射正确。

Changes:

  • WxPayPartnerRefundV3Request 中新增 sp_appid(spAppid,必填)与 sub_appid(subAppid,选填)字段及对应序列化注解。
  • 新增 WxPayPartnerRefundV3RequestTest,覆盖包含/不包含 sub_appid 两种序列化场景。

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 4 comments.

File Description
weixin-java-pay/src/main/java/com/github/binarywang/wxpay/bean/request/WxPayPartnerRefundV3Request.java 为服务商退款请求补齐 sp_appid/sub_appid 字段并映射到正确的 JSON key
weixin-java-pay/src/test/java/com/github/binarywang/wxpay/bean/request/WxPayPartnerRefundV3RequestTest.java 新增序列化单测,验证新增字段的 JSON key 映射及 sub_appid 的可选性

@binarywang
Copy link
Owner

@copilot apply changes based on the comments in this thread

Co-authored-by: binarywang <1343140+binarywang@users.noreply.github.com>
Copy link
Contributor Author

Copilot AI commented Mar 10, 2026

@copilot apply changes based on the comments in this thread

已在提交 5aa16cf 中按 Review 意见完成以下修改:

  1. 移除 @author GitHub CopilotWxPayPartnerRefundV3Request.java 和测试类的 Javadoc 均已移除该标注
  2. 修复 NPE 风险:测试断言中所有 getAsString() 调用前均先通过 has() 断言对应 key 存在,失败时可给出明确提示
  3. 自动补齐 sp_appid/sub_appidpartnerRefundV3() 现在与 unifiedPartnerOrderV3 保持一致——未显式设置时从配置自动填充 sp_appidsub_appid 仅在配置中存在非空值时才补齐,避免向微信 API 发送空字符串

@binarywang
Copy link
Owner

@copilot apply changes based on the comments in this thread

Copy link
Contributor Author

Copilot AI commented Mar 10, 2026

@copilot apply changes based on the comments in this thread

Review 线程中的所有变更均已在提交 5aa16cf 中完成:

  1. 移除两个文件 Javadoc 中的 @author GitHub Copilot
  2. 测试断言中 getAsString() 前统一加了 has() 前置检查,防止字段映射失败时抛 NPE
  3. partnerRefundV3() 新增自动从配置补齐 sp_appid(必填)和 sub_appid(仅配置非空时),与 unifiedPartnerOrderV3 保持一致

@binarywang binarywang merged commit 1eeb095 into develop Mar 10, 2026
2 checks passed
@binarywang binarywang deleted the copilot/add-sp-appid-parameter branch March 10, 2026 08:07
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.

服务商退款实体对像,缺少sp_appid参数

3 participants