Skip to content

Add WxOpenMaService support to WxOpenMessageRouter with routeForMa methods #3654

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 3 commits into
base: develop
Choose a base branch
from

Conversation

Copilot
Copy link
Contributor

@Copilot Copilot AI commented Jul 24, 2025

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:

  1. routeForMa(WxMpXmlMessage wxMessage, String appId) - Routes mini-app messages with automatic service injection
  2. 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: WxOpenMaService available via context.get("wxOpenMaService")
  • Consistent API: Uses same WxMpXmlMessage format 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.

…thods

Co-authored-by: binarywang <1343140+binarywang@users.noreply.github.com>
@Copilot Copilot AI changed the title [WIP] WxOpenMessageRouter类方法中中缺少对WxOpenMaService的支持 Add WxOpenMaService support to WxOpenMessageRouter with routeForMa methods Jul 24, 2025
@Copilot Copilot AI requested a review from binarywang July 24, 2025 08:02
Copilot finished work on behalf of binarywang July 24, 2025 08:02
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.

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