Documentation Sync
This page is auto-generated from plugins/adapters/wechat-mp/README.md. Please edit the in-package README and then run pnpm sync:adapter-docs.
@zhin.js/adapter-wechat-mp
Zhin.js WeChat Official Account adapter (Plugin Runtime). Sends and receives messages via the Runtime Host HTTP Webhook.
Features
- Webhook event reception (
httpHostTokenGET signature verification + POST messages) - Signature verification with optional AES encryption/decryption
- Automatic Access Token refresh
- XML message parsing
- Convention-based
defineAdapter/definePlugin(nousePluginneeded)
Installation
pnpm add @zhin.js/adapter-wechat-mpPlugin Runtime
@zhin.js/adapter— convention-basedadapters/wechat-mp.ts(defineAdapter)@zhin.js/core—messageGatewayTokeninbound/outbound@zhin.js/host-http—httpHostTokenregisters Webhook route (not legacy host-router/Koa)@zhin.js/plugin-runtime—plugin.ts(definePlugin)- Configuration goes to
plugins.<instanceKey>via the plugin'sschema.json
Inbound: gateway.receive({ adapter, target: openid, content: text, sender, metadata }) Outbound: send({ target, payload }) -> passive reply XML (default) or Customer Service Message API (replyMode: customer_service)
Prerequisites
| Requirement | Description |
|---|---|
| Official Account | A registered WeChat Official Account; obtain AppID and AppSecret from the WeChat Official Account Platform |
| Server configuration | Configure Token (must match the token field); server URL must be publicly accessible |
| host-http | Required — Runtime Host provides HTTP; the adapter registers GET/POST on path |
| Response time limit | WeChat requires a response within 5 seconds; timeouts will cause connection failure |
| Reply mode | Default replyMode: passive (subscription account passive reply); service accounts can set customer_service |
| Message encryption | Optional; encrypt: true + encodingAESKey; encryptMode: compatible (default) or secure |
Required fields (endpoints[i]): name, appId, appSecret, token.
Minimal Configuration
# zhin.config.yml (Plugin Runtime)
plugins:
wechat-mp:
path: /wechat/webhook
endpoints:
- name: my-wechat-bot
appId: "${WECHAT_APP_ID}"
appSecret: "${WECHAT_APP_SECRET}"
token: "${WECHAT_TOKEN}"The root plugin zhin.plugins (or project graph) must reference @zhin.js/adapter-wechat-mp (instanceKey: wechat-mp). The Runtime Host (http) must already be listening for the Webhook to be reachable.
Optional Fields
path: Webhook path, default/wechat/webhookreplyMode:passive(default) |customer_servicepassiveReplyTimeoutMs: Passive reply wait limit, default4500encrypt/encodingAESKey/encryptMode
WeChat Official Account Configuration
- Log in to the WeChat Official Account Platform
- Obtain
AppIDandAppSecretfrom "Development -> Basic Configuration" - Configure the server address (URL):
https://your-server/wechat/webhook(no/apiprefix; map through reverse proxy as needed) - Set the Token (must match the
tokenin the configuration file) - If message encryption is needed, set the EncodingAESKey
Troubleshooting
| Symptom | Investigation |
|---|---|
| Server configuration verification failure | token must match the Official Account Platform; URL should be https://<host>/wechat/webhook; Runtime Host must be listening and publicly accessible |
| Not receiving user messages | Check if the Official Account type supports the message interface; check if the user has followed the account; path must match the Official Account Platform URL; endpoint must have called open() |
| Reply timeout / no reply | Default passive reply must complete within ~4.5s; consider switching to replyMode: customer_service (requires Customer Service API permissions) |
48001 api unauthorized | Unverified subscription accounts do not have Customer Service API access; keep the default replyMode: passive |
| Encryption mode error | encodingAESKey, encrypt must match the Official Account Platform's "Security Mode" settings |
AI Tools
See agent/skills/wechat-mp.md for skill documentation.
Documentation Links
License
MIT License