This skill is used to publish articles to the WeChat Official Account draft box. The script relies only on Node.js built-in modules; the automatic cover generation step reuses the existing bun image generation script.
Prerequisites
Node.js >= 16- To automatically generate a cover, you also need
bun - available on the local machine. In the skill directory,
.envmust contain at least:
WECHAT_APP_ID=你的公众号AppID
WECHAT_APP_SECRET=你的公众号AppSecret
WECHAT_DEFAULT_THUMB_MEDIA_ID=默认封面图media_id(可选)
WECHAT_DEFAULT_AUTHOR=AI源来如此(可选)
- The public IP of the machine running the script has been added to the Official Account backend IP whitelist
- When automatically generating a cover, you need to ensure that
zhy-article-illustrator's image generation environment is available
Installation Instructions
This skill is suitable for being installed together with npx skills add ... --skill zhy-wechat-publish into agent tools such as OpenCode and Claude Code that support SKILL.md .
After installation, please manually create .envin the local skill directory. Do not commit real credentials back to the repository.
Script List
The scripts are located in scripts/:
| Script | Purpose |
|---|---|
wechat_draft.js |
Upload the body to the Official Account draft box |
upload_image.js |
Upload a local cover image to the permanent material library and obtain media_id |
publish_with_cover.js |
Read the article, generate a cover, upload the cover, and push the draft |
Core Capabilities
- Automatically handle body CSS variable compatibility
- Automatically upload body images to the WeChat body image interface and replace URLs
- Automatically downgrade
ul/olto a paragraph list that is more stable in the WeChat Official Account editing state - Support default author, comment toggle, and fans-only comment setting
- Support generating a single Official Account cover from article content and automatically uploading it as
thumb_media_id
Workflow
Method 1: HTML and cover media_id are ready
node scripts/wechat_draft.js --title "文章标题" --file "post.html" --author "AI源来如此" --thumb "MEDIA_ID" --need-open-comment "1" --only-fans-can-comment "1"
Parameter Description:
| Parameter | Required | Description |
|---|---|---|
--title |
Yes | Article title |
--file |
Yes | HTML body file path |
--author |
No | Author; if not provided, defaults to WECHAT_DEFAULT_AUTHOR or AI源来如此 |
--digest |
No | Summary |
--thumb |
No | Cover media_id; if not provided, read .env default value |
--source-url |
No | Original link |
--need-open-comment |
No | Whether to enable comments, default 1 |
--only-fans-can-comment |
No | Whether only fans can comment, default 1 |
Method 2: Automatically generate a cover and publish
When you already have the article source file and the final HTML file used for upload, you can run directly:
node scripts/publish_with_cover.js --article "article.md" --html "post.html" --author "AI源来如此" --source-url "https://example.com"
The script will automatically complete:
- Read the article content and extract the title/summary
- Call
zhy-article-illustrator/scripts/image-gen.tsto generate a single 16:9 cover image - Call
upload_image.js --jsonto upload the cover and obtainthumb_media_id - Call
wechat_draft.jsto push the draft, and automatically include:authorthumb_media_idneed_open_comment=1only_fans_can_comment=1
Optional Parameters:
| Parameter | Description |
|---|---|
--article |
Original article file, Markdown recommended, HTML also acceptable |
--html |
The final HTML file uploaded to the Official Account |
--title |
Explicitly override the title |
--author |
Explicitly override the author |
--cover-output |
Custom cover output path |
--cover-ar |
Cover aspect ratio, default 16:9 |
--source-url |
Original link |
--need-open-comment |
Whether comments are enabled, default 1 |
--only-fans-can-comment |
Whether only followers can comment, default 1 |
Body compatibility notes
Before publishing,wechat_draft.js will automatically handle:
var(--xxx)CSS variable expansion- WeChat section background style compatibility
- The first
h1is removed to avoid duplication with the title - Body images are uploaded to
cgi-bin/media/uploadimg - Native lists are converted to plain paragraph lists
Troubleshooting
[40013] invalid appid: Check.envinWECHAT_APP_ID[40164] invalid ip... not in whitelist: Add the error IP to the WeChat backend whitelist[40007] invalid media_id: The cover asset is invalid; re-upload the cover image缺少 Xiaomi/Gemini/OpenAI API Key: The image generation configuration required for automatic cover generation is missing- Body images not displaying: Check whether the original image path/URL is accessible, and whether
media/uploadimgsucceeded
Quick example
# 已有 HTML,直接发草稿
node scripts/wechat_draft.js --title "技术周报" --file "post.html"
# 自动生封面并发布
node scripts/publish_with_cover.js --article "article.md" --html "post.html"
# 上传封面图并把 media_id 回写 .env
node scripts/upload_image.js "cover.png" --write-env --json