微信公众号素材管理和草稿发布 API 文档
http://localhost:3001/api
{
"success": true, // 请求是否成功
"data": { }, // 响应数据(成功时)
"error": "错误信息" // 错误信息(失败时)
}
所有接口支持通过参数指定账号,优先级如下:
appid + secret{
"success": true,
"data": [
{
"id": "uuid",
"name": "公众号名称",
"appid": "wx...",
"secret": "***",
"realSecret": "真实secret",
"isDefault": true,
"remark": "备注"
}
]
}
| 参数 | 类型 | 必填 | 说明 |
|---|---|---|---|
name |
string | 是 | 公众号名称 |
appid |
string | 是 | 公众号 AppID |
secret |
string | 是 | 公众号 AppSecret |
remark |
string | 否 | 备注信息 |
| 参数 | 类型 | 必填 | 说明 |
|---|---|---|---|
file |
file | 是 | 图片文件 (JPG/PNG/GIF/WebP, 最大10MB) |
appid |
string | 否 | 公众号 AppID(覆盖默认账号) |
secret |
string | 否 | 公众号 AppSecret(覆盖默认账号) |
{
"success": true,
"url": "https://mmbiz.qpic.cn/...",
"mediaId": "media_id"
}
| 参数 | 类型 | 必填 | 说明 |
|---|---|---|---|
title |
string | 是 | 文章标题 |
content |
string | 是 | 正文内容(HTML格式) |
thumbMediaId |
string | 否 | 封面图 MediaID |
author |
string | 否 | 作者名称 |
digest |
string | 否 | 文章摘要 |
needOpenComment |
boolean | 否 | 是否开启评论(默认true) |
appid |
string | 否 | 公众号 AppID |
secret |
string | 否 | 公众号 AppSecret |
{
"success": true,
"mediaId": "draft_media_id",
"previewUrl": "https://mp.weixin.qq.com/..."
}
offset |
number | 否 | 偏移量(默认0) |
count |
number | 否 | 数量(默认20,最大20) |
appid |
string | 否 | 公众号 AppID |
secret |
string | 否 | 公众号 AppSecret |
mediaId |
string | 是 | 草稿 MediaID |
type |
string | 否 | 素材类型:image/voice/video/thumb(默认image) |
offset |
number | 否 | 偏移量(默认0) |
count |
number | 否 | 数量(默认20) |
import requests # 上传图片 url = "http://localhost:3001/api/upload/image" files = {'file': open('image.jpg', 'rb')} data = { 'appid': 'your_appid', # 可选,覆盖默认账号 'secret': 'your_secret' # 可选 } response = requests.post(url, files=files, data=data) result = response.json() print(result['url']) # 微信图片URL
import requests # 1. 先上传封面图获取 media_id thumb_resp = requests.post( "http://localhost:3001/api/upload/thumb", files={'file': open('cover.jpg', 'rb')}, data={'appid': 'your_appid', 'secret': 'your_secret'} ).json() thumb_media_id = thumb_resp['mediaId'] # 2. 发布草稿 draft_data = { "title": "文章标题", "content": "<p>文章内容</p>", "thumbMediaId": thumb_media_id, "author": "作者名", "appid": "your_appid", "secret": "your_secret" } response = requests.post( "http://localhost:3001/api/draft/create", json=draft_data ) result = response.json() print(result['previewUrl']) # 草稿预览链接
// 发布草稿 async function publishDraft() { const response = await fetch('http://localhost:3001/api/draft/create', { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify({ title: '文章标题', content: '<p>文章内容</p>', thumbMediaId: '封面图media_id', author: '作者', // 可选:指定账号 appid: 'your_appid', secret: 'your_secret' }) }); const result = await response.json(); if (result.success) { console.log('预览链接:', result.previewUrl); } }
# 上传图片 curl -X POST http://localhost:3001/api/upload/image \ -F "file=@image.jpg" \ -F "appid=your_appid" \ -F "secret=your_secret" # 发布草稿 curl -X POST http://localhost:3001/api/draft/create \ -H "Content-Type: application/json" \ -d '{ "title": "文章标题", "content": "文章内容
", "thumbMediaId": "media_id", "appid": "your_appid", "secret": "your_secret" }'