接口简介

  • 通过环信给用户发送模版类型的通知消息(只适用于版本号>=4.0 的app)

因为环信的限制,发送内容最好不要超过20kb,发送数量最好不要超过20条/秒。

接口请求说明

请求方式

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

请求参数

参数名 类型 是否必须 说明
from int 服务号uid,只有设置为服务号的uid才能发送(注意必须是服务号uid,不是服务号id)
target string 接收用户uid,多个用户用英文逗号隔开例如’1031,1231’,建议数量不要大于20
msg string 手机通知提醒的内容,例如 ‘活动消息提醒’
showData jsonString 模版消息的主体内容,有如下的数组组成的json

服务号uid的获取方式

showData由以下数组组成的json
数组里的字段务必保证都有,如果没有内容的content可以为空。

// php代码示例
$showData = [
    'title' => '活动报名成功',
    'date' => '10月29日',
    'setting' => [
        [
            'setKey' => '活动名称',
            'setValue' => '千帆移动',
        ],
        [
            'setKey' => '主办方',
            'setValue' => '迪诺水镇暑期狂欢游',
        ],
        [
            'setKey' => '开始时间',
            'setValue' => '2018-07-24',
        ],
    ],
    'content' => '恭喜您成功报名2018.12.18 的彩虹马拉松亲子长跑活动。',
    'url' => 'https://zzz.com'
];

showData参数说明

字段名 类型 说明
title string 标题,例如‘xxx活动报名成功通知’
date string 时间,发送时间,例如‘7月24日’
content string 消息主体内容
url string 协议跳转地址
setting array 具体的模板相关数据
setKey string 模版设置名称
setValue string 模板设置内容

请求示例

curl -X POST  'https://站点接口域名/openapi/message/template' \
  -H 'Authorization: Bearer 5d39164d1f281' \
  -H 'Content-Type: application/x-www-form-urlencoded' \
  -H 'Accept: application/json'
  -d 'from=1&target=1031%2C2&msg=%E9%80%9A%E7%9F%A5%E6%A0%87%E9%A2%98&showData=%7B%22title%22%3A%22%5Cu6d3b%5Cu52a8%5Cu62a5%5Cu540d%5Cu6210%5Cu529f%22%2C%22date%22%3A%2210%5Cu670829%5Cu65e5%22%2C%22setting%22%3A%5B%7B%22setKey%22%3A%22%5Cu6d3b%5Cu52a8%5Cu540d%5Cu79f0%22%2C%22setValue%22%3A%22%5Cu5343%5Cu5e06%5Cu79fb%5Cu52a8%22%7D%2C%7B%22setKey%22%3A%22%5Cu4e3b%5Cu529e%5Cu65b9%22%2C%22setValue%22%3A%22%5Cu8fea%5Cu8bfa%5Cu6c34%5Cu9547%5Cu6691%5Cu671f%5Cu72c2%5Cu6b22%5Cu6e38%22%7D%2C%7B%22setKey%22%3A%22%5Cu5f00%5Cu59cb%5Cu65f6%5Cu95f4%22%2C%22setValue%22%3A%222018-07-24%22%7D%5D%2C%22content%22%3A%22%5Cu606d%5Cu559c%5Cu60a8%5Cu6210%5Cu529f%5Cu62a5%5Cu540d2018.12.18%20%5Cu7684%5Cu5f69%5Cu8679%5Cu9a6c%5Cu62c9%5Cu677e%5Cu4eb2%5Cu5b50%5Cu957f%5Cu8dd1%5Cu6d3b%5Cu52a8%5Cu3002%22%2C%22url%22%3A%22https%3A%5C%2F%5C%2F站点接口域名%5C%2Fstore-view%5C%2Fstore%5C%2Fhome%22%7D'

接口响应说明

响应示例

{
    "code": 0,
    "text": "",
    "data": [],
    "time": 1545809695
}

响应结果说明
code=0表示推送任务已经提交成功。

文档更新时间: 2022-12-28 16:02   作者:漫漫