Install
openclaw skills install @yyi162751-collab/wechat-mp-publish-toolkitWeChat Official Account (微信公众号) draft push and auto-publish toolkit. This skill should be used when the user wants to push article drafts to a WeChat Official Account draft box via API, publish drafts automatically on a schedule, or set up a daily publishing automation. Covers credential setup, IP whitelisting, draft creation, and freepublish/submit publishing. Triggers: push draft, publish to WeChat, auto-publish, 微信发布, 推送草稿, 自动发布, 公众号发布.
openclaw skills install @yyi162751-collab/wechat-mp-publish-toolkitA generic toolkit for pushing and publishing articles to a WeChat Official Account (公众号) via the WeChat MP API. Supports two core operations:
draft/add)freepublish/submit)Plus a daily automation template for scheduled auto-publishing.
Copy assets/.env.example to a permanent location and fill in values:
cp assets/.env.example ~/.wechat-mp.env
Edit the file:
WECHAT_APPID=wx_your_appid_here
WECHAT_SECRET=your_secret_here
WECHAT_AUTHOR=你的公众号名称
Where to find credentials:
The server IP calling the API must be whitelisted, otherwise errcode=40164.
To get the current server IP:
curl -s https://api.ipify.org
Add this IP at: mp.weixin.qq.com → Development → Basic Configuration → IP Whitelist (IP白名单).
draft/add (push draft): Available to all verified accountsfreepublish/submit (publish): Requires verified enterprise/organization account (已认证的企业/个体工商户主体). Permission activates ~24 hours after verification. If errcode=48001, the permission is still syncing — publish manually from the draft box.Use scripts/push_draft.py to push an article as a draft.
python3 scripts/push_draft.py \
--env ~/.wechat-mp.env \
--title "文章标题" \
--digest "文章摘要,不超过120字" \
--html /path/to/article.html \
--thumb MEDIA_ID_OR_LEAVE_BLANK
What the script does:
--env fileaccess_token (handles 40164 IP whitelist error)--thumb not provided and a cover image path is given, upload it to the material library firstdraft/add APImedia_idKey constraints:
mmbiz.qpic.cn domains (upload to material library first)ensure_ascii=False to avoid garbled Chinese — the script handles this with curl --data-binaryUse scripts/publish_draft.py to publish a draft that's already in the draft box.
python3 scripts/publish_draft.py \
--env ~/.wechat-mp.env \
--media-id MEDIA_ID_FROM_DRAFT
What the script does:
--env fileaccess_tokenfreepublish/submit with the media_idpublish_id) or the specific error codeError handling:
| errcode | Meaning | Action |
|---|---|---|
| 0 | Success | Notify user, provide publish_id |
| 48001 | API permission not active | Tell user to publish manually from mp.weixin.qq.com draft box |
| 40007 | media_id invalid (already published or deleted) | Tell user to check the draft box |
| -1 | System error (transient) | Retry 2-3 times; if persistent, manual publish |
Publishing is irreversible — once published, the article goes to all subscribers. Always verify the media_id is correct.
Refer to references/automation-template.md for the complete automation prompt. The recommended setup:
freepublish/submit on the day's draftCreate automations using the automation_update tool with:
scheduleType: "recurring"rrule: "FREQ=DAILY;BYHOUR=20;BYMINUTE=0" (for 20:00 daily)references/automation-template.mdFor ad-hoc operations, use scripts/wechat_api.sh:
source scripts/wechat_api.sh
# Set credentials
export WECHAT_APPID="wx_your_appid"
export WECHAT_SECRET="your_secret"
# Get access token
TOKEN=$(get_wechat_token)
# Upload cover image (returns media_id)
upload_wechat_image "$TOKEN" /path/to/cover.png
# Create draft from JSON file
create_draft "$TOKEN" /path/to/draft.json
# Publish draft
publish_draft "$TOKEN" "MEDIA_ID_HERE"
scripts/push_draft.py — Push article HTML to draft box (Python, uses curl for binary-safe JSON)scripts/publish_draft.py — Publish a draft via freepublish/submit (Python)scripts/wechat_api.sh — Bash helper functions for all WeChat MP API callsreferences/api-guide.md — Detailed API documentation, error codes, encoding gotchasreferences/automation-template.md — Ready-to-use automation prompt for daily publishingassets/.env.example — Credential template file