fix: 兼容旧版退款提现通知解析 - #4095
Conversation
🤖 Augment PR Summary摘要: 为 🤖 Was this summary useful? React with 👍 or 👎 |
| */ | ||
| @Deprecated | ||
| default RefundNotifyResult parseRefundNotifyResult(String notifyData, | ||
| com.github.binarywang.wxpay.bean.ecommerce.SignatureHeader header) throws WxPayException { |
There was a problem hiding this comment.
此重载会让原本可用的 parseRefundNotifyResult(notifyData, null) 变成二义性调用:两个 SignatureHeader 类型没有继承关系,而上方 Javadoc 又将 null 定义为跳过验签的支持用法,因此现有调用方升级后无法重新编译。其他位置也会发生相同问题:weixin-java-pay/src/main/java/com/github/binarywang/wxpay/service/EcommerceService.java:562。
Severity: medium
Other Locations
weixin-java-pay/src/main/java/com/github/binarywang/wxpay/service/EcommerceService.java:562
🤖 Was this useful? React with 👍 or 👎, or 🚀 if it prevented an incident/outage.
There was a problem hiding this comment.
已在后续 PR #4096 修复:旧 SignatureHeader 现继承新类型,使旧重载成为更具体的候选,parseRefundNotifyResult(notifyData, null) 与提现同类调用不再二义。
| Assert.assertNotNull(EcommerceService.class.getMethod("parseRefundNotifyResult", String.class, legacyHeader)); | ||
| Assert.assertNotNull(EcommerceService.class.getMethod("parseWithdrawNotifyResult", String.class, legacyHeader)); |
There was a problem hiding this comment.
已在后续 PR #4096 补充回归测试,验证旧头与新头的继承关系,以及 signed/serialNo 到 signature/serial 的字段映射。
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: e1d447f370
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| default RefundNotifyResult parseRefundNotifyResult(String notifyData, | ||
| com.github.binarywang.wxpay.bean.ecommerce.SignatureHeader header) throws WxPayException { |
There was a problem hiding this comment.
新增参数类型互不相关的重载后,下游原本合法的 service.parseRefundNotifyResult(notifyData, null) 会因无法在两个 SignatureHeader 重载之间选择而编译失败;相邻 Javadoc 明确说明 null 表示不校验请求头。parseWithdrawNotifyResult 的新增重载也有相同问题,因此需要让两个参数类型具备明确的继承关系,或采用不会使现有 null 调用歧义的兼容方案;当前反射测试只能确认签名存在,无法发现此源码兼容性回归。
AGENTS.md reference: AGENTS.md:L47-L48
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
已在后续 PR #4096 修复。单参数重载不能消除原有的两参数 null 调用歧义,因此采用旧头继承新头的方案,使旧重载成为更具体的匹配。
There was a problem hiding this comment.
Pull request overview
该 PR 针对 weixin-java-pay 电商收付通(Ecommerce)通知解析 API 做向后兼容:在保留当前统一模型(bean.notify.SignatureHeader)实现的前提下,补充对旧模型(bean.ecommerce.SignatureHeader)方法签名的兼容入口,帮助旧项目更平滑升级。
Changes:
- 在
EcommerceService为退款通知与提现通知解析新增已废弃的旧bean.ecommerce.SignatureHeader重载,并委托到统一实现(通过toUnifiedSignatureHeader转换)。 - 在
LegacyEcommerceApiCompatibilityTest增加反射级别的签名存在性测试,确保旧方法签名不被移除。
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| weixin-java-pay/src/main/java/com/github/binarywang/wxpay/service/EcommerceService.java | 为退款/提现通知解析补充旧版 SignatureHeader 的兼容重载,并复用统一签名转换逻辑。 |
| weixin-java-pay/src/test/java/com/github/binarywang/wxpay/service/LegacyEcommerceApiCompatibilityTest.java | 增加对旧版通知解析方法签名的兼容性测试(反射检查)。 |
Suppressed comments (1)
weixin-java-pay/src/main/java/com/github/binarywang/wxpay/service/EcommerceService.java:563
- 新增旧版 SignatureHeader 重载后,调用方如果传入 null(当前 Javadoc 允许不校验头)会在编译期出现方法重载歧义:parseWithdrawNotifyResult(String, SignatureHeader) 与 parseWithdrawNotifyResult(String, bean.ecommerce.SignatureHeader) 都可匹配 null,导致现有用户代码升级后无法编译。建议补充一个仅接收 notifyData 的 default 重载用于“不校验头”场景,提供无歧义的调用入口。
default WithdrawNotifyResult parseWithdrawNotifyResult(String notifyData,
com.github.binarywang.wxpay.bean.ecommerce.SignatureHeader header) throws WxPayException {
return parseWithdrawNotifyResult(notifyData, toUnifiedSignatureHeader(header));
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
| RefundNotifyResult parseRefundNotifyResult(String notifyData, SignatureHeader header) throws WxPayException; | ||
|
|
||
| /** | ||
| * @deprecated 从 4.8.5.B 起,请改用使用 {@link SignatureHeader} 的同名方法;5.0 将移除。 | ||
| */ | ||
| @Deprecated | ||
| default RefundNotifyResult parseRefundNotifyResult(String notifyData, | ||
| com.github.binarywang.wxpay.bean.ecommerce.SignatureHeader header) throws WxPayException { | ||
| return parseRefundNotifyResult(notifyData, toUnifiedSignatureHeader(header)); | ||
| } |
There was a problem hiding this comment.
已在后续 PR #4096 修复:采用旧头继承新头,而非增加单参数重载;这样保留原有两参数 null 调用且无歧义。
背景
#4087 恢复旧版收付通模型和部分服务入口后,
parseRefundNotifyResult、parseWithdrawNotifyResult仍只接受新的bean.notify.SignatureHeader,旧项目使用bean.ecommerce.SignatureHeader时无法直接升级。变更
SignatureHeader重载SignatureHeader重载toUnifiedSignatureHeader转换并委托新实现验证
git diff --check