企业微信消息推送接口

将外部请求转换为企业微信自建应用消息,并自动管理 access_token。

接口地址

POSThttps://wx.exloli.net/v1/messages/send

GEThttps://wx.exloli.net/healthz(健康检查)

鉴权

请求必须携带网关密钥:

Authorization: Bearer <PUSH_API_KEY>
Content-Type: application/json

网关密钥和企业微信 app_secret 都是敏感信息,请使用 Secret Manager 或环境变量保存,不要写入前端代码、仓库或日志。

请求示例

curl -X POST 'https://wx.exloli.net/v1/messages/send' \
  -H "Authorization: Bearer ${WECOM_PUSH_API_KEY}" \
  -H 'Content-Type: application/json' \
  --data-raw '{
    "corp_id": "wwfd78bcd13bdd080e",
    "agent_id": 1000002,
    "app_secret": "企业微信自建应用Secret",
    "recipients": {"users": ["zhangsan"]},
    "message": {
      "type": "text",
      "payload": {"content": "服务告警:订单处理失败"}
    }
  }'

请求字段

字段必填说明
corp_id企业 CorpId。当前白名单仅允许 wwfd78bcd13bdd080e
agent_id自建应用 AgentId,正整数。
app_secret对应自建应用 Secret,仅用于获取 token,不写入 token 缓存。
recipients.users至少一种成员 UserID 数组,可传 @all
recipients.parties至少一种部门 ID 数组。
recipients.tags至少一种标签 ID 数组。
message.typetextmarkdownimagevoicevideofiletextcardnewsmpnewstemplate_card
message.payload对应企业微信“发送应用消息”接口的消息对象。

Markdown 示例

"message": {
  "type": "markdown",
  "payload": {
    "content": "您的任务已完成,详情请查看 [任务页面](https://example.com/task/123)。"
  }
}

响应

成功返回 HTTP 200:

{
  "ok": true,
  "data": {"errcode": 0, "errmsg": "ok", "msgid": "消息ID"},
  "request_id": "请求追踪ID"
}

常见状态码:400 参数错误,401 网关鉴权失败,403 CorpId 不在白名单,502 企业微信接口拒绝或网络错误。

企业微信 60020 表示服务器出口 IP 不在可信 IP 列表中;当前服务器 IP 为 111.119.195.75

运行机制