wechat-draft-publisher

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese

微信公众号草稿发布器

WeChat Official Account Draft Publisher

自动将 HTML 格式的文章发布到微信公众号草稿箱,支持封面图上传、标题、作者和摘要等元数据管理。
Automatically publish HTML-formatted articles to WeChat Official Account draft box, supporting cover image upload, title, author, abstract and other metadata management.

⚡ 快速开始

⚡ Quick Start

最简单的用法:
bash
python publisher.py --title "文章标题" --content article.html
完整参数:
bash
python publisher.py \
  --title "标题" \
  --content article.html \
  --author "作者名" \
  --cover cover.png \
  --digest "文章摘要"
默认值:
  • 作者:
    YanG
  • 封面图:
    cover.png
Simplest usage:
bash
python publisher.py --title "Article Title" --content article.html
Full parameters:
bash
python publisher.py \
  --title "Title" \
  --content article.html \
  --author "Author Name" \
  --cover cover.png \
  --digest "Article Abstract"
Default values:
  • Author:
    YanG
  • Cover image:
    cover.png

📋 执行步骤

📋 Execution Steps

发布文章到微信草稿箱的完整流程:
  1. 查找 HTML 文件
    • 优先查找
      *_formatted.html
      (formatter 输出)
    • 回退到最新的
      .html
      文件
  2. 提取文章标题
    • 从 HTML 注释提取:
      <!-- Title: xxx -->
    • 从文件名提取
    • 询问用户
  3. 检查封面图
    • 查找
      cover.png
    • 如缺失则警告但继续发布
  4. 调用发布脚本
    bash
    python publisher.py --title "xxx" --content xxx.html --cover xxx.png
  5. 验证结果
    • 确认草稿创建成功
    • 获取草稿 media_id
  6. 提示用户
    • 提供微信后台链接
    • 说明下一步操作
Complete workflow for publishing articles to WeChat draft box:
  1. Locate HTML file
    • Prioritize looking for
      *_formatted.html
      (formatter output)
    • Fall back to the latest
      .html
      file
  2. Extract article title
    • Extract from HTML comment:
      <!-- Title: xxx -->
    • Extract from file name
    • Ask user for input
  3. Check cover image
    • Look for
      cover.png
    • Warn but continue publishing if missing
  4. Call publishing script
    bash
    python publisher.py --title "xxx" --content xxx.html --cover xxx.png
  5. Verify results
    • Confirm draft creation success
    • Obtain draft media_id
  6. Notify user
    • Provide WeChat backend link
    • Explain next steps

🔧 配置要求

🔧 Configuration Requirements

首次使用

First-time Usage

工具会在首次运行时引导配置:
  1. 获取微信公众号凭证
  2. 运行发布器
    bash
    python publisher.py --title "测试" --content test.html
  3. 添加服务器 IP 到白名单(如需要)
The tool will guide you through configuration on first run:
  1. Obtain WeChat Official Account Credentials
  2. Run the publisher
    bash
    python publisher.py --title "Test" --content test.html
  3. Add server IP to whitelist (if required)

配置文件

Configuration File

位置:
~/.wechat-publisher/config.json
格式:
json
{
  "appid": "wx1234567890abcdef",
  "appsecret": "your_secret_here"
}
Location:
~/.wechat-publisher/config.json
Format:
json
{
  "appid": "wx1234567890abcdef",
  "appsecret": "your_secret_here"
}

✨ 核心功能

✨ Core Features

  • ✅ access_token 自动缓存(有效期 7200 秒)
  • ✅ 封面图上传和管理
  • ✅ HTML 内容自动优化(适配微信)
  • ✅ 字段长度自动截断(标题/作者/摘要)
  • ✅ 错误处理和重试机制
  • ✅ 中文错误提示和解决方案
  • ✅ 交互模式和命令行模式
  • ✅ Automatic access_token caching (valid for 7200 seconds)
  • ✅ Cover image upload and management
  • ✅ Automatic HTML content optimization (WeChat-adapted)
  • ✅ Automatic field length truncation (title/author/abstract)
  • ✅ Error handling and retry mechanism
  • ✅ Chinese error prompts and solutions
  • ✅ Interactive mode and command-line mode

🛠️ 工作流集成

🛠️ Workflow Integration

