接口简介

  • 本接口用作给用户发送消息,支持群发,但1秒内最多允许调用1次,否则触发接口限流,错误码为429

接口请求参数

请求地址

POST https://站点接口域名/openapi/message/send

请求参数

参数名 类型 说明
sender int 发送人uid
receiver string 接收人uid列表,用英文逗号[,]隔开,建议一次不超过1000个
message string 消息内容
redirect string|array 对内容的关键词进行自定义跳转设置,使用json格式化,详见请求示例
type int 默认为0 值为1并且receiver传单个uid(消息会储存到聊天记录里面),type针对单用户聊天而非批量推送,可根据需求酌情传参

请求示例

// 普通表单请求
curl -X POST 'http://站点接口域名/openapi/message/send' \
  -H 'Accept: application/json' \
  -H 'Authorization: Bearer 5d39164d1f281' \
  -H 'Content-Type: application/x-www-form-urlencoded' \
  -d 'sender=%201&message=%20%E6%8E%A5%E5%8F%A3%E6%8E%A8%E9%80%81%E6%B5%8B%E8%AF%95&receiver=%201%2C2%2C3%2C4%2C5%2C6&redirect=%20%5B%7B%22redirect_name%22%3A%20%22%E6%B5%8B%E8%AF%95%22%2C%22redirct_url%22%3A%20%22qianfanyidong%3A%2F%2Fenvelopelist%22%7D%2C%7B%22redirect_name%22%3A%20%22%E6%8E%A8%E9%80%81%22%2C%22redirct_url%22%3A%20%22http%3A%2F%2Fwww.qianfanyun.com%22%7D%5D'
// 上面请求体中为urlencode的内容,原文内容如下
// 'sender=1&message=接口推送测试&receiver=1,2,3,4,5,6&redirect=[{"redirect_name": "测试","redirct_url": "qianfanyidong://envelopelist"},{"redirect_name": "推送","redirct_url": "http://www.qianfanyun.com"}]'


//使用json作为请求体
curl -X POST 'http://站点接口域名/openapi/message/send' \
  -H 'Accept: application/json' \
  -H 'Authorization: Bearer 5d39164d1f281' \
  -H 'Content-Type: application/json' \
  -d '{
  "sender": "1",
  "message": "接口推送测试",
  "receiver": "1,2,3,4,5,6",
  "redirect": [
    {
      "redirect_name": "测试",
      "redirct_url": "qianfanyidong://envelopelist"
    },
    {
      "redirect_name": "推送",
      "redirct_url": "http://www.qianfanyun.com"
    }
  ]
}'

接口响应说明

响应示例

{
    "code": 0,
    "text": "",
    "data": {
        "receiver_count": 6
    },
    "time": 1545809695
}

响应结果说明

参数名 说明
receiver_count 实际推送的用户数

重要说明:用户消息系统是建立在第三方平台之上的,所以响应返回的receiver_count的数值仅说明本次消息发送请求已经成功提交到了消信的任务队列中,并非说明这些用户已经收到了消息。

至于何时发送是由消息的后台任务系统进行调度的,在绝大多数情况下,消息都会在1~2秒钟之内发送到目标用户的客户端,偶尔会存在延迟,也不排除在某些极端情况下发送失败的情况。

文档更新时间: 2024-01-11 09:24   作者:千帆云