支持多种消息格式:文本卡片、Markdown、图文、文件等
普通文本消息,支持标题和内容
带链接的卡片消息,支持按钮
支持Markdown格式的富文本
多图文消息,支持图片和链接
发送图片文件
发送各种文件附件
POST /api/notify/{your_code}/textcard
| 参数名 | 类型 | 必填 | 说明 |
|---|---|---|---|
| title | String | 是 | 卡片标题,不超过128个字节 |
| description | String | 是 | 卡片描述,不超过512个字节 |
| url | String | 是 | 点击后跳转的链接 |
| btntxt | String | 否 | 按钮文字,默认为"详情" |
curl -X POST "http://your-server.com/api/notify/your-code/textcard" \
-H "Content-Type: application/json" \
-d '{
"title": "🚨 服务器告警",
"description": "服务器CPU使用率过高,当前使用率:85%,请及时处理!",
"url": "https://monitor.example.com/server/web-01",
"btntxt": "查看详情"
}'
POST /api/notify/{your_code}/markdown
| 参数名 | 类型 | 必填 | 说明 |
|---|---|---|---|
| content | String | 是 | Markdown格式的消息内容 |
# 标题 ## 二级标题 **粗体文本** *斜体文本* [链接文本](http://example.com) `代码` > 引用文本
curl -X POST "http://your-server.com/api/notify/your-code/markdown" \
-H "Content-Type: application/json" \
-d '{
"content": "# 📊 系统监控报告\n\n## 服务器状态\n- **CPU使用率**: 45%\n- **内存使用率**: 67%\n- **磁盘使用率**: 23%\n\n> 系统运行正常\n\n[查看详细监控](https://monitor.example.com)"
}'
POST /api/notify/{your_code}/news
| 参数名 | 类型 | 必填 | 说明 |
|---|---|---|---|
| articles | Array | 是 | 图文数组,最多8个 |
| articles[].title | String | 是 | 图文标题,不超过128个字节 |
| articles[].description | String | 否 | 图文描述,不超过512个字节 |
| articles[].url | String | 是 | 点击后跳转的链接 |
| articles[].picurl | String | 否 | 图片链接,支持JPG、PNG格式 |
curl -X POST "http://your-server.com/api/notify/your-code/news" \
-H "Content-Type: application/json" \
-d '{
"articles": [
{
"title": "🚀 新版本发布",
"description": "v2.0版本已发布,包含多项新功能和性能优化",
"url": "https://example.com/release/v2.0",
"picurl": "https://example.com/images/release.jpg"
},
{
"title": "📊 月度报告",
"description": "查看本月系统运行报告和统计数据",
"url": "https://example.com/reports/monthly"
}
]
}'
POST /api/notify/{your_code}/file
使用 multipart/form-data 格式上传文件
| 参数名 | 类型 | 必填 | 说明 |
|---|---|---|---|
| file | File | 是 | 要上传的文件,最大20MB |
| fileType | String | 否 | 文件类型:file(默认) 或 image |
# 发送文件 curl -X POST "http://your-server.com/api/notify/your-code/file" \ -F "file=@/path/to/report.pdf" \ -F "fileType=file" # 发送图片 curl -X POST "http://your-server.com/api/notify/your-code/file" \ -F "file=@/path/to/screenshot.png" \ -F "fileType=image"
POST /api/notify/{your_code}/enhanced
根据消息类型提供相应的参数,type字段必填
# 文本消息
{
"type": "text",
"content": "消息内容"
}
# 文本卡片
{
"type": "textcard",
"title": "卡片标题",
"description": "卡片描述",
"url": "跳转链接",
"btntxt": "按钮文字"
}
# Markdown消息
{
"type": "markdown",
"content": "# Markdown内容"
}
GET /api/notify/{your_code}/formats
{
"supportedFormats": [
{
"type": "text",
"name": "文本消息",
"description": "普通文本消息",
"endpoint": "/api/notify/:code",
"parameters": ["title", "content"]
},
{
"type": "textcard",
"name": "文本卡片",
"description": "带链接的卡片消息",
"endpoint": "/api/notify/:code/textcard",
"parameters": ["title", "description", "url", "btntxt?"]
}
]
}
import requests
class EnhancedWeChatNotifier:
def __init__(self, base_url, code):
self.base_url = base_url
self.code = code
def send_textcard(self, title, description, url, btntxt="详情"):
"""发送文本卡片"""
response = requests.post(f"{self.base_url}/api/notify/{self.code}/textcard", json={
"title": title,
"description": description,
"url": url,
"btntxt": btntxt
})
return response.json()
def send_markdown(self, content):
"""发送Markdown消息"""
response = requests.post(f"{self.base_url}/api/notify/{self.code}/markdown", json={
"content": content
})
return response.json()
def send_file(self, file_path, file_type="file"):
"""发送文件"""
with open(file_path, 'rb') as f:
files = {'file': f}
data = {'fileType': file_type}
response = requests.post(f"{self.base_url}/api/notify/{self.code}/file",
files=files, data=data)
return response.json()
# 使用示例
notifier = EnhancedWeChatNotifier("http://your-server:12121", "your-code")
# 发送告警卡片
notifier.send_textcard(
"🚨 系统告警",
"服务器CPU使用率过高,请及时处理!",
"https://monitor.example.com/alerts/001"
)
# 发送Markdown报告
notifier.send_markdown("""
# 📊 日报
## 今日数据
- **用户访问**: 1,234
- **订单数量**: 56
- **收入**: ¥12,345
""")
# 发送文件
notifier.send_file("/path/to/report.pdf")
class EnhancedWeChatNotifier {
constructor(baseUrl, code) {
this.baseUrl = baseUrl;
this.code = code;
}
async sendTextCard(title, description, url, btntxt = '详情') {
const response = await fetch(`${this.baseUrl}/api/notify/${this.code}/textcard`, {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ title, description, url, btntxt })
});
return response.json();
}
async sendNews(articles) {
const response = await fetch(`${this.baseUrl}/api/notify/${this.code}/news`, {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ articles })
});
return response.json();
}
}
// 使用示例
const notifier = new EnhancedWeChatNotifier('http://your-server:12121', 'your-code');
// 发送图文消息
await notifier.sendNews([
{
title: '🚀 新功能上线',
description: '增强版API现已支持多种消息格式',
url: 'https://example.com/features',
picurl: 'https://example.com/images/feature.jpg'
}
]);