← Back to Skills Marketplace
chenyd002025

微信公众号文章发布技能

by chenyd002025 · GitHub ↗ · v1.0.6 · MIT-0
cross-platform ⚠ suspicious
389
Downloads
0
Stars
2
Active Installs
7
Versions
Install in OpenClaw
/install jvs-wechat-article-publisher
Description
微信公众号文章排版和发布技能。提供专业排版模板、图片上传、草稿发布等完整工作流。使用场景:(1) 创建公众号文章,(2) 上传图片到素材库,(3) 发布草稿到微信后台,(4) 装修案例/干货分享/客户故事等类型文章。
README (SKILL.md)

WeChat Article Publisher

微信公众号文章排版和发布技能。


📋 使用前准备(首次使用必读!)

1. 微信公众号要求

  • ✅ 需要已注册的微信公众号(服务号或订阅号均可)
  • ✅ 需要公众号的 AppIDAppSecret
  • ⚠️ 公众号需要通过微信认证(未认证账号部分 API 受限)

2. 获取 AppID 和 AppSecret

  1. 登录 微信公众平台
  2. 进入 开发 → 基本配置
  3. 复制 开发者 ID 中的:
    • AppID(应用 ID) - 类似 你的 APPID
    • AppSecret(应用密钥) - 类似 你的 APPSECRET

3. 配置 IP 白名单(重要!)

微信 API 要求配置服务器 IP 白名单:

  1. 开发 → 基本配置 页面
  2. 找到 IP 白名单 设置
  3. 添加你的服务器公网 IP:
    • 本地测试:查询本机公网 IP(访问 https://ip.sb
    • 服务器:填写服务器的公网 IP 地址
    • 可添加多个 IP,用逗号分隔

常见 IP 白名单配置:

{
  "ipWhitelist": ["你的公网 IP", "你的服务器 IP 2", "你的服务器 IP 1"]
}

4. 创建配置文件

在技能目录创建 config.json

{
  "appId": "你的 AppID",
  "appSecret": "你的 AppSecret",
  "ipWhitelist": ["你的公网 IP"]
}

⚠️ 安全提醒

  • config.json 包含敏感信息,不要上传到 ClawHub
  • 只保留 config.example.json 作为示例
  • 真实配置文件应加入 .gitignore

5. 验证配置

运行测试命令验证配置是否正确:

# 获取 token(成功会返回一串字符)
curl -s "https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=你的 APPID&secret=你的 APPSECRET"

成功响应:

{"access_token":"ACCESS_TOKEN","expires_in":7200}

失败响应:

{"errcode":40013,"errmsg":"invalid appid"}

🔴 严重警告:中文乱码问题(必读!)

问题现象:发布后文章内容显示为 \x3Cp>这是文字\x3C/p> 标签,而不是正常中文。

根本原因

  1. ❌ Python requests 库默认编码不是 UTF-8
  2. ❌ Content-Type 头未指定 charset=utf-8
  3. ❌ Token 过期导致 API 异常处理

✅ 正确解决方案(必须遵守!)

# ========== 第 1 步:获取最新 token(每次发布前都要重新获取!) ==========
TOKEN=$(curl -s "https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=APPID&secret=SECRET" | python3 -c "import sys,json; print(json.load(sys.stdin).get('access_token',''))")

# ========== 第 2 步:上传封面图 ==========
COVER=$(curl -s -X POST "https://api.weixin.qq.com/cgi-bin/material/add_material?access_token=$TOKEN&type=image" -F "media=@/path/to/cover.jpg" | python3 -c "import sys,json; print(json.load(sys.stdin).get('media_id',''))")

# ========== 第 3 步:发布草稿(关键:-H "Content-Type: application/json; charset=utf-8") ==========
curl -s -X POST "https://api.weixin.qq.com/cgi-bin/draft/add?access_token=$TOKEN" \
  -H "Content-Type: application/json; charset=utf-8" \
  -d "{\"articles\":[{\"title\":\"标题\",\"content\":\"\x3Cp>中文内容\x3C/p>\",\"thumb_media_id\":\"$COVER\"}]}"

⚠️ 四个必须(缺一不可!)

  1. 每次发布前都重新获取 token - token 有效期只有 2 小时
  2. 必须指定 charset=utf-8 - -H "Content-Type: application/json; charset=utf-8"
  3. 必须用 curl 命令 - 不要用 Python requests(编码不可靠)
  4. 必须手机扫码预览 - PC 预览可能显示 Unicode(未验证账号)

🧪 测试命令(发布前先用这个验证编码):

curl -s -X POST "https://api.weixin.qq.com/cgi-bin/draft/add?access_token=$TOKEN" \
  -H "Content-Type: application/json; charset=utf-8" \
  -d "{\"articles\":[{\"title\":\"测试文字\",\"content\":\"\x3Cp>这是中文测试\x3C/p>\x3Cp>能看到吗\x3C/p>\",\"thumb_media_id\":\"$COVER\"}]}"

❌ 错误做法(不要再犯!)

  • 使用 Python requests.post(url, json=data) 直接发布
  • 复用旧 token(超过 2 小时)
  • 不指定 charset=utf-8
  • 只在 PC 端预览,不用手机扫码

快速开始

发布文章(推荐方式)

# 使用 curl 命令发布(见上方「严重警告」章节的完整命令)

上传图片

python3 scripts/upload_images.py /path/to/images/

排版模板

专业版模板(推荐)

适用于装修案例、实景展示等专业内容。

特点:

  • 英文 + 中文双语标题(如 LIVING ROOM · 客厅)
  • 奶油色配色方案(#f5e6d3、#8b7355)
  • 标题底部装饰线
  • 表格相间背景色
  • 预约框圆角背景

模板文件: assets/templates/professional.md

简洁版模板

适用于快讯、通知等简单内容。

模板文件: assets/templates/simple.md


文章结构

标准结构

  1. 封面大图 - 标题后第一张就是图片
  2. 项目信息 - 小区/面积/风格/造价表格
  3. 空间展示 - 客厅/餐厅/卧室/厨房等
  4. 费用明细 - 分类费用表格
  5. 改造亮点 - 项目亮点列表
  6. 预约量房 - CTA 行动号召
  7. 联系我们 - 公司信息

图片规则

  • 每个空间 1-2 张图
  • 图片宽度 100%,最大 600px
  • 图片间留白 20px
  • 封面图单独指定

发布流程

步骤 1:准备文章

# 文章标题

\x3Cimg src="封面图 URL">

---

## 空间 1

\x3Cimg src="图片 URL">

说明文字

---

## 空间 2

...

步骤 2:上传图片

python3 scripts/upload_images.py /path/to/images/
# 输出图片 URL 列表

步骤 3:插入 URL

将上传的图片 URL 替换文章中的占位符。

步骤 4:发布草稿

唯一推荐方式(curl 命令):

# 1. 获取 token
TOKEN=$(curl -s "https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=你的 APPID&secret=你的 APPSECRET" | python3 -c "import sys,json; print(json.load(sys.stdin).get('access_token',''))")

# 2. 上传封面
COVER=$(curl -s -X POST "https://api.weixin.qq.com/cgi-bin/material/add_material?access_token=$TOKEN&type=image" -F "media=@/path/to/cover.jpg" | python3 -c "import sys,json; print(json.load(sys.stdin).get('media_id',''))")

# 3. 发布(注意:-H "Content-Type: application/json; charset=utf-8")
curl -s -X POST "https://api.weixin.qq.com/cgi-bin/draft/add?access_token=$TOKEN" \
  -H "Content-Type: application/json; charset=utf-8" \
  -d "{\"articles\":[{\"title\":\"标题\",\"content\":\"\x3Cp>中文内容\x3C/p>\",\"thumb_media_id\":\"$COVER\"}]}"

❌ 禁止使用 Python 脚本直接发布(会导致乱码)

步骤 5:手动发表

登录微信后台 → 草稿箱 → 检查 → 点发表


配置

配置文件:config.json

{
  "appId": "你的 AppID",
  "appSecret": "你的 AppSecret",
  "ipWhitelist": ["你的服务器 IP 1", "你的服务器 IP 2"]
}

常见问题

🔴 中文乱码(最重要!)

现象:文章显示为 \x3Cp>这是文字\x3C/p> 标签

原因:编码格式不正确

解决方案

  1. 使用 curl 命令发布
  2. 必须指定 -H "Content-Type: application/json; charset=utf-8"
  3. 每次发布前重新获取 token

API 48001 错误

微信 API 未授权,无法直接发布。

解决方案: 使用草稿 API + 手动发表工作流。

图片不显示

图片未上传到微信素材库。

解决方案: 先用 upload_images.py 上传图片获取 URL。

排版错乱

Markdown 格式不正确。

解决方案: 使用提供的模板文件。


脚本说明

publish_wechat.py

发布文章到微信草稿箱。

python3 scripts/publish_wechat.py \x3Carticle.md> [options]

选项:
  --template \x3Cname>     模板名称 (viral/professional/simple)
  --cover-image \x3Cpath>  封面图路径
  --output \x3Cpath>       输出 HTML 路径

⚠️ 注意:此脚本可能导致中文乱码,建议使用 curl 命令替代。

upload_images.py

批量上传图片到微信素材库。

python3 scripts/upload_images.py \x3Cimage_folder>

输出:
  图片 URL JSON 文件

内容栏目

7 栏目规划

  1. 实景案例 - 完工项目实景拍摄
  2. 干货分享 - 装修知识/避坑指南
  3. 客户故事 - 业主访谈/入住反馈
  4. 工地实况 - 施工进度/工艺展示
  5. 材料科普 - 主材/辅材知识
  6. 问答互动 - 常见问题解答
  7. 活动促销 - 优惠活动/套餐

参考链接

  • 微信公众平台:https://mp.weixin.qq.com
  • 微信 API 文档:https://developers.weixin.qq.com/doc/offiaccount/
  • 排版参考:见 references/ 目录

公司信息模板

公司:[你的公司名称]
网站:[你的网站]
电话:[你的联系电话] / [你的联系电话]
地址:[你的地址]
时间:9:00-18:00(周一至周日)

发布检查清单(每次发布前必看!)

  • 已重新获取最新 token(不超过 2 小时)
  • 已使用 curl 命令(不是 Python)
  • 已指定 -H "Content-Type: application/json; charset=utf-8"
  • 已用手机扫码预览(不是 PC 预览)
  • 已确认文字正常显示(不是 \x3Cp>...\x3C/p> 标签)

以上 5 项全部打勾后才能正式发布!

Usage Guidance
This package appears to implement a WeChat article publisher, but take these precautions before installing: - Do not commit config.json (AppID/AppSecret) to any public registry; follow the SKILL.md advice and add it to .gitignore. The skill stores credentials in a local config.json rather than environment variables. - The SKILL.md insists on using curl for publishing to avoid encoding issues, yet publish_wechat.py uses Python requests to post drafts. If you prefer the Python script, review and test it carefully (the script posts JSON without specifying charset and may produce the exact encoding problems the docs warn about). - The Python scripts use requests with verify=False (disables SSL certificate verification). This is insecure — either remove verify=False or understand the risk (MITM could intercept tokens/uploads). Fix before use. - The repository does not declare dependencies (requests, markdown). Install only trusted packages and prefer pinned versions. Inspect scripts before running and run them in an isolated environment. - Confirm you control the IPs you add to the WeChat IP whitelist and that you trust the network path the scripts will use. Given these inconsistencies and insecure defaults, only proceed after (1) deciding whether to use the curl-based workflow (preferred in the docs) or updating the Python scripts to follow the same safe practices, (2) removing verify=False, and (3) installing dependencies from known sources. If you want, I can produce a minimal checklist or a patched version of the scripts that set proper headers, enable SSL verification, and declare dependencies.
Capability Analysis
Type: OpenClaw Skill Name: jvs-wechat-article-publisher Version: 1.0.6 The skill bundle provides tools for publishing WeChat articles but contains security vulnerabilities, specifically disabling SSL certificate verification (verify=False) in scripts/publish_wechat.py and scripts/upload_images.py, which exposes the user to man-in-the-middle attacks. While the instructions in SKILL.md are aligned with the stated purpose, they include forceful directives for the AI agent to handle sensitive API credentials (appId/appSecret) and perform manual network requests via curl. No evidence of intentional data exfiltration or malicious backdoors was found.
Capability Assessment
Purpose & Capability
Name/description match the included files: templates, an image uploader and a publish script that call the official WeChat APIs. Requiring AppID/AppSecret in a local config.json is proportional. Minor inconsistency: SKILL.md emphatically recommends using curl for publishing (and says 'do not use Python requests' due to encoding), yet the package includes publish_wechat.py which uses Python requests to post drafts (contradiction between documentation and shipped code).
Instruction Scope
Runtime instructions ask the user to create a local config.json with AppID/AppSecret and to add server IP(s) to WeChat's whitelist — these are expected. All network activity is directed at api.weixin.qq.com (expected). Concerns: the docs insist curl + explicit charset; the included Python scripts perform the same publish/upload flows (they perform network calls using requests). The scripts read local config.json (expected) and write image_url and publish_result JSON files (expected). There is no evidence of exfiltration to other endpoints, but the mismatch between 'do not use requests' guidance and included requests-based scripts is confusing and risky (may lead to encoding bugs or unexpected behavior).
Install Mechanism
No install spec (instruction-only) — lowest platform install risk. However, shipped Python scripts depend on third-party libraries (requests, markdown) that are not declared anywhere in the metadata or SKILL.md; user must install them manually. This omission is an operational/packaging concern (missing dependency declaration) rather than immediate malware, but it increases installation friction and potential for users to run arbitrary pip installs without guidance.
Credentials
The skill requires WeChat AppID/AppSecret stored in a local config.json — this is appropriate and proportional to the stated purpose. The skill does not request unrelated credentials or system config. Caution: SKILL.md warns not to upload config.json (good), but the repository includes an example only; users must ensure they don't accidentally commit secrets. Also, the code disables SSL verification (requests.* verify=False) which weakens TLS guarantees and could allow man-in-the-middle tampering of tokens or uploads.
Persistence & Privilege
The skill does not request always:true or any special platform persistence. It runs as user-invoked code or instruction-only flows and writes only local artifacts (image_urls.json, publish_result.json). It does not modify other skills or system-wide settings.
How to Use
  1. Make sure OpenClaw is installed (local or Docker)
  2. Run the install command in chat: /install jvs-wechat-article-publisher
  3. After installation, invoke the skill by name or use /jvs-wechat-article-publisher
  4. Provide required inputs per the skill's parameter spec and get structured output
Version History
v1.0.6
jvs-wechat-article-publisher 1.0.6 - 更新文档中的 IP 白名单和配置文件示例内容,更加泛化,提示需填写自己的服务器 IP。 - 强化配置说明,去除具体的公共 IP 示例,改用“你的服务器 IP”占位,强调自定义输入。 - 其他功能和使用流程无变动,核心文档内容保持一致。 - 未检测到代码或脚本变更,仅为文档优化。
v1.0.5
No changes detected in this release. - Version updated to 1.0.5 with no content or file modifications - Documentation and functionality remain the same as the previous version
v1.0.4
No user-facing changes in this version. - No file changes detected between previous and current versions.
v1.0.3
- 新增“使用前准备”章节,详细说明公众号要求、AppID/AppSecret 获取、IP 白名单配置和 config.json 文件设置。 - 提供本地和服务器常见 IP 白名单配置范例及安全提醒,建议将真实配置文件加入 .gitignore。 - 增加 curl 命令获取 token 的成功与失败响应示例,便于新手快速验证配置。 - 其他功能流程、乱码警告、发布流程等内容保持不变。
v1.0.2
- 更新了公司信息模板中的联系电话占位符,更加通用,便于自定义。 - 其余说明和功能保持不变。
v1.0.1
- Removed the sample configuration file config.json from the project. - Updated company information template in documentation to placeholders instead of a specific company. - No functional changes; documentation and sample data cleanup only.
v1.0.0
- Major update: Thoroughly revised documentation to address workflow and critical encoding issues. - Added detailed step-by-step publishing guide with strong warnings about Chinese character encoding and API pitfalls. - Changed file structure: added configuration templates and image uploading scripts for improved usability. - Expanded template support, including professional and simple layouts. - Provided clear troubleshooting section and comprehensive publishing checklist. - Removed obsolete agent and script definition files.
Metadata
Slug jvs-wechat-article-publisher
Version 1.0.6
License MIT-0
All-time Installs 2
Active Installs 2
Total Versions 7
Frequently Asked Questions

What is 微信公众号文章发布技能?

微信公众号文章排版和发布技能。提供专业排版模板、图片上传、草稿发布等完整工作流。使用场景:(1) 创建公众号文章,(2) 上传图片到素材库,(3) 发布草稿到微信后台,(4) 装修案例/干货分享/客户故事等类型文章。 It is an AI Agent Skill for Claude Code / OpenClaw, with 389 downloads so far.

How do I install 微信公众号文章发布技能?

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

Is 微信公众号文章发布技能 free?

Yes, 微信公众号文章发布技能 is completely free, licensed under MIT-0. You can download, install and use it at no cost.

Which platforms does 微信公众号文章发布技能 support?

微信公众号文章发布技能 is cross-platform and runs anywhere OpenClaw / Claude Code is available (cross-platform).

Who created 微信公众号文章发布技能?

It is built and maintained by chenyd002025 (@chenyd002025); the current version is v1.0.6.

💬 Comments