jianshuo/claude-skills / wjs-publishing-wechat
wjs-publishing-wechat
Unverified当用户想写或发布微信公众号文章时使用——他们给出零散思路、草稿或笔记,请你润色、生成题图和解释图,或准备上传到 mp.weixin.qq.com。触发词:"写一篇微信文章"、"公众号"、"润色"、"题图"、"发公众号"、"/wjs-publishing-wechat"。
| File | Kind | Size |
|---|---|---|
| .gitignore | other | 65 B |
| .publish-manifest.json | config | 13.2 KB |
| LICENSE | other | 1.0 KB |
| README.md | markdown | 4.7 KB |
| SKILL.md | skill md | 14.2 KB |
| STYLE.md | markdown | 10.8 KB |
| prompts/cover-prompt.md | markdown | 20.6 KB |
| prompts/illustration-prompt.md | markdown | 2.8 KB |
| scripts/backfill-permalinks.pyexecutable | script | 9.3 KB |
| scripts/build-recent-articles.pyexecutable | script | 5.5 KB |
| scripts/fetch-comments-by-cookie.shexecutable | script | 12.2 KB |
| scripts/fetch-comments-via-gstack.shexecutable | script | 10.8 KB |
| scripts/fetch-comments.shexecutable | script | 5.4 KB |
| scripts/gen-cover-ai.shexecutable | script | 3.8 KB |
| scripts/gen-illustration.shexecutable | script | 3.0 KB |
| scripts/mass-send.shexecutable | script | 7.2 KB |
| scripts/open-draft-edit.shexecutable | script | 5.3 KB |
| scripts/pangu.py | script | 2.9 KB |
| scripts/update-draft-via-api.pyexecutable | script | 3.9 KB |
| scripts/upload-draft.shexecutable | script | 19.4 KB |
scripts/mass-send.sh
View on GitHub#!/usr/bin/env bash
# Mass-send an already-created WeChat draft to all subscribers (or preview
# to a single OpenID first). On success, also enables comments on the article
# and persists msg_id / msg_data_id to publish.json so fetch-comments.sh can
# pull留言 later.
#
# WHY this is a separate command (not folded into upload-draft.sh):
# - 订阅号 has only 1 mass-send slot per day. An accidental auto-trigger
# burns the day's quota.
# - Mass-send bypasses the human "草稿箱 → 后台预览 → 改一下措辞" gate.
# That final human check has caught typos in the past — keeping it.
#
# Usage:
# mass-send.sh <article-folder> --preview <openid> # send to ONE person (yourself), 0 quota cost
# mass-send.sh <article-folder> --preview <wxname> # OR a WeChat ID (e.g. "jianshuo")
# mass-send.sh <article-folder> --send # real broadcast to all subscribers
#
# --preview target auto-detection:
# - Looks like an OpenID (28 chars, starts with 'o', alphanumeric) → uses `touser` field
# - Otherwise treated as a WeChat ID (微信号) → uses `towxname` field
# - Preview quota is 100/day per account (separate from the 1/day mass-send quota)
#
# Run --preview first. Inspect the message in your WeChat. If happy, run --send.
#
# Prerequisites:
# - WECHAT_APPID + WECHAT_SECRET in env (same as upload-draft.sh)
# - <article-folder>/publish.json exists with draft_media_id (written by upload-draft.sh)
# - 公众号 is "已认证" (个人认证 or 企业认证) — unauthenticated 个人订阅号 gets errcode=48001
set -euo pipefail
ARTICLE_DIR="${1:-}"
MODE="${2:-}"
TARGET="${3:-}"
usage() {
cat <<'EOF' >&2
usage:
mass-send.sh <article-folder> --preview <openid-or-wxname>
mass-send.sh <article-folder> --send
--preview: mass/preview to one user (typically yourself). Argument is auto-detected:
28-char string starting with 'o' → OpenID (touser)
anything else → WeChat ID 微信号 (towxname)
100/day preview quota; does NOT consume mass-send quota.
--send: mass/sendall to all subscribers. Burns today's 1 mass-send slot.
EOF
exit 1
}
[[ -d "$ARTICLE_DIR" ]] || usage
ARTICLE_DIR="$(cd "$ARTICLE_DIR" && pwd)"
case "$MODE" in
--preview) [[ -n "$TARGET" ]] || usage ;;
--send) ;;
*) usage ;;
esac
PUB="$ARTICLE_DIR/publish.json"
[[ -f "$PUB" ]] || { echo "error: $PUB missing (did you run upload-draft.sh?)" >&2; exit 1; }
: "${WECHAT_APPID:?WECHAT_APPID env var not set}"
: "${WECHAT_SECRET:?WECHAT_SECRET env var not set}"
# Get fresh access_token, then mass-send, then comment/open, then persist.
# All API I/O lives in one python block so errors surface cleanly.
WECHAT_APPID="$WECHAT_APPID" WECHAT_SECRET="$WECHAT_SECRET" \
ARTICLE_DIR="$ARTICLE_DIR" MODE="$MODE" TARGET="$TARGET" \
python3 <<'PYEOF'
import os, json, sys, urllib.request, urllib.parse, time
APPID = os.environ['WECHAT_APPID']
SECRET = os.environ['WECHAT_SECRET']
DIR = os.environ['ARTICLE_DIR']
MODE = os.environ['MODE']
TARGET = os.environ['TARGET']
PUB = os.path.join(DIR, 'publish.json')
pub = json.load(open(PUB))
media_id = pub.get('draft_media_id')
if not media_id:
sys.exit('error: publish.json has no draft_media_id')
def api(method, path, body=None):
url = f'https://api.weixin.qq.com/cgi-bin/{path}'
data = json.dumps(body, ensure_ascii=False).encode('utf-8') if body is not None else None
req = urllib.request.Request(url, data=data, method=method,
headers={'Content-Type': 'application/json'})
with urllib.request.urlopen(req, timeout=30) as r:
return json.loads(r.read().decode('utf-8'))
print('→ fetching access_token ...', file=sys.stderr)
tok = api('GET', f'token?grant_type=client_credential&appid={APPID}&secret={SECRET}')
if 'access_token' not in tok:
sys.exit(f'token error: {tok}')
TOKEN = tok['access_token']
if MODE == '--preview':
# Auto-detect: OpenID is 28 chars, starts with 'o', alphanumeric+_-.
# Anything else is a WeChat ID (微信号) → towxname field.
import re
is_openid = bool(re.fullmatch(r'o[A-Za-z0-9_-]{27}', TARGET))
field = 'touser' if is_openid else 'towxname'
label = 'OpenID' if is_openid else '微信号 (wxname)'
print(f'→ mass/preview to {label}={TARGET} ...', file=sys.stderr)
body = {field: TARGET, 'mpnews': {'media_id': media_id}, 'msgtype': 'mpnews'}
r = api('POST', f'message/mass/preview?access_token={TOKEN}', body)
else: # --send
print('→ mass/sendall to ALL subscribers (burning today\'s 1 quota) ...', file=sys.stderr)
body = {'filter': {'is_to_all': True},
'mpnews': {'media_id': media_id},
'msgtype': 'mpnews',
'send_ignore_reprint': 0}
r = api('POST', f'message/mass/sendall?access_token={TOKEN}', body)
if r.get('errcode', 0) != 0:
hint = ''
if r.get('errcode') == 48001:
hint = ('\n hint: 48001 = api unauthorized — but it\'s probably NOT what you think.'
'\n 自 2025-07 起,微信回收了「个人主体」账号的「发布能力 API」权限。'
'\n 即使你公众号有黄色 V(个人认证),mass/preview + mass/sendall 都返回 48001。'
'\n 只有「企业主体认证」的服务号/订阅号才有这个 API 权限。'
'\n fallback:用 fetch-comments-by-cookie.sh + 浏览器抓包 cookie 拉留言(不依赖 API)'
'\n 或者 mp.weixin.qq.com 后台 → 留言管理 → 人肉看 / 导出')
elif r.get('errcode') == 45028:
hint = '\n hint: 45028 = today\'s mass-send quota exhausted (订阅号 1/day, 服务号 4/month)'
sys.exit(f'mass send failed: {r}{hint}')
msg_id = r.get('msg_id')
msg_data_id = r.get('msg_data_id')
print(f' ✓ mass send OK: msg_id={msg_id} msg_data_id={msg_data_id}', file=sys.stderr)
# Open comments on this article. Idempotent in practice — failures here are
# not fatal because comments may already be on, but we surface the result.
if msg_data_id:
print('→ comment/open ...', file=sys.stderr)
open_r = api('POST', f'comment/open?access_token={TOKEN}',
{'msg_data_id': int(msg_data_id), 'index': 0})
if open_r.get('errcode', 0) == 0:
print(' ✓ comments enabled', file=sys.stderr)
else:
print(f' ⚠ comment/open returned {open_r} (may already be open — ignoring)', file=sys.stderr)
# Persist back to publish.json. Preserve any prior fields.
import datetime
now = datetime.datetime.utcnow().strftime('%Y-%m-%dT%H:%M:%SZ')
if MODE == '--preview':
pub['preview_sent_at'] = now
pub['preview_to'] = TARGET
pub['preview_msg_id'] = msg_id
else:
pub['mass_sent_at'] = now
pub['msg_id'] = msg_id
pub['msg_data_id'] = msg_data_id
pub['comments_open'] = True
open(PUB, 'w').write(json.dumps(pub, ensure_ascii=False, indent=2))
print(f' (publish.json updated)', file=sys.stderr)
if MODE == '--send':
print('\n下一步:', file=sys.stderr)
print(' - 等几分钟让粉丝看到 + 开始留言', file=sys.stderr)
print(f' - 然后 fetch-comments.sh "{DIR}" 把所有留言拉成 comments.md', file=sys.stderr)
PYEOF
Related skills
| Skill | Stars | Updated | Works with | Status | Install |
|---|---|---|---|---|---|
| slack-gif-creatoranthropics/skillsKnowledge and utilities for creating animated GIFs optimized for Slack. Provides constraints, validation tools, and animation concepts. Use when users request animated GIFs for Slack like "make me a GIF of X doing Y for Slack." | Stars: 198k | Updated | Claude CodeCodex | Verified | Install |
| ponytailDietrichGebert/ponytailLazy senior dev mode for any coding task: the smallest change that fully solves it, and a reply a busy human understands in one read. | Stars: 194k | Updated | Claude CodeCodex | Verified | Install |
| ponytail-debtDietrichGebert/ponytailHarvest every shortcut: comment into one debt ledger, so deferrals get tracked instead of forgotten. One-shot report. | Stars: 194k | Updated | Claude CodeCodex | Verified | Install |
| ponytail-debtDietrichGebert/ponytailList every `shortcut:` comment (and older `ponytail:` ones) as a debt ledger. One-shot report, changes nothing. Use for "ponytail debt", "what did ponytail defer", "list the shortcuts", /ponytail-debt. | Stars: 194k | Updated | Claude CodeCodex | Verified | Install |