企业微信群机器人 Webhook
本文档记录企业微信群机器人的 Webhook 地址及使用方法,用于通过 API 向企业微信群推送消息。
Webhook 地址
Webhook URL:
https://qyapi.weixin.qq.com/cgi-bin/webhook/send?key=73febdcb-1b38-4d1b-a994-790f21fc8d30⚠️ 注意: 此 Webhook 地址包含密钥(key),请勿公开分享或提交到公共代码仓库。
发送消息
发送文本消息
请求方式: POST
Content-Type: application/json
请求示例
bash
curl -X POST \
'https://qyapi.weixin.qq.com/cgi-bin/webhook/send?key=73febdcb-1b38-4d1b-a994-790f21fc8d30' \
-H 'Content-Type: application/json' \
-d '{
"msgtype": "text",
"text": {
"content": "Hello,企业微信群机器人!"
}
}'请求体参数
| 参数 | 类型 | 必填 | 说明 |
|---|---|---|---|
msgtype | string | 是 | 消息类型,此处为 text |
text.content | string | 是 | 文本内容,最长 2048 字节 |
text.mentioned_list | string[] | 否 | @ 的成员 userid 列表 |
text.mentioned_mobile_list | string[] | 否 | @ 的成员手机号列表 |
发送 Markdown 消息
bash
curl -X POST \
'https://qyapi.weixin.qq.com/cgi-bin/webhook/send?key=73febdcb-1b38-4d1b-a994-790f21fc8d30' \
-H 'Content-Type: application/json' \
-d '{
"msgtype": "markdown",
"markdown": {
"content": "# 标题\n**加粗文本**\n> 引用文本"
}
}'Markdown 支持格式
| 格式 | 语法 |
|---|---|
| 标题 | # 一级标题 ## 二级标题 |
| 加粗 | **文本内容** |
| 链接 | [文本](url) |
| 引用 | > 引用内容 |
| 字体颜色 | <font color="warning">警告</font> |
发送图片消息
bash
curl -X POST \
'https://qyapi.weixin.qq.com/cgi-bin/webhook/send?key=73febdcb-1b38-4d1b-a994-790f21fc8d30' \
-H 'Content-Type: application/json' \
-d '{
"msgtype": "image",
"image": {
"base64": "BASE64_ENCODED_IMAGE",
"md5": "IMAGE_MD5"
}
}'Node.js 使用示例
发送文本消息
javascript
const axios = require('axios');
const WEBHOOK_URL = 'https://qyapi.weixin.qq.com/cgi-bin/webhook/send?key=73febdcb-1b38-4d1b-a994-790f21fc8d30';
async function sendTextMessage(content) {
try {
const response = await axios.post(WEBHOOK_URL, {
msgtype: 'text',
text: {
content: content
}
}, {
headers: {
'Content-Type': 'application/json'
}
});
console.log('发送成功:', response.data);
return response.data;
} catch (error) {
console.error('发送失败:', error.response?.data || error.message);
throw error;
}
}
// 使用示例
sendTextMessage('AI 新闻推送测试 🤖');发送 Markdown 消息
javascript
async function sendMarkdownMessage(content) {
try {
const response = await axios.post(WEBHOOK_URL, {
msgtype: 'markdown',
markdown: {
content: content
}
}, {
headers: {
'Content-Type': 'application/json'
}
});
console.log('发送成功:', response.data);
return response.data;
} catch (error) {
console.error('发送失败:', error.response?.data || error.message);
throw error;
}
}
// 使用示例
sendMarkdownMessage(`# AI 新闻日报
> 今日 AI 领域最新动态
**热点新闻**
1. OpenAI 发布最新模型
2. Google 推出 AI 编程助手
`);Python 使用示例
python
import requests
import json
WEBHOOK_URL = "https://qyapi.weixin.qq.com/cgi-bin/webhook/send?key=73febdcb-1b38-4d1b-a994-790f21fc8d30"
def send_text_message(content):
"""发送文本消息"""
payload = {
"msgtype": "text",
"text": {
"content": content
}
}
response = requests.post(WEBHOOK_URL, json=payload)
result = response.json()
if result.get("errcode") == 0:
print("发送成功")
else:
print(f"发送失败: {result}")
return result
# 使用示例
send_text_message("AI 新闻推送测试 🤖")返回格式
成功返回
json
{
"errcode": 0,
"errmsg": "ok"
}错误返回
json
{
"errcode": 93000,
"errmsg": "invalid webhook url"
}常见错误码
| 错误码 | 说明 |
|---|---|
| 0 | 成功 |
| 93000 | Webhook 地址无效 |
| 88888 | 请求参数错误 |
| 45009 | 接口调用超过限制 |
使用场景
- AI 新闻推送: 每日定时推送 AI 领域最新动态
- 系统监控告警: 服务异常时自动通知
- 日程提醒: 重要事项提前通知
- 数据报表: 定期推送数据统计结果
注意事项
- 频率限制: 每个机器人每分钟最多发送 20 条消息
- 消息长度: 文本内容最长 2048 字节
- 安全保管: Webhook URL 包含密钥,请勿泄露
- 群聊限制: 每个群最多添加 10 个机器人
最后更新: 2026-05-18