Skip to content

为 WxOpenMessageRouter 添加 WxOpenMaService 支持,新增 routeForMa 方法 - #3654

Merged
binarywang merged 3 commits into
developfrom
copilot/fix-3629
Dec 22, 2025
Merged

为 WxOpenMessageRouter 添加 WxOpenMaService 支持,新增 routeForMa 方法#3654
binarywang merged 3 commits into
developfrom
copilot/fix-3629

Conversation

CopilotAI commented Jul 24, 2025

Copy link
Copy Markdown
Contributor

问题描述

WxOpenMessageRouter 类原本只支持将消息路由到 WxMpService(公众号),但缺少对 WxOpenMaService(小程序)的支持。这导致开发者在通过路由器处理小程序消息时无法访问小程序特定的功能。

用户原始问题:

@ComponentpublicclassWxMaAuditHandlerextendsAbstractWxOpenHandler {
@OverridepublicWxMpXmlOutMessagehandle(WxMpXmlMessagewxMessage, Map<String, Object> context, WxMpServicewxMpService, WxSessionManagersessionManager) {
// ❌ 问题:无法获取 WxOpenMaService 来进行小程序操作// wxOpenService.getWxOpenComponentService().getWxMaServiceByAppid(""); // 缺少 appid 上下文
}
}

解决方案

WxOpenMessageRouter 中新增了两个方法,将 WxOpenMaService 注入到消息上下文中:

  1. routeForMa(WxMpXmlMessage wxMessage, String appId) - 路由小程序消息并自动注入服务
  2. routeForMa(WxMpXmlMessage wxMessage, Map<String, Object> context, String appId) - 支持自定义上下文并注入服务

主要特性:

  • 向后兼容:所有现有的 route() 方法保持不变
  • 上下文注入:可通过 context.get("wxOpenMaService") 获取 WxOpenMaService
  • API一致性:使用与现有方法相同的 WxMpXmlMessage 格式
  • 改动最小:仅新增约25行代码

使用方式

开发者现在可以在处理器中访问 WxOpenMaService

@OverridepublicWxMpXmlOutMessagehandle(WxMpXmlMessagewxMessage, Map<String, Object> context, WxMpServicewxMpService, WxSessionManagersessionManager) {
// ✅ 现在可以获取 WxOpenMaService 进行小程序操作WxOpenMaServicemaService = (WxOpenMaService) context.get("wxOpenMaService");
if (maService != null) {
WxOpenMaQueryAuditResultresult = maService.getLatestAuditStatus();
maService.releaseAudited();
}
returnnull;
}
// 使用新方法路由小程序消息router.routeForMa(message, appId); // ✨ 新增 - 注入 WxOpenMaServicerouter.route(message, appId); // 不变 - 用于公众号消息

这使开发者能够通过现有的路由器基础设施处理小程序审核事件、代码提交和其他小程序特定操作。

修复 #3629


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

…thods
Co-authored-by: binarywang <1343140+binarywang@users.noreply.github.com>
CopilotAI changed the title [WIP] WxOpenMessageRouter类方法中中缺少对WxOpenMaService的支持Add WxOpenMaService support to WxOpenMessageRouter with routeForMa methodsJul 24, 2025
CopilotAI requested a review from binarywangJuly 24, 2025 08:02
@binarywangbinarywang added this to the 4.7.9 milestone Sep 24, 2025
@binarywangbinarywang modified the milestones: 4.7.9, 4.8.0Nov 27, 2025
@binarywang

Copy link
Copy Markdown
Owner

@copilot 请用中文改下描述文字

CopilotAI commented Nov 28, 2025

Copy link
Copy Markdown
ContributorAuthor

@copilot 请用中文改下描述文字

已将 PR 描述改为中文。

CopilotAI changed the title Add WxOpenMaService support to WxOpenMessageRouter with routeForMa methods为 WxOpenMessageRouter 添加 WxOpenMaService 支持,新增 routeForMa 方法Nov 28, 2025
@binarywang
binarywang marked this pull request as ready for review December 21, 2025 12:28
CopilotAI review requested due to automatic review settings December 21, 2025 12:28

CopilotAI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Pull request overview

本 PR 为 WxOpenMessageRouter 添加了小程序服务支持,同时修复了微信支付退款通知中的字段名拼写错误。主要目的是使开发者能够在处理开放平台消息时访问小程序特定的 API 功能。

  • 新增 routeForMa 方法,支持将 WxOpenMaService 注入到消息处理上下文中
  • 修复 WxPayRefundNotifyResult.ReqInfo 类中的字段名拼写错误:refundRecvAccoutrefundRecvAccount
  • 更新相应的测试用例以使用正确的方法名

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated no comments.

FileDescription
weixin-java-open/src/main/java/me/chanjar/weixin/open/api/impl/WxOpenMessageRouter.java新增 routeForMa 方法,通过 context 将 WxOpenMaService 传递给消息处理器,实现小程序消息路由支持
weixin-java-pay/src/main/java/com/github/binarywang/wxpay/bean/notify/WxPayRefundNotifyResult.java修正字段名拼写:refundRecvAccout → refundRecvAccount(保持 XML 别名不变以匹配微信 API)
weixin-java-pay/src/test/java/com/github/binarywang/wxpay/bean/notify/WxPayRefundNotifyResultTest.java更新测试用例以使用修正后的 getter 方法名

@binarywangbinarywang linked an issue Dec 22, 2025 that may be closed by this pull request
@binarywang
binarywang merged commit 8e760a9 into developDec 22, 2025
7 of 8 checks passed
@binarywang
binarywang deleted the copilot/fix-3629 branch March 10, 2026 03:51
Sign up for freeto 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.

WxOpenMessageRouter类方法中中缺少对WxOpenMaService的支持

3 participants

@binarywang