← Back to Skills Marketplace
864446285

wechat-md-publish

by asdassad · GitHub ↗ · v0.3.0 · MIT-0
cross-platform ⚠ suspicious
56
Downloads
0
Stars
0
Active Installs
1
Versions
Install in OpenClaw
/install wechat-md-publish
Description
将 Markdown 文章发布到微信公众号。支持 AI 生成封面图片、HTML 卡片渲染、创建草稿、可选自动发布。当用户说'发公众号'、'发布文章到微信'、'公众号发布'时使用此技能。
README (SKILL.md)

微信公众号文章发布

将 Markdown 文章发布到微信公众号,支持 AI 生成封面图片。


首次配置

1. 获取公众号 AppID 和 AppSecret

微信公众平台 → 开发 → 基本配置 中获取。

2. 设置 IP 白名单

在基本配置页面,将你的出口 IP 加入白名单。查看出口 IP:

curl -s https://ipinfo.io/ip

3. 创建配置文件

mkdir -p ~/.wechat_publish
cat > ~/.wechat_publish/config.json \x3C\x3C 'EOF'
{
  "app_id": "你的AppID",
  "app_secret": "你的AppSecret"
}
EOF

4. 安装依赖

pip install requests markdown

如需使用 HTML 卡片渲染功能,额外安装:

pip install playwright
playwright install chromium

工作流程

当用户要求发布文章时,按以下步骤执行:

步骤 1:AI 总结摘要

阅读文章内容,用 AI 总结一段摘要,不超过 120 字节(中文约 40 字)。

步骤 2:判断封面来源

如果用户已提供封面图片 → 直接使用,跳到步骤 4。

如果用户未提供封面图片 → 进入步骤 3 用 AI 生成。

步骤 3:用 ImageGen 生成封面图片(仅当用户未提供封面时)

根据文章标题和内容,调用 ImageGen 工具生成封面。提示词参考:

微信公众号封面图,风格简约专业,比例 16:9,主题:{文章标题关键词},不要出现文字

更多提示词模板见下方"AI 封面生成提示词建议"。

步骤 4:(可选)生成 HTML 卡片

如果文章需要插入排版精美的信息卡片(对比图、步骤说明、工具栈展示等),由 AI 生成 HTML 模板,脚本自动渲染为图片插入文章。

微信公众号对 HTML/CSS 支持有限,有些排版效果无法用内联样式实现。HTML 卡片通过 Playwright 将 HTML 渲染为图片,绕过这个限制。

常见卡片类型和 HTML 模板:

对比卡片

\x3C!DOCTYPE html>
\x3Chtml>\x3Chead>\x3Cmeta charset="UTF-8">
\x3Cstyle>
*{margin:0;padding:0;box-sizing:border-box}
body{font-family:system-ui,-apple-system,sans-serif;background:#f5f5f7;padding:30px 20px}
.title{font-size:22px;font-weight:bold;color:#1a1a1a;margin-bottom:20px;text-align:center}
.section{margin-bottom:16px;padding:12px 16px;border-radius:8px}
.green{background:#e8f5e9;border-left:4px solid #4CAF50}
.red{background:#fce4ec;border-left:4px solid #f44336}
.section-title{font-size:15px;font-weight:bold;margin-bottom:8px}
.item{font-size:14px;color:#333;margin-bottom:4px;line-height:1.6}
\x3C/style>\x3C/head>\x3Cbody>
\x3Cdiv class="title">标题\x3C/div>
\x3Cdiv class="section green">\x3Cdiv class="section-title">✅ 能做的\x3C/div>\x3Cdiv class="item">• 内容1\x3C/div>\x3C/div>
\x3Cdiv class="section red">\x3Cdiv class="section-title">❌ 不能做的\x3C/div>\x3Cdiv class="item">• 内容1\x3C/div>\x3C/div>
\x3C/body>\x3C/html>

保存为 .html 文件后通过 --html-card 参数传入。可同时传入多个卡片文件。

步骤 5:运行发布脚本

# 仅创建草稿
python scripts/wx_publish.py --title "文章标题" --content article.md --digest "AI总结的摘要" --thumb-image \x3C封面图片路径>

# 带 HTML 卡片
python scripts/wx_publish.py --title "文章标题" --content article.md --digest "AI总结的摘要" --thumb-image \x3C封面图片路径> --html-card card.html

# 多个 HTML 卡片
python scripts/wx_publish.py --title "文章标题" --content article.md --digest "AI总结的摘要" --thumb-image \x3C封面图片路径> --html-card card1.html card2.html

# 创建草稿并自动发布
python scripts/wx_publish.py --title "文章标题" --content article.md --digest "AI总结的摘要" --thumb-image \x3C封面图片路径> --publish

如果用户提供了封面素材 ID 而非图片文件:

python scripts/wx_publish.py --title "文章标题" --content article.md --thumb-media-id \x3C素材ID>

完整参数说明

参数 必填 说明
--title 文章标题
--content Markdown 文件路径
--thumb-image 封面图片本地路径(AI 生成或用户提供的封面都用此参数)
--thumb-media-id 已上传的封面素材 ID
--html-card HTML 卡片文件路径(可多个),渲染为图片插入文章
--card-width HTML 卡片渲染宽度(默认 750px)
--author 作者名
--digest 文章摘要(由 AI 总结,不超过 120 字节/约 40 字)
--upload-thumb 仅上传封面图片,输出 thumb_media_id
--publish 创建草稿后自动发布

封面优先级:--thumb-media-id > --thumb-image。均未指定时会提示提供。


AI 封面生成提示词建议

根据文章类型选择合适的提示词:

文章类型 提示词模板
技术教程 微信公众号封面,科技感,深蓝配色,简洁图标,无文字
财经分析 微信公众号封面,金融主题,数据图表元素,蓝金配色,无文字
生活分享 微信公众号封面,清新风格,柔和配色,简约图形,无文字
量化交易 微信公众号封面,K线图表元素,深色背景,科技金融感,无文字

常见问题

问题 解决方案
获取 access_token 失败 检查 AppID/AppSecret 是否正确,IP 白名单是否已设置
上传封面失败 封面图片需小于 10MB,支持 bmp/png/jpeg/jpg/gif 格式
草稿创建失败 确认公众号已认证,具有草稿接口权限
markdown 模块未找到 运行 pip install markdown

注意事项

  • 本工具仅适用于已认证的微信公众号(订阅号/服务号均可)
  • access_token 有效期 2 小时,脚本自动缓存和刷新
  • 文章中的本地图片会自动上传到微信并替换 URL
  • 建议先创建草稿确认效果,再加 --publish 自动发布
  • 用户已提供封面图片时,不要再用 ImageGen 生成
Usage Guidance
Before installing or using this skill, make sure you are comfortable giving it WeChat Official Account API credentials and uploading the selected Markdown article and referenced images to WeChat. Prefer creating a draft first, review the rendered result in WeChat, and only use automatic publishing after explicit confirmation. Use a virtual environment for the Python dependencies and protect ~/.wechat_publish/config.json and the token cache.
Capability Analysis
Type: OpenClaw Skill Name: wechat-md-publish Version: 0.3.0 The skill provides a utility for publishing Markdown articles to WeChat, but the script `scripts/wx_publish.py` contains a potential Local File Inclusion (LFI) vulnerability. Specifically, the `process_local_images` function parses image tags from Markdown and uploads the referenced local files to WeChat's servers (`api.weixin.qq.com`) without path sanitization, which could be exploited to exfiltrate sensitive system files. While this functionality is aligned with the stated purpose of handling local assets, the lack of validation for file paths makes it a high-risk capability in an agentic environment.
Capability Assessment
Purpose & Capability
The requested capabilities—reading Markdown, uploading images, creating WeChat drafts, and optionally publishing—match the stated purpose, but they affect a real WeChat Official Account.
Instruction Scope
The skill defaults to draft creation and documents --publish as optional, but users should ensure public publishing only happens after explicit approval and review.
Install Mechanism
There is no install spec, while SKILL.md asks the user to install unpinned Python packages and optionally a Playwright Chromium browser; this is user-directed and purpose-aligned.
Credentials
The skill uses local files, a local credential config, network calls to WeChat, and optional browser rendering; these are proportionate to publishing but handle sensitive account/content data.
Persistence & Privilege
The script persists WeChat configuration and an access-token cache under ~/.wechat_publish, but there is no evidence of background agents, self-propagation, or hidden persistence.
How to Use
  1. Make sure OpenClaw is installed (local or Docker)
  2. Run the install command in chat: /install wechat-md-publish
  3. After installation, invoke the skill by name or use /wechat-md-publish
  4. Provide required inputs per the skill's parameter spec and get structured output
Version History
v0.3.0
wechat-md-publish v0.3.0 - 支持将 Markdown 文章发布到微信公众号,包括 AI 自动生成封面图片、摘要。 - HTML 卡片支持:可通过 Playwright 渲染自定义 HTML 卡片为图片插入文章,提升排版效果。 - 实现草稿创建和可选的自动发布功能。 - 添加详细的首次配置说明和常见问题解答。 - 明确参数说明和 AI 封面生成提示词建议。
Metadata
Slug wechat-md-publish
Version 0.3.0
License MIT-0
All-time Installs 0
Active Installs 0
Total Versions 1
Frequently Asked Questions

What is wechat-md-publish?

将 Markdown 文章发布到微信公众号。支持 AI 生成封面图片、HTML 卡片渲染、创建草稿、可选自动发布。当用户说'发公众号'、'发布文章到微信'、'公众号发布'时使用此技能。 It is an AI Agent Skill for Claude Code / OpenClaw, with 56 downloads so far.

How do I install wechat-md-publish?

Run "/install wechat-md-publish" in the OpenClaw or Claude Code chat to install it in one step — no extra setup required.

Is wechat-md-publish free?

Yes, wechat-md-publish is completely free, licensed under MIT-0. You can download, install and use it at no cost.

Which platforms does wechat-md-publish support?

wechat-md-publish is cross-platform and runs anywhere OpenClaw / Claude Code is available (cross-platform).

Who created wechat-md-publish?

It is built and maintained by asdassad (@864446285); the current version is v0.3.0.

💬 Comments