Skip to content

feat(pay): 支持单参数 switchover 自定义键及通知回调空 appId 降级处理#3898

Merged
binarywang merged 3 commits intodevelopfrom
copilot/update-switchover-parameter
Mar 3, 2026
Merged

feat(pay): 支持单参数 switchover 自定义键及通知回调空 appId 降级处理#3898
binarywang merged 3 commits intodevelopfrom
copilot/update-switchover-parameter

Conversation

Copy link
Contributor

Copilot AI commented Mar 3, 2026

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 对比表格

使用示例

// 多租户场景:使用租户 ID 作为配置键
payService.addConfig("tenant_001", tenant1Config);
payService.addConfig("tenant_002", tenant2Config);

// 单参数切换,不依赖 mchId/appId 格式
payService.switchover("tenant_001");

// 链式调用
payService.switchoverTo("tenant_001").unifiedOrder(request);

// 通知回调中 appId 为空时可正常切换
payService.switchover(notifyResult.getMchId(), notifyResult.getAppid()); // appId 为 null 时自动降级
Original prompt

This section details on the original issue you should resolve

<issue_title>关于switchOver改成mchId+appId的入参的咨询</issue_title>
<issue_description>最近试用了一下4.7.7.B发现调用switchOver改成了mchId+appId的入参,感觉原来使用一个id作为入参的方式挺好的。
1.通过一个全局唯一id获取租户的配置感觉使用更方便一些
2.也不是所有的服务都依赖appid这个参数,比如微信支付通知回调
希望能保留或者兼容原来单参数switchOver的方法</issue_description>

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


💡 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.

Co-authored-by: binarywang <1343140+binarywang@users.noreply.github.com>
Copilot AI changed the title [WIP] Update switchOver to support mchId and appId parameters feat(pay): 支持单参数 switchover 自定义键及通知回调空 appId 降级处理 Mar 3, 2026
@binarywang binarywang marked this pull request as ready for review March 3, 2026 08:29
Copilot AI review requested due to automatic review settings March 3, 2026 08:29
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

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) and removeConfig(String configKey) to WxPayService interface and implemented in BaseWxPayServiceImpl, allowing any custom string (e.g., a tenant ID) as the config key.
  • Modified switchover(mchId, appId) and switchoverTo(mchId, appId) to automatically fall back to the single-argument form when appId is blank/null, fixing notification callback failures.
  • Updated MULTI_APPID_USAGE.md with new multi-tenant usage examples and an API comparison table; added corresponding tests in MultiAppIdSwitchoverTest.

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>
@binarywang binarywang merged commit 65deaab into develop Mar 3, 2026
1 check passed
@binarywang binarywang deleted the copilot/update-switchover-parameter branch March 3, 2026 08:41
@binarywang binarywang added this to the 4.8.2 milestone Mar 7, 2026
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.

关于switchOver改成mchId+appId的入参的咨询

3 participants