本API提供微信公众号草稿箱管理功能,支持多公众号使用各自的appid和app_secret进行操作。
多公众号API: 在请求体中包含 appid 和 app_secret
自动获取访问令牌: 程序会自动根据appid和app_secret获取微信访问令牌
http://localhost:3000 (开发环境)
请根据实际部署情况调整域名和端口
支持不同公众号使用自己的appid和app_secret创建草稿,程序会自动获取访问令牌。
/api/draft/multi/import-url
{
"url": "https://example.com/article",
"appid": "your-appid",
"app_secret": "your-app-secret",
"author": "作者名称",
"digest": "文章摘要",
"thumb_media_id": "封面图片素材ID"
}
{
"success": true,
"data": {
"media_id": "MEDIA_ID",
"created_at": 1640995200000,
"title": "文章标题",
"content_preview": "内容预览..."
},
"message": "从URL导入成功"
}
curl -X POST http://localhost:3000/api/draft/multi/import-url \
-H "Content-Type: application/json" \
-d '{
"url": "https://example.com/article",
"appid": "your-appid",
"app_secret": "your-app-secret"
}'
/api/draft/multi/import-html
{
"html": "标题
内容
",
"title": "文章标题",
"appid": "your-appid",
"app_secret": "your-app-secret",
"author": "作者名称",
"digest": "文章摘要"
}
{
"success": true,
"data": {
"media_id": "MEDIA_ID",
"created_at": 1640995200000,
"title": "文章标题",
"content_preview": "内容预览..."
},
"message": "从HTML导入成功"
}
curl -X POST http://localhost:3000/api/draft/multi/import-html \
-H "Content-Type: application/json" \
-d '{
"html": "标题
内容
",
"title": "文章标题",
"appid": "your-appid",
"app_secret": "your-app-secret"
}'
/api/draft/multi/import-markdown
{
"markdown": "# 标题\n\n这是**粗体**文本\n\n```javascript\nconsole.log('Hello');\n```",
"title": "文章标题",
"appid": "your-appid",
"app_secret": "your-app-secret",
"author": "作者名称",
"digest": "文章摘要"
}
{
"success": true,
"data": {
"media_id": "MEDIA_ID",
"created_at": 1640995200000,
"title": "文章标题",
"content_preview": "内容预览..."
},
"message": "从Markdown导入成功"
}
curl -X POST http://localhost:3000/api/draft/multi/import-markdown \
-H "Content-Type: application/json" \
-d '{
"markdown": "# 标题\n\n这是内容",
"title": "文章标题",
"appid": "your-appid",
"app_secret": "your-app-secret"
}'
/api/draft/multi/preview-markdown
将Markdown内容转换为HTML格式进行预览,但不创建草稿。
{
"markdown": "# 标题\n\n这是**粗体**文本\n\n```javascript\nconsole.log('Hello');\n```",
"appid": "your-appid",
"app_secret": "your-app-secret"
}
{
"success": true,
"data": {
"html": "<div style=\"font-family: -apple-system...\"><h1>标题</h1>..."
},
"message": "Markdown预览生成成功"
}
/api/draft/multi/create-draft
{
"title": "文章标题",
"content": "标题
内容
",
"appid": "your-appid",
"app_secret": "your-app-secret",
"author": "作者名称",
"digest": "文章摘要"
}
{
"success": true,
"data": {
"media_id": "MEDIA_ID",
"created_at": 1640995200000
},
"message": "创建草稿成功"
}
curl -X POST http://localhost:3000/api/draft/multi/create-draft \
-H "Content-Type: application/json" \
-d '{
"title": "文章标题",
"content": "标题
内容
",
"appid": "your-appid",
"app_secret": "your-app-secret"
}'
/api/draft/multi/list
{
"appid": "your-appid",
"app_secret": "your-app-secret",
"offset": 0,
"count": 20
}
{
"success": true,
"data": {
"item_count": 5,
"item": [
{
"media_id": "MEDIA_ID",
"content": {
"news_item": [
{
"title": "文章标题",
"author": "作者",
"digest": "摘要",
"content": "内容",
"thumb_media_id": "THUMB_MEDIA_ID"
}
]
},
"update_time": 1640995200
}
]
},
"message": "获取草稿列表成功"
}
curl -X POST http://localhost:3000/api/draft/multi/list \
-H "Content-Type: application/json" \
-d '{
"appid": "your-appid",
"app_secret": "your-app-secret",
"offset": 0,
"count": 20
}'
/api/draft/multi/delete
{
"mediaId": "MEDIA_ID",
"appid": "your-appid",
"app_secret": "your-app-secret"
}
{
"success": true,
"message": "草稿删除成功"
}
curl -X POST http://localhost:3000/api/draft/multi/delete \
-H "Content-Type: application/json" \
-d '{
"mediaId": "MEDIA_ID",
"appid": "your-appid",
"app_secret": "your-app-secret"
}'
/api/draft/multi/materials
{
"appid": "your-appid",
"app_secret": "your-app-secret",
"type": "image",
"count": 20
}
{
"success": true,
"data": {
"item": [
{
"media_id": "MEDIA_ID",
"name": "图片名称",
"url": "https://mmbiz.qpic.cn/..."
}
]
},
"message": "获取素材列表成功"
}
curl -X POST http://localhost:3000/api/draft/multi/materials \
-H "Content-Type: application/json" \
-d '{
"appid": "your-appid",
"app_secret": "your-app-secret",
"type": "image",
"count": 20
}'
| 错误码 | 说明 | 解决方案 |
|---|---|---|
| 400 | 缺少认证信息 | 请提供appid和app_secret |
| 401 | 认证失败 | 检查appid和app_secret是否正确 |
| 500 | 服务器内部错误 | 检查服务器日志 |
# 服务器配置
PORT=3000
NODE_ENV=production
PORT: 服务器端口号NODE_ENV: 运行环境(development/production)