Skip to content

Quickstart

packy edited this page Jun 18, 2026 · 1 revision

安装与配置

环境要求

  • Node.js >= 20(查看:node --version
  • npmpnpm

安装

方式一:npm 全局安装(推荐)

npm install -g @packy-tang/wx-newspic

方式二:源码构建

git clone https://github.com/lpreterite/wx-newspic.git
cd wx-newspic
npm install
npm run build
npm link

验证安装:

wx-newspic --version
wx-newspic --help

配置微信凭证

优先级:CLI 参数 > 环境变量 > .env 文件。

方式一:CLI 参数(每次执行时指定)

wx-newspic publish --app-id "wx_xxx" --app-secret "secret_xxx"

方式二:环境变量

export WECHAT_APP_ID=your_app_id
export WECHAT_APP_SECRET=your_app_secret

方式三:持久化配置

wx-newspic credential set --app-id "wx_xxx" --app-secret "secret_xxx"

验证凭证:

wx-newspic credential check

发布第一条消息

图片消息(小绿书)

wx-newspic publish \
  --title "今日推荐" \
  --content "正文内容" \
  --images ./photos/*.png

图文消息(Markdown 渲染)

wx-newspic publish \
  --type news \
  --title "标题" \
  --md article.md \
  --theme orangeheart

成功返回:

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

Clone this wiki locally