zhy-wechat-publish
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
Chinese微信公众号草稿箱发布技能
WeChat Official Account Draft Publishing Skill
本技能用于将文章发布到微信公众号草稿箱。脚本仅依赖 Node.js 内置模块;自动封面生成步骤会复用现有 生图脚本。
bunThis skill is used to publish articles to WeChat Official Account drafts. The script only depends on Node.js built-in modules; the automatic cover generation step reuses the existing image generation script.
bun前置条件
Prerequisites
Node.js >= 16- 若要自动生成封面,还需本机可用
bun - 技能目录下 至少包含:
.env
env
WECHAT_APP_ID=你的公众号AppID
WECHAT_APP_SECRET=你的公众号AppSecret
WECHAT_DEFAULT_THUMB_MEDIA_ID=默认封面图media_id(可选)
WECHAT_DEFAULT_AUTHOR=AI源来如此(可选)- 运行机器公网 IP 已加入公众号后台 IP 白名单
- 自动生成封面时,需保证 的生图环境可用
zhy-article-illustrator
Node.js >= 16- To automatically generate covers, must be available locally
bun - The file in the skill directory must contain at least the following:
.env
env
WECHAT_APP_ID=Your Official Account AppID
WECHAT_APP_SECRET=Your Official Account AppSecret
WECHAT_DEFAULT_THUMB_MEDIA_ID=Default cover image media_id (optional)
WECHAT_DEFAULT_AUTHOR=AI Yuanlai Ruci (optional)- The public IP of the running machine has been added to the IP whitelist in the Official Account backend
- When automatically generating covers, ensure the image generation environment of is available
zhy-article-illustrator
安装说明
Installation Instructions
本 skill 适合与 一起安装到 OpenCode、Claude Code 等支持 的 agent 工具中。
npx skills add ... --skill zhy-wechat-publishSKILL.md安装后请在本地 skill 目录手动创建 ,不要将真实凭据提交回仓库。
.envThis skill is suitable for installation into agent tools that support such as OpenCode and Claude Code using .
SKILL.mdnpx skills add ... --skill zhy-wechat-publishAfter installation, please manually create the file in the local skill directory and do not commit real credentials back to the repository.
.env脚本清单
Script List
脚本位于 :
scripts/| 脚本 | 用途 |
|---|---|
| 上传正文到公众号草稿箱 |
| 上传本地封面图到永久素材库,获取 |
| 读取文章、生成封面、上传封面并推送草稿 |
Scripts are located in :
scripts/| Script | Purpose |
|---|---|
| Upload article content to WeChat Official Account drafts |
| Upload local cover images to the permanent material library to obtain |
| Read articles, generate covers, upload covers, and push drafts |
核心能力
Core Capabilities
- 自动处理正文 CSS 变量兼容
- 自动将正文图片上传到微信正文图片接口并替换 URL
- 自动将 降级为微信公众号编辑态更稳定的段落列表
ul/ol - 支持默认作者、评论开关、仅粉丝评论设置
- 支持从文章内容生成单张公众号封面,并自动上传为
thumb_media_id
- Automatically handle CSS variable compatibility for article content
- Automatically upload article body images to WeChat's body image API and replace URLs
- Automatically downgrade to paragraph lists which are more stable in WeChat Official Account editing mode
ul/ol - Support default author, comment toggle, and comment-only-for-fans settings
- Support generating a single WeChat Official Account cover from article content and automatically uploading it as
thumb_media_id
工作流
Workflow
方式一:已准备好 HTML 与封面 media_id
Method 1: HTML and cover media_id
are ready
media_idbash
node scripts/wechat_draft.js --title "文章标题" --file "post.html" --author "AI源来如此" --thumb "MEDIA_ID" --need-open-comment "1" --only-fans-can-comment "1"参数说明:
| 参数 | 必填 | 说明 |
|---|---|---|
| 是 | 文章标题 |
| 是 | HTML 正文文件路径 |
| 否 | 作者,不传时默认 |
| 否 | 摘要 |
| 否 | 封面 |
| 否 | 原文链接 |
| 否 | 是否开启评论,默认 |
| 否 | 是否仅粉丝可评论,默认 |
bash
node scripts/wechat_draft.js --title "Article Title" --file "post.html" --author "AI Yuanlai Ruci" --thumb "MEDIA_ID" --need-open-comment "1" --only-fans-can-comment "1"Parameter Description:
| Parameter | Required | Description |
|---|---|---|
| Yes | Article title |
| Yes | Path to HTML article file |
| No | Author; if not provided, defaults to |
| No | Article abstract |
| No | Cover |
| No | Original article URL |
| No | Whether to enable comments, default is |
| No | Whether only fans can comment, default is |
方式二:自动生成封面并发布
Method 2: Automatically generate cover and publish
当你已有文章源文件,以及最终用于上传的 HTML 文件时,可直接运行:
bash
node scripts/publish_with_cover.js --article "article.md" --html "post.html" --author "AI源来如此" --source-url "https://example.com"该脚本会自动完成:
- 读取文章内容并提取标题/摘要
- 调用 生成单张 16:9 封面图
zhy-article-illustrator/scripts/image-gen.ts - 调用 上传封面,获得
upload_image.js --jsonthumb_media_id - 调用 推送草稿,并自动带上:
wechat_draft.jsauthorthumb_media_idneed_open_comment=1only_fans_can_comment=1
可选参数:
| 参数 | 说明 |
|---|---|
| 原始文章文件,推荐 Markdown,也可 HTML |
| 最终上传到公众号的 HTML 文件 |
| 显式覆盖标题 |
| 显式覆盖作者 |
| 自定义封面输出路径 |
| 封面宽高比,默认 |
| 原文链接 |
| 是否开启评论,默认 |
| 是否仅粉丝可评论,默认 |
When you have the original article file and the final HTML file for upload, you can directly run:
bash
node scripts/publish_with_cover.js --article "article.md" --html "post.html" --author "AI Yuanlai Ruci" --source-url "https://example.com"This script will automatically complete the following steps:
- Read the article content and extract the title/abstract
- Call to generate a 16:9 cover image
zhy-article-illustrator/scripts/image-gen.ts - Call to upload the cover and obtain
upload_image.js --jsonthumb_media_id - Call to push the draft, automatically including:
wechat_draft.jsauthorthumb_media_idneed_open_comment=1only_fans_can_comment=1
Optional Parameters:
| Parameter | Description |
|---|---|
| Original article file, recommended Markdown, can also be HTML |
| Final HTML file to be uploaded to the Official Account |
| Explicitly override the title |
| Explicitly override the author |
| Custom cover output path |
| Cover aspect ratio, default is |
| Original article URL |
| Whether to enable comments, default is |
| Whether only fans can comment, default is |
正文兼容说明
Content Compatibility Instructions
发布前, 会自动处理:
wechat_draft.js- CSS 变量展开
var(--xxx) - 微信 section 背景样式兼容
- 首个 去除,避免与标题重复
h1 - 正文图片上传到
cgi-bin/media/uploadimg - 原生列表转换为普通段落列表
Before publishing, will automatically handle the following:
wechat_draft.js- Expand CSS variables
var(--xxx) - Compatibility of WeChat section background styles
- Remove the first to avoid duplication with the article title
h1 - Upload body images to
cgi-bin/media/uploadimg - Convert native lists to plain paragraph lists
错误排查
Troubleshooting
- :检查
[40013] invalid appid中.envWECHAT_APP_ID - :将报错 IP 加入微信后台白名单
[40164] invalid ip... not in whitelist - :封面素材无效,重新上传封面图
[40007] invalid media_id - :自动封面生成所需生图配置缺失
缺少 Xiaomi/Gemini/OpenAI API Key - 正文图片不显示:检查原图路径/URL 是否可访问,以及 是否成功
media/uploadimg
- : Check
[40013] invalid appidinWECHAT_APP_ID.env - : Add the reported IP to the whitelist in the WeChat Official Account backend
[40164] invalid ip... not in whitelist - : The cover material is invalid; re-upload the cover image
[40007] invalid media_id - : Missing image generation configuration required for automatic cover generation
Missing Xiaomi/Gemini/OpenAI API Key - Body images not displaying: Check if the original image path/URL is accessible and whether was successful
media/uploadimg
快速示例
Quick Examples
bash
undefinedbash
undefined已有 HTML,直接发草稿
Existing HTML, directly publish to draft
node scripts/wechat_draft.js --title "技术周报" --file "post.html"
node scripts/wechat_draft.js --title "Tech Weekly" --file "post.html"
自动生封面并发布
Automatically generate cover and publish
node scripts/publish_with_cover.js --article "article.md" --html "post.html"
node scripts/publish_with_cover.js --article "article.md" --html "post.html"
上传封面图并把 media_id 回写 .env
Upload cover image and write media_id back to .env
node scripts/upload_image.js "cover.png" --write-env --json
undefinednode scripts/upload_image.js "cover.png" --write-env --json
undefined