与其他 skill 协同工作:
完整工作流:
  1. wechat-tech-writer
    → 生成文章(
    xxx_article.md
    +
    cover.png
  2. wechat-article-formatter
    → 格式化 HTML(
    xxx_formatted.html
  3. wechat-draft-publisher
    → 发布到微信草稿箱(本 skill)
自动检测机制:
  • 自动查找
    *_formatted.html
    文件
  • 自动查找
    cover.png
    封面图
  • 自动识别内容图片
Collaborate with other skills:
Complete workflow:
  1. wechat-tech-writer
    → Generate article (
    xxx_article.md
    +
    cover.png
    )
  2. wechat-article-formatter
    → Format HTML (
    xxx_formatted.html
    )
  3. wechat-draft-publisher
    → Publish to WeChat draft box (this skill)
Automatic detection mechanism:
  • Automatically find
    *_formatted.html
    files
  • Automatically find
    cover.png
    cover images
  • Automatically identify content images

🚨 常见问题

🚨 FAQ

错误:IP 不在白名单

Error: IP not in whitelist

症状:
invalid ip not in whitelist
解决:
  1. 登录微信公众号后台
  2. 进入 设置 → 基本配置
  3. 添加服务器 IP 到白名单
Symptom:
invalid ip not in whitelist
Solution:
  1. Log in to WeChat Official Account backend
  2. Go to Settings → Basic Configuration
  3. Add server IP to whitelist

错误:AppSecret 错误

Error: AppSecret error

症状:
AppSecret error
解决:
  • 检查配置文件:
    ~/.wechat-publisher/config.json
  • 验证 AppID 以 "wx" 开头(18 个字符)
  • 确认 AppSecret 正确
Symptom:
AppSecret error
Solution:
  • Check configuration file:
    ~/.wechat-publisher/config.json
  • Verify AppID starts with "wx" (18 characters)
  • Confirm AppSecret is correct

错误:标题/作者超出限制

Error: Title/author exceeds limit

症状:
title/author size out of limit
解决:
  • 工具会自动截断(标题:32 字节,作者:20 字节)
  • 如需调整,修改
    publisher.py
Symptom:
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               # 详细英文文档
wechat-draft-publisher/
├── SKILL.md                # This file
├── publisher.py            # Core publishing script
├── scripts/                # Utility scripts
│   ├── fix-wechat-style.py # HTML optimizer
│   ├── optimize-html.py    # HTML compression tool
│   ├── publish-workflow.sh # Complete workflow
│   ├── install.sh          # Installation assistant
│   └── test.sh             # Test script
├── examples/               # Example files
│   ├── config.json.example # Configuration example
│   └── example.html        # HTML example
└── README.md               # Detailed English documentation

💡 使用示例

💡 Usage Examples

示例 1:标准发布
bash
python publisher.py \
  --title "VSCode 更名事件" \
  --content article.html
示例 2:完整元数据
bash
python publisher.py \
  --title "技术文章" \
  --content article.html \
  --author "YanG" \
  --cover images/cover.png \
  --digest "这是一篇关于..."
示例 3:交互模式
bash
python publisher.py --interactive
Example 1: Standard publishing
bash
python publisher.py \
  --title "VSCode Renaming Incident" \
  --content article.html
Example 2: Full metadata
bash
python publisher.py \
  --title "Technical Article" \
  --content article.html \
  --author "YanG" \
  --cover images/cover.png \
  --digest "This is an article about..."
Example 3: Interactive mode
bash
python publisher.py --interactive

📱 发布后操作

📱 Post-Publishing Actions

发布成功后:
  1. 登录微信公众号后台
  2. 进入"草稿箱"
  3. 预览效果
  4. 确认后发布
注意事项:
  • ⚠️ 草稿保存在微信后台,不会立即发布
  • ⚠️ 可以在草稿箱中编辑后再发布
  • ⚠️ 封面图会在预览时显示
After successful publishing:
  1. Log in to WeChat Official Account backend
  2. Go to "Draft Box"
  3. Preview the effect
  4. Publish after confirmation
Notes:
  • ⚠️ Drafts are saved in WeChat backend and will not be published immediately
  • ⚠️ You can edit drafts in the draft box before publishing
  • ⚠️ Cover images will be displayed during preview

🔗 相关文档

🔗 Related Documents

  • 详细文档: README.md(英文)
  • 安装指南: scripts/install.sh
  • HTML 处理: scripts/fix-wechat-style.py
  • Detailed Documentation: README.md (English)
  • Installation Guide: scripts/install.sh
  • HTML Processing: scripts/fix-wechat-style.py