canghe-post-to-wechat
Posts content to WeChat Official Account (微信公众号) via API or Chrome CDP. Supports article posting (文章) with HTML, markdown, or plain text input, and image-text posting (贴图, formerly 图文) with multiple images. Use when user mentions "发布公众号", "post to wechat", "微信公众号", or "贴图/图文/文章".
1How It Works & Mechanism
Dual-channel publishing: either via the WeChat Official Account Platform API (wechat-api.ts, draft interface) or via browser CDP (wechat-article.ts / wechat-browser.ts driving real Chrome).
Posts content to WeChat Official Account (微信公众号) via API or Chrome CDP.
The workflow is a checklist-based Step 0-7, and initial setup is defined as a blocking action: no other steps or questions are permitted until EXTEND.md is ready.
**BLOCKING OPERATION**: This setup MUST complete before ANY other workflow steps.
Credentials for the API path come from .env: WECHAT_APP_ID / WECHAT_APP_SECRET, with a 3-tier priority of environment variables → project .canghe-skills/.env → user ~/.canghe-skills/.env.
test -f .canghe-skills/.env && grep -q "WECHAT_APP_ID" .canghe-skills/.env && echo "project"
Draft request body rules are hardcoded: POST draft/add, article_type set to news/newspic, news requires thumb_media_id, and explicitly carries comment toggle fields.
- Use endpoint: `POST https://api.weixin.qq.com/cgi-bin/draft/add?access_token=ACCESS_TOKEN`
The browser path uses real Chrome + CDP, disabling automation flags with --disable-blink-features=AutomationControlled.
'--disable-blink-features=AutomationControlled',
Sticker/image-text pastes images into the editor: markdown images are first replaced with WECHATIMGPH_n placeholders, and after pasting HTML, placeholders are located one by one, deleted, and replaced by pasting the image.
3. **Paste**: HTML content is pasted into WeChat editor
Clipboard writing relies on inline Swift/AppKit: the script writes a snippet of Swift source code to a temporary file, then compiles and executes it to support image/rich text clipboards.
await writeFile(swiftPath, getMacSwiftClipboardSource(), 'utf8');
markdown→HTML conversion is delegated to canghe-markdown-to-html, sharing command and theme options.
npx -y bun ${MD_TO_HTML_SKILL_DIR}/scripts/main.ts <markdown_file> --theme <theme>
The preflight script checks Chrome, profile isolation, Bun, accessibility permissions, clipboard, paste keystrokes, API credentials, and Chrome conflicts.
Checks: Chrome, profile isolation, Bun, Accessibility, clipboard, paste keystroke, API credentials, Chrome conflicts.
2Core Capabilities
3External Dependencies
| Kind | Dependency / Endpoint |
|---|---|
| api | 微信公众平台草稿接口(draft/add) |
| network | 微信公众平台(凭证申请/草稿管理页) |
| cli | bun(经 npx -y 即时拉取) |
| cli | Google Chrome(CDP)+ osascript / xdotool / ydotool(真实键击贴图) |
4Recommended Governance & Evidence
- SKILL.md / 脚本参数: Bypasses automation detection, disables host sandboxing, or skips SSL certificate verification
- SKILL.md / 会话存储: Reads or reuses browser user login states and session cookies
- 本地凭据 / 浏览器配置: Reads user login cookies/sessions/keyrings: Browser path reuses the Official Account login state from the shared Chrome profile (session cookies reside in the profile)
- scripts/: Executes local scripts or commands: npx -y bun ${SKILL_DIR}/scripts/wechat-api.ts / wechat-article.ts / wechat-
- 网络端点: Declares external network access: WeChat draft interface POST https://api.weixin.qq.com/cgi-bin/draft/add?access_token=ACCESS
- 本地工作目录: File read/write and artifact output: Creates post-to-wechat/yyyy-MM-dd/[slug].md on plain text input (mkdir -p + file write)
5Second-Pass Verification
- [ok] 双通道实现原理 — SKILL.md 描述、脚本清单与 Step 5/6 命令三处互证 api 与 browser 两条路径。
- [ok] 反自动化绕过 — 风险扫描在 cdp.ts:220 与 wechat-browser.ts:345 各定位一条 --disable-blink-features=AutomationControlled,判红据成立。
- [ok] 凭证读取 — SKILL.md 的 .env 探测命令、凭证引导流程与 Config File Locations 三级优先级一致。
- [ok] 微信 API 端点与报文规则 — draft/add 端点在 SKILL.md Step 6 与 Feature Comparison 中一致出现,含 thumb_media_id 与评论字段规则。
- [ok] 贴图占位符机制 — article-posting.md 的 Parse/Render/Paste/Replace 四步与 image-text-posting.md 说明自洽。
- [unlocatable] 主脚本正文细节 — wechat-api.ts / wechat-article.ts / wechat-browser.ts 全文未在 bundle 展开,取 token、DOM 操作等细节以 SKILL.md 与扫描行为据,未代码级复核。
- [ok] 跨 skill 依赖 canghe-markdown-to-html — SKILL.md Step 2/3 明写发现与调用,属他人 skill 行为,不参与本 skill 判级。
- [ok] 插件/镜像等供应链线索 — 除 npx -y bun 即时拉取与自带 md 子集外,未在 bundle 内发现第三方镜像或远程包注入。
6Verdict & Scenarios
1efd21eef0ed6ee4…