简体中文 English 繁體中文 日本語 Русский
本文为静态镜像,内容以交互版为准 在交互式文档中心打开 →

WeChat MP Adapter - Platform Features Documentation

Basic Information

v5 Paradigm Update (4.2.0)


Platform Capabilities Already Integrated


Supported Message Sending Types

Method Description WeChat API
Text(text) Send text message Customer Service Message message/custom/send
Image(file) Send image (automatically uploads and retrieves media_id) Customer Service Message + media/upload
Voice(file) Send voice (automatically uploads and retrieves media_id) Customer Service Message + media/upload
Video(file, title, description) Send video (automatically uploads and retrieves media_id) Customer Service Message + media/upload
Music(url, title, description, ...) Send music Customer Service Message
News(articles) Send news message Customer Service Message
Template(template_id, data, url) Send template message message/template/send
Menu(head_content, list, tail_content) Send menu message Customer Service Message msgmenu
Raw_ob12(message) Send OneBot12 standard message segment -

Media File Notes

Important Restrictions

Event Types

Message Events (message)

All user messages have detail_type: private (1v1 scenario for official accounts).

WeChat MsgType Message Segment Type Description
text text Text message
image image Image message
voice voice Voice message (includes voice recognition result)
video video Video message
shortvideo video Short video (marked with mp_shortvideo)
location location Location message
link text Link message (converted to text)

Notification Events (notice)

Events are distinguished by the mp_event field.

WeChat Event mp_event Description
subscribe subscribe Subscribe to official account
unsubscribe unsubscribe Unsubscribe from official account
SCAN scan Scan a QR code with parameters
LOCATION location_report Report location
CLICK menu_click Click on a custom menu
VIEW menu_view Navigate to a menu link
TEMPLATESENDJOBFINISH template_send_finish Template message send result
MASSSENDJOBFINISH mass_send_finish Mass message send result

Platform Extension Fields

WeChat-specific fields (with mp_ prefix) in the event object:

Field Type Description
mp_raw str Raw XML data
mp_raw_type str Original message/event type
mp_msg_id str WeChat message ID
mp_event str Event type (only for event notifications)
mp_event_key str Event Key (menu click/scan, etc.)
mp_to_user str Receiver's WeChat ID (official account original ID)
mp_from_user str Sender's OpenID
mp_data dict Parsed XML dictionary data

Event Extension Methods

Registered via register_event_mixin("mp", ...), allowing direct calls on event objects:

Method Return Value Description
get_openid() str Sender's OpenID
get_msg_type() str Original WeChat message type
get_event() str Event type (only for event notifications)
get_content() str Pure text content of the message
get_raw_xml() str Raw XML data

Configuration Options

Multi-Account Configuration

Each account corresponds to a public account:

[WechatMpAdapter.accounts.main]
appid = "wx1234567890abcdef"
appsecret = "your_app_secret_here"
token = "your_callback_token"
encoding_aes_key = ""                    # Required for secure mode/compatibility mode (43 characters)
callback_path = "/mp/main"               # Callback path
verified = true                          # Whether it is a verified service account (affects active sending capability)
enable = true

[WechatMpAdapter.accounts.secondary]
appid = "wx0987654321fedcba"
appsecret = "another_app_secret"
token = "another_callback_token"
callback_path = "/mp/secondary"
enable = true

Configuration Field Descriptions

Field Required Description
appid Yes Public account AppID
appsecret Yes Public account AppSecret (secret)
token No Callback verification Token (recommended to enable signature verification)
encoding_aes_key No Message encryption/decryption key (43 characters, required for secure mode)
callback_path No Callback path template, default /mp/{account}, {account} will be replaced by the account name
verified No Whether it is a verified service account, default true (see below for details)
enable No Whether to enable, default true

Verified Service Account and Passive Reply (verified)

Encryption Mode Explanation

WeChat Official Accounts provide three message encryption and decryption modes:

Mode Description encoding_aes_key Verification Field
Plaintext Mode XML transmitted in plaintext Not required signature
Compatible Mode Both plaintext and encrypted messages exist Optional signature / msg_signature
Secure Mode Entire message encrypted Required msg_signature

This adapter automatically handles:

Callback Routes

The adapter registers two routes (GET + POST) for each enabled account:

The actual access paths automatically include the module prefix. For example, if the registered path is /mp/main, the actual access paths will be /mp_{account}_verify/mp/main and /mp_{account}_message/mp/main.

API Response

All call_api calls return a standardized response: