Add WxOpenMaService support to WxOpenMessageRouter with routeForMa methods
Problem
The WxOpenMessageRouter class only supported routing messages to WxMpService (公众号) but lacked support for WxOpenMaService (小程序/miniapp). This prevented developers from accessing mini-app specific functionality when handling mini-app messages through the router.
User's original issue:
@Component
public class WxMaAuditHandler extends AbstractWxOpenHandler {
@Override
public WxMpXmlOutMessage handle(WxMpXmlMessage wxMessage, Map<String, Object> context,
WxMpService wxMpService, WxSessionManager sessionManager) {
// ❌ Problem: No way to access WxOpenMaService for mini-app operations
// wxOpenService.getWxOpenComponentService().getWxMaServiceByAppid(""); // Missing appid context
}
}
Solution
Added two new methods to WxOpenMessageRouter that inject WxOpenMaService into the message context:
-
routeForMa(WxMpXmlMessage wxMessage, String appId)- Routes mini-app messages with automatic service injection -
routeForMa(WxMpXmlMessage wxMessage, Map<String, Object> context, String appId)- Routes with custom context plus service injection
Key Features:
- ✅ Backward Compatible: All existing
route()methods unchanged - ✅ Context Injection:
WxOpenMaServiceavailable viacontext.get("wxOpenMaService") - ✅ Consistent API: Uses same
WxMpXmlMessageformat as existing methods - ✅ Minimal Changes: Only 25 lines of new code
Usage
Now developers can access WxOpenMaService in their handlers:
@Override
public WxMpXmlOutMessage handle(WxMpXmlMessage wxMessage, Map<String, Object> context,
WxMpService wxMpService, WxSessionManager sessionManager) {
// ✅ Now can access WxOpenMaService for mini-app operations
WxOpenMaService maService = (WxOpenMaService) context.get("wxOpenMaService");
if (maService != null) {
WxOpenMaQueryAuditResult result = maService.getLatestAuditStatus();
maService.releaseAudited();
}
return null;
}
// Route mini-app messages using the new method
router.routeForMa(message, appId); // ✨ NEW - injects WxOpenMaService
router.route(message, appId); // Unchanged - for MP messages
This enables developers to handle mini-app audit events, code submissions, and other mini-app specific operations through the existing router infrastructure.
Fixes #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.