Skip to content

Commands Publish

packy edited this page Jun 18, 2026 · 2 revisions

publish — 发布

发布图片消息到公众号草稿箱。支持两种模式:

  • newspic(默认)— 纯文本正文 + 多张图片的图片消息
  • news — Markdown 渲染为图文消息,支持排版主题和代码高亮

用法

# 图片消息(默认)
wx-newspic publish \
  --title "标题" \
  --content "正文内容" \
  --images "./slides/slide-*.png"

# 图文消息
wx-newspic publish \
  --type news \
  --title "标题" \
  --md article.md \
  --theme orangeheart \
  --hl-theme atom-one-dark

# 验证模式(v0.3.0+)
wx-newspic publish \
  --title "测试" \
  --content "正文" \
  --images "./slides/*.png" \
  --dry-run

参数说明

参数 必填 说明
--title, -t 标题,最长 32 字
--content, -c 是/--md 正文内容(newspic 模式必填,news 模式与 --md 二选一)
--md, -m 是/--content Markdown 文件路径(news 模式)
--type, -T 文章类型:newspic(默认)或 news
--images, -i 图片路径列表(newspic 模式必填),支持 glob,最多 20 张,PNG/JPEG/JPG/GIF
--theme 排版主题(news 模式),默认 default
--hl-theme 代码高亮主题(news 模式),如 draculaatom-one-dark
--theme-file, -f 自定义主题 CSS 文件路径(与 --theme 配合使用)
--author, -a 作者,最长 16 字
--digest, -d 摘要,最长 128 字
--server, -s 中转服务器地址
--api-key 中转服务器 API Key
--app-id 微信 APP_ID
--app-secret 微信 APP_SECRET
--dry-run 验证模式:本地处理图片但不调用微信 API,返回 mock 结果。用于测试和 CI(v0.3.0+)

服务器地址和 API Key 也可通过环境变量指定:

export WECHAT_SERVER_URL=https://your-server.com
export WECHAT_API_KEY=sk-your-key

旧名称 WX_NEWSPIC_SERVER / WX_NEWSPIC_API_KEY 仍兼容。

成功输出

{
  "media_id": "MkFrOVhDZ3hCQUFBQVFDQUFBQlFBQUFBTUFRQUFJQUFBQUFCd0FB",
  "created_at": "2026-05-19T10:30:00+08:00",
  "success": true
}

版本历史

版本 变更
v0.1.0 初始版本:newspic 图片消息发布
v0.2.0 新增 --type news 图文消息、--md--theme--hl-theme--theme-file
v0.3.0 新增 --dry-run 验证模式

Clone this wiki locally