Automatically publish HTML-format articles to the WeChat Official Account draft box, supporting metadata management such as cover image upload, title, author, and summary.
⚡ Quick Start
Simplest usage:
python publisher.py --title "文章标题" --content article.html
Full parameters:
python publisher.py \
--title "标题" \
--content article.html \
--author "作者名" \
--cover cover.png \
--digest "文章摘要"
Default values:
- Author:
YanG - Cover image:
cover.png
📋 Execution Steps
Complete process for publishing an article to the WeChat draft box:
-
Find the HTML file
- Prioritize finding
*_formatted.html(formatter output) - Fall back to the latest
.htmlfile
- Prioritize finding
-
Extract the article title
- Extract from HTML comments:
<!-- Title: xxx --> - Extract from the file name
- Ask the user
- Extract from HTML comments:
-
Check the cover image
- Find
cover.png - If missing, warn but continue publishing
- Find
-
Call the publishing script
python publisher.py --title "xxx" --content xxx.html --cover xxx.png -
Verify the result
- Confirm the draft was created successfully
- Get the draft media_id
-
Notify the user
- Provide the WeChat backend link
- Explain the next steps
🔧 Configuration Requirements
First-time use
The tool will guide configuration on first run:
-
Obtain WeChat Official Account credentials
- Visit https://mp.weixin.qq.com
- Go to Settings → Basic Configuration
- Copy the AppID and AppSecret
-
Run the publisher
python publisher.py --title "测试" --content test.html -
Add the server IP to the whitelist(if needed)
Configuration file
Location: ~/.wechat-publisher/config.json
Format:
{
"appid": "wx1234567890abcdef",
"appsecret": "your_secret_here"
}
✨ Core Features
- ✅ Automatic access_token caching (valid for 7200 seconds)
- ✅ Cover image upload and management
- ✅ Automatic HTML content optimization (adapted for WeChat)
- ✅ Automatic field length truncation (title/author/summary)
- ✅ Error handling and retry mechanism
- ✅ Chinese error messages and solutions
- ✅ Interactive mode and command-line mode
🛠️ Workflow Integration
Works in coordination with other skills:
Complete workflow:
wechat-tech-writer→ Generate article (xxx_article.md+cover.png)wechat-article-formatter→ Format HTML (xxx_formatted.html)wechat-draft-publisher→ Publish to WeChat draft box (this skill)
Automatic detection mechanism:
- Automatically find
*_formatted.htmlfiles - Automatically find
cover.pngcover images - Automatically identify content images
🚨 Common Issues
Error: IP not in whitelist
Symptoms: invalid ip not in whitelist
Solution:
- Log in to the WeChat Official Account backend
- Go to Settings → Basic Configuration
- Add the server IP to the whitelist
Error: Incorrect AppSecret
Symptoms: AppSecret error
Solution:
- Check the configuration file:
~/.wechat-publisher/config.json - Verify that the AppID starts with "wx" (18 characters)
- Confirm that the AppSecret is correct
Error: Title/author exceeds the limit
Symptoms: title/author size out of limit
Solution:
- The tool will automatically truncate (title: 32 bytes, author: 20 bytes)
- To adjust, modify
publisher.py
📁 File structure
wechat-draft-publisher/
├── SKILL.md # 本文件
├── publisher.py # 核心发布脚本
├── scripts/ # 工具脚本
│ ├── fix-wechat-style.py # HTML 优化器
│ ├── optimize-html.py # HTML 压缩工具
│ ├── publish-workflow.sh # 完整工作流
│ ├── install.sh # 安装助手
│ └── test.sh # 测试脚本
├── examples/ # 示例文件
│ ├── config.json.example # 配置示例
│ └── example.html # HTML 示例
└── README.md # 详细英文文档
💡 Usage examples
Example 1: Standard publishing
python publisher.py \
--title "VSCode 更名事件" \
--content article.html
Example 2: Complete metadata
python publisher.py \
--title "技术文章" \
--content article.html \
--author "YanG" \
--cover images/cover.png \
--digest "这是一篇关于..."
Example 3: Interactive mode
python publisher.py --interactive
📱 Post-publishing actions
After successful publishing:
- Log in to the WeChat Official Account backend
- Go to "Drafts"
- Preview the result
- Publish after confirmation
Notes:
- ⚠️ The draft is saved in the WeChat backend and will not be published immediately
- ⚠️ You can edit it in the drafts box before publishing
- ⚠️ The cover image will be displayed during preview
🔗 Related documentation
- Detailed documentation: README.md(English)
- Installation guide: scripts/install.sh
- HTML processing: scripts/fix-wechat-style.py