目录
推送消息
推送api接口限流
为保证服务公平性和可用性,对服务开放的接口进行限流。限流策略如下:
消息类型 | 上限 |
---|---|
单聊消息 | 50 人·消息/秒 |
普通聊消息 | 20 群·消息/秒 |
无限群聊消息 | 50 群·消息/秒 |
参数列表
Variable | Meanings |
---|---|
$appId | 小米开放平台申请的AppId |
$appKey | 小米开放平台申请的AppKey |
$appSecret | 小米开放平台申请的AppSecret |
$fromAccount | 表示消息发送方在APP账号系统内唯一ID |
$fromResource | 表示消息发送方设备的标识 |
$toAccount | 表示消息接收方在APP账号系统内唯一ID |
$toAccounts | 表示消息接收方在APP账号系统内唯一ID集合($toAccounts是一个List |
$msgType | 表示发送消息的类型 msgType="base64": msg是base64编码后的数据,一般传输二进制数据时使用; msgType="": msg是原始数据,一般传输String数据时使用 |
$isStore | 表示消息是否存储在mimc服务器,true存储,false不存储,默认不存储 |
$topicId | 表示群ID |
$topicIds | 表示群ID集合($topicIds是一个List |
$packetId | 表示发送消息包ID,由"随机串-数字"构成,在单个appAccount角度看可认为唯一 |
$bizType | 开发者定义消息类型,默认为空字符串 |
推送单聊信息
HTTP 请求
curl https://mimc.chat.xiaomi.net/api/push/p2p/ -XPOST -d '{"appId":$appId, "appKey":$appKey,"appSecret":$appSecret, "fromAccount":$fromAccount, "fromResource":$fromResource, "toAccount":$toAccount, "msg":$msg, "msgType":$msgType, "isStore":$isStore, "bizType":$bizType}' -H "Content-Type: application/json"
JSON结果
{ "code":200, "data":{"packetId":$packetId}, "message":"success" }
批量推送单聊信息
此功能目的是针对多个用户推送同一条消息。
- HTTP 请求
curl https://mimc.chat.xiaomi.net/api/push/p2p/more -XPOST -d '{"appId":$appId, "appKey":$appKey,"appSecret":$appSecret, "fromAccount":$fromAccount, "fromResource":$fromResource, "toAccounts":$toAccounts, "msg":$msg, "msgType":$msgType, "isStore":$isStore, "bizType":$bizType}' -H "Content-Type: application/json"
其中的$toAccounts变量格式为[$toAccount1,$toAccount2,...],每一个用户名之间用逗号隔开。
- JSON结果
{ "code":200, "data":{ "packetId":$packetId }, "message":"success" }
一次推送仅返回一个packetId,之前版本为一个接收者,返回一个packetId。
推送群聊信息
HTTP 请求
curl https://mimc.chat.xiaomi.net/api/push/p2t/ -XPOST -d '{"appId":$appId, "appKey":$appKey,"appSecret":$appSecret, "fromAccount":$fromAccount, "fromResource":$fromResource, "msg":$msg, "topicId":$topicId, "msgType":$msgType, "isStore":$isStore, "bizType":$bizType}' -H "Content-Type: application/json"
JSON结果
{ "code":200, "data":{"packetId":$packetId}, "message":"success" }
批量推送群聊信息
此功能目的是针对多个群组推送同一条消息。
HTTP 请求
curl https://mimc.chat.xiaomi.net/api/push/p2t/more -XPOST -d '{"appId":$appId, "appKey":$appKey,"appSecret":$appSecret, "fromAccount":$fromAccount, "fromResource":$fromResource, "topicIds":$topicIds, "msg":$msg, "msgType":$msgType, "isStore":$isStore, "bizType":$bizType}' -H "Content-Type: application/json"
其中的$topicIds变量格式为[$topicId1,$topicId2,...],每一个群ID之间用逗号隔开。
JSON结果
{ "code":200, "data":{ "packetId":$packetId }, "message":"success" }
之前返回packetIds集合,经过优化后,一次推送仅返回一个packetId。
单条推送无限群聊消息
向App的某个无限群聊推送一条消息。
HTTP 请求
curl https://mimc.chat.xiaomi.net/api/push/ucs/singleMsgPush -XPOST -H "Content-Type: application/json" -d '{"appId":$appId, "appKey":$appKey, "appSecret":$appSecret, "fromAccount":$fromAccount, "topicId":$topicId, "fromResource":$fromResource, "message":$message, "isStore":$isStore, "msgType":$msgType, "bizType":$bizType}'
JSON结果
{ "code": 200, "message": "success", "data": { "packetId": $packetId } }
批量推送无限群聊消息
向App的某个无限群推送多条消息。
HTTP请求
curl https://mimc.chat.xiaomi.net/api/push/ucs/multiMsgPush -XPOST -H "Content-Type: application/json" -d '{"appId":$appId, "appKey":$appKey, "appSecret":$appSecret, "fromAccount":$fromAccount, "topicId":$topicId, "fromResource":$fromResource, "messages":$messages, "isStore":$isStore, "msgType":$msgType, "bizType":$bizType}'
其中的$messages变量格式为[$message1,$message2,...],每一条消息之间用逗号隔开。
JSON结果
{ "code": 200, "message": "success", "data": { "packetIds": [$packetId] } }
这里优化后,将多条消息合并为单条发送,因此只有一个packetId。packetIds为集合,是为了以后N条消息,分为M条发送,目前多条消息,以单条形式发送。
多群推送单条消息
向App的一些无线群推送单条消息
- HTTP请求
curl https://mimc.chat.xiaomi.net/api/push/ucs/multiTopicPush -XPOST -H "Content-Type: application/json" -d '{"appId":$appId, "appKey":$appKey, "appSecret":$appSecret, "fromAccount":$fromAccount, "topicIds":$topicIds, "fromResource":$fromResource, "message":$message, "isStore":$isStore, "msgType":$msgType, "bizType":$bizType}'
其中的$topicIds变量格式为[$topic1,$topic2,...],每一条消息之间用逗号隔开。
- JSON结果
{ "code": 200, "message": "success", "data": { "succPacketIds": [$packetId1, $packetId2, ...], "failTopicIds": [$topicId1, $topicId2] } }