通过微信公众号官方 API 把图文送入草稿箱或直接群发,支持封面上传与发布前检查。
编程
WeChat MP Publish Toolkit
试用WeChat Official Account (微信公众号) draft push and auto-publish toolkit. This skill should be used when the user wants to push article drafts to a WeChat Officia...
它能做什么
WeChat 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, 微信发布, 推送草稿, 自动发布, 公众号发布.
技能文档
WeChat MP Publisher
Overview
A generic toolkit for pushing and publishing articles to a WeChat Official Account (公众号) via the WeChat MP API. Supports two core operations:
- Push Draft — Upload article HTML + cover image to the draft box (
draft/add) - Publish Draft — Publish a draft from the draft box to all subscribers (
freepublish/submit)
Plus a daily automation template for scheduled auto-publishing.
First-Time Setup
1. Configure Credentials
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:
- Login to https://mp.weixin.qq.com
- Settings & Development → Development → Basic Configuration
- AppID is visible directly; AppSecret click "Reset" to get (save immediately, only shown once)
2. IP Whitelist
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白名单).
3. API Permissions
draft/add(push draft): Available to all verified accountsfreepublish/submit(publish): Requires verified enterprise/organization account (已认证的企业/个体工商户主体). Permission activates ~24 hours after verification. Iferrcode=48001, the permission is still syncing — publish manually from the draft box.
Core Tasks
Task 1: Push Draft to 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:
- Load credentials from the
--envfile - Get
access_token(handles 40164 IP whitelist error) - If
--thumbnot provided and a cover image path is given, upload it to the material library first - Push the draft via
draft/addAPI - Print the resulting
media_id
Key constraints:
- Title: max 64 bytes (~21 Chinese characters)
- Digest (摘要): max 120 characters
- Author: leave empty via API (Chinese names exceed 8-byte limit) — set manually in editor
- Article images must use
mmbiz.qpic.cndomains (upload to material library first) - JSON must use
ensure_ascii=Falseto avoid garbled Chinese — the script handles this withcurl --data-binary
Task 2: Publish a Draft
Use 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:
- Load credentials from the
--envfile - Get
access_token - Call
freepublish/submitwith themedia_id - Report success (
publish_id) or the specific error code
Error 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.
Task 3: Set Up Daily Auto-Publish Automation
Refer to references/automation-template.md for the complete automation prompt. The recommended setup:
- Draft generation automation — runs daily (e.g., 15:00) to generate article content and push to draft box
- Publish automation — runs daily (e.g., 20:00) to call
freepublish/submiton the day's draft
Create automations using the automation_update tool with:
scheduleType: "recurring"rrule: "FREQ=DAILY;BYHOUR=20;BYMINUTE=0"(for 20:00 daily)- The prompt from
references/automation-template.md
Quick API Reference (Bash)
For 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"
Resources
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
相关技能
基于微信云托管 relay 的公众号草稿发布器:把现成的 markdown 文章 + 封面图推送到微信公众号草稿箱,本地无需 appid/secret、免 IP 白名单。触发:「推草稿」「发公众号草稿箱」「wechat draft publish」「send to wechat draft」。不触发:写文章、tr...
Write and publish WeChat Official Account articles end-to-end with AI, or take an existing draft straight into the skill's built-in formatting + direct-send...
Independently turn an article into WeChat Official Accounts compatible Markdown/HTML, present built-in theme choices, and publish to WeChat as a draft or for...
公众号图文从选题到发布全流程编排,单条指令跑完 8 个子 skill。
微信公众号写作发布助手 / WeChat Official Account Writer. 用于写公众号文章、微信公众号推文、技术长文、AI 热点解读、个人观点文、产品文章、教程文章和商业内容;支持选题策划、爆款标题、文章大纲、正文成稿、润色改写、链接翻译/链接改写、AI 资讯整理、Markdown/微信 HTM...