Skills wechat-public-cli
Publish and download WeChat Public Platform content and Baijiahao articles via a local CLI.
install
source · Clone the upstream repo
git clone https://github.com/openclaw/skills
manifest:
skills/ai-chen2050/wechat-public-cli/skill.mdsource content
Wechat Public CLI Skill
Goal
Publish an Obsidian markdown article to WeChat Public Platform or Baidu Baijiahao using a local CLI.
Requirements
- Node.js 16+
- Config file or environment variables for credentials
- Markdown file with frontmatter (author, digest, banner or banner_path, thumb_media_id optional)
Article Template
title: "Test" author: Blake digest: Short summary banner: "https://image.png"
Install
git clone https://github.com/ai-chen2050/obsidian-wechat-public-platform.git cd obsidian-wechat-public-platform npm install Or by clawdhub claw install wechat-public-cli
Or install globally via npm:
npm install -g wechat-public-cli
If this CLI is published to npm, you can run it via npx without cloning:
npx wechat-public-cli wechat:draft --file /path/to/article.md
Config
Create a JSON file in the repo root named
wechat-public.config.json:
{ "wechat": { "appid": "YOUR_APP_ID", "secret": "YOUR_APP_SECRET", "accessToken": "" }, "baidu": { "cookie": "YOUR_BJH_COOKIE", "token": "YOUR_BJH_TOKEN", "appId": "YOUR_BJH_APP_ID" }, "paths": { "customCss": "./custom.css", "downloadDir": "./wechat-downloads" } }
Env override:
,WECHAT_APPID
,WECHAT_SECRETWECHAT_ACCESS_TOKEN
,BJH_COOKIE
,BJH_TOKENBJH_APP_ID
,WECHAT_CUSTOM_CSSWECHAT_PUBLIC_CONFIGWECHAT_DOWNLOAD_DIR
Build
npm run build:cli
Commands
- Create WeChat draft:
wechat-public-cli wechat:draft --file /path/to/article.md # 使用自定义 CSS wechat-public-cli wechat:draft --file /path/to/article.md --css /path/to/tech.css - Publish WeChat (from file):
wechat-public-cli wechat:publish --file /path/to/article.md # 使用自定义 CSS wechat-public-cli wechat:publish --file /path/to/article.md --css /path/to/business.css - Publish WeChat (from media_id):
wechat-public-cli wechat:publish --media-id YOUR_MEDIA_ID - Send to all WeChat followers:
wechat-public-cli wechat:sendall --file /path/to/article.md - Publish Baijiahao:
wechat-public-cli bjh:publish --file /path/to/article.md # 使用自定义 CSS wechat-public-cli bjh:publish --file /path/to/article.md --css /path/to/custom.css - Convert markdown to HTML:
wechat-public-cli convert --file /path/to/article.md --platform wechat # 使用自定义 CSS wechat-public-cli convert --file /path/to/article.md --platform wechat --css /path/to/style.css - Download recent N WeChat articles:
wechat-public-cli wechat:download --count 10 --out-dir ./wechat-downloads - Get cumulative user statistics:
# 查询最近7天(默认) wechat-public-cli wechat:stats:cumulate # 指定日期范围(最多30天) wechat-public-cli wechat:stats:cumulate --begin-date 2025-11-01 --end-date 2025-11-07 - Get published content overview statistics:
# 查询最近7天(默认) wechat-public-cli wechat:stats:bizsummary # 指定日期范围(最多30天) wechat-public-cli wechat:stats:bizsummary --begin-date 2025-11-01 --end-date 2025-11-07
使用自定义 CSS 样式
所有发布命令都支持通过
--css 参数指定自定义样式文件:
# 使用技术类文章样式 wechat-public-cli wechat:draft --file tech-article.md --css ./styles/tech.css # 使用营销类文章样式 wechat-public-cli wechat:publish --file marketing.md --css ./styles/marketing.css # 使用教程类文章样式 wechat-public-cli bjh:publish --file tutorial.md --css ./styles/tutorial.css
自定义公众号格式
你可以通过定义和修改 CSS 文件,来调整发布到微信公众号的文章样式。支持为不同类型的文章使用不同的样式文件。
CSS 文件加载优先级
- 命令行参数
(最高优先级)--css - 配置文件
中的wechat-public.config.jsonpaths.customCss - 默认文件 当前目录下的
custom.css - 空样式 如果以上都不存在,则不应用自定义样式
使用场景示例
1. 使用默认样式
在项目根目录创建
custom.css,不传任何参数时自动使用:
wechat-public-cli wechat:publish --file article.md
2. 为不同类型文章使用不同样式
创建多个 CSS 文件,通过
--css 参数指定:
# 技术类文章使用 tech.css wechat-public-cli wechat:publish --file tech-article.md --css ./styles/tech.css # 商业类文章使用 business.css wechat-public-cli wechat:publish --file business-article.md --css ./styles/business.css # 教程类文章使用 tutorial.css wechat-public-cli wechat:publish --file tutorial.md --css ./styles/tutorial.css
3. 在配置文件中指定默认样式
在
wechat-public.config.json 的 paths.customCss 字段指定默认样式文件路径:
{ "paths": { "customCss": "./styles/default.css" } }
这样不传
--css 参数时,会使用配置文件中指定的样式。
CSS 示例
/* tech.css - 技术文章样式 */ .wechat-title { font-size: 2em; color: #2c3e50; font-family: "Monaco", "Consolas", monospace; } .wechat-banner { border-radius: 8px; } code { background-color: #f4f4f4; padding: 2px 4px; } /* business.css - 商业文章样式 */ .wechat-title { font-size: 2.2em; color: #c7254e; font-family: "Arial", "Helvetica", sans-serif; }
AI 也可通过自动生成或修改 CSS 文件,实现对公众号内容格式的智能优化。
Notes
- WeChat draft requires
orthumb_media_id
/banner
in frontmatter.banner_path - Baijiahao publish requires
orbanner
in frontmatter.banner_path - The CLI uploads inline images to the target platform automatically.
saves recent articles in update_time order and writes allwechat:download
entries.news_item
/wechat:stats:cumulate
must be called server-side; the date range can be at most 30 days. Results are printed as JSON to stdout.wechat:stats:bizsummary