feat(pay): 支持单参数 switchover 自定义键及通知回调空 appId 降级处理#3898
Conversation
Co-authored-by: binarywang <1343140+binarywang@users.noreply.github.com>
There was a problem hiding this comment.
Pull request overview
This PR addresses a regression introduced in v4.7.7.B, where switchOver was changed to require both mchId + appId parameters. This broke multi-tenant (SaaS) scenarios (using custom unique keys for config management) and payment notification callbacks (where appId may be absent). The fix adds a single-key API overload and adds a graceful fallback when appId is blank.
Changes:
- Added
addConfig(String configKey, WxPayConfig)andremoveConfig(String configKey)toWxPayServiceinterface and implemented inBaseWxPayServiceImpl, allowing any custom string (e.g., a tenant ID) as the config key. - Modified
switchover(mchId, appId)andswitchoverTo(mchId, appId)to automatically fall back to the single-argument form whenappIdis blank/null, fixing notification callback failures. - Updated
MULTI_APPID_USAGE.mdwith new multi-tenant usage examples and an API comparison table; added corresponding tests inMultiAppIdSwitchoverTest.
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
weixin-java-pay/src/main/java/com/github/binarywang/wxpay/service/WxPayService.java |
Adds addConfig(String, WxPayConfig) and removeConfig(String) interface methods; updates Javadoc for single-arg switchover/switchoverTo to describe dual-mode matching |
weixin-java-pay/src/main/java/com/github/binarywang/wxpay/service/impl/BaseWxPayServiceImpl.java |
Implements the new single-key addConfig/removeConfig methods; adds null/blank appId fallback in switchover(mchId, appId) and switchoverTo(mchId, appId) |
weixin-java-pay/src/test/java/com/github/binarywang/wxpay/service/impl/MultiAppIdSwitchoverTest.java |
Adds test cases for custom-key add/remove/switchover and for null/blank appId fallback behavior |
weixin-java-pay/MULTI_APPID_USAGE.md |
Adds new section 2 for multi-tenant custom-key usage, updates API table, adds description of null-appId fallback; contains duplicate section numbering |
The only identified issue is a documentation inconsistency: the new section ### 2. 使用自定义唯一键配置(多租户场景) (line 62) was inserted without renumbering the subsequent ### 2. 获取配置的方式 (line 102) through ### 5. sections, resulting in two sections both numbered "2.". The code changes themselves are correct, consistent, and well-tested.
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
4.7.7.B 将
switchOver改为必须传入mchId + appId两个参数,导致多租户场景(使用自定义唯一键管理配置)和通知回调(appId 可能为空)无法正常切换配置。变更
新增单键 API(多租户场景)
WxPayService.addConfig(String configKey, WxPayConfig)— 以任意唯一键注册配置WxPayService.removeConfig(String configKey)— 以任意唯一键移除配置switchover(String)/switchoverTo(String)本身已支持精确 key 匹配,Javadoc 补充说明其可接受任意自定义键修复通知回调空 appId 问题
switchover(mchId, appId)/switchoverTo(mchId, appId)当appId为 null 或空白时,自动降级为switchover(mchId)而非以mchId_null查找失败文档
MULTI_APPID_USAGE.md补充多租户用法示例及完整 API 对比表格使用示例
Original prompt
💡 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.