WeChat MP Draft Publisher
Publish draft articles by calling the bundled wrapper script, which enforces this fixed sequence:
getAuthuploadArticleImageuploadCoverImageaddDraft
Requirements
- Provide executable via one of:
- Local binary path:
- CLI flag
--bin /absolute/path/to/mp-weixin-skill - Env var
MP_WECHAT_CLI_BIN
- CLI flag
- GitHub Release auto-download:
- Env var
MP_WECHAT_RELEASE_URL=https://github.com/<owner>/<repo>/releases/download/<tag>/<asset>(direct asset URL, supports zip or binary) - or:
- Env var
MP_WECHAT_GITHUB_REPO=owner/repo - Optional env
MP_WECHAT_RELEASE_TAG=latest(default latest) - Optional env
MP_WECHAT_ASSET_NAME=custom-asset-name
- Env var
- Local binary path:
- Ensure local credentials file exists for
getAuth:~/.weixin_credentials- format:
appid=YOUR_APP_IDsecret=YOUR_APP_SECRET
- Prepare these files before running:
- Article content file (
--content-file), usually HTML - Inline article image (
--article-image) - Cover image (
--cover-image)
- Article content file (
Run
Use the wrapper script:
bash scripts/publish_draft.sh \
--article-image /absolute/path/to/article-image.png \
--cover-image /absolute/path/to/cover-image.png \
--content-file /absolute/path/to/content.html \
--title "Article Title" \
--author "Author Name" \
--digest "Optional digest"
GitHub Release mode (auto-download executable):
export MP_WECHAT_GITHUB_REPO="owner/repo"
export MP_WECHAT_RELEASE_TAG="latest"
bash scripts/publish_draft.sh \
--cover-image /absolute/path/to/cover-image.png \
--content-file /absolute/path/to/content.html \
--title "Article Title"
Direct URL mode:
export MP_WECHAT_RELEASE_URL="https://github.com/Mesus/weixin-mp-skill/releases/download/v0.0.1/mp-weixin-skill.zip"
bash scripts/publish_draft.sh \
--cover-image /absolute/path/to/cover-image.png \
--content-file /absolute/path/to/content.html \
--title "Article Title"
If uploadCoverImage response does not include usable media_id, pass it explicitly:
bash scripts/publish_draft.sh \
--bin /absolute/path/to/mp-weixin-skill \
--article-image /absolute/path/to/article-image.png \
--cover-image /absolute/path/to/cover-image.png \
--content-file /absolute/path/to/content.html \
--title "Article Title" \
--thumb-media-id "YOUR_MEDIA_ID"
Output Contract
Script prints one JSON object on stdout:
access_token: token returned bygetAutharticle_image_url: URL returned byuploadArticleImagecover_upload: raw JSON object returned byuploadCoverImagethumb_media_id_used: value passed toaddDraftdraft: raw JSON object returned byaddDraft
On failure, script prints JSON error to stderr and exits non-zero.
Resource
- CLI wrapper implementation details:
references/cli-contract.md