跳到主要内容

Rest接口发送私聊、群聊 - IM即时通讯

接口功能

发送群聊、私聊信息,支持Uniapp通知栏提醒。
消息类型支持文本消息和自定义消息的发送,暂不支持服务端图片、语音、视频和文件,但可以用自定义消息里包含路径的方式实现。

调用说明

URL:

POST http://{rest-host}/v2/im/message

REST Host

杭州: rest-hz.goeasy.io
新加坡: rest-singapore.goeasy.io

参数格式

参数为JSON格式


{
"appkey": "bc-xxx",
"senderId": "user002",
"senderData": {'avatar':'/www/xxx.png','nickname':'Neo'},
"to": {
"type": "private/group",
"id": "userId/groupId",
"data": {"avatar":"/images/Avatar-2.png","name":"Wallace"},
"receivers":
[
{id: "userId/groupId", data: {"avatar": "/images/Avatar-1.png", "name": "Mattie"}},
{id: "userId/groupId", data: {"avatar": "/images/Avatar-1.png", "name": "Mattie"}}
]
},
"type": "text/[自定义类型]",
"payload":"Hello,GoEasy",
"notification": {
"title": "hello world",
"body": "你有一条新消息"
}
}

参数字段说明

参数类型描述
appkeyStringcommon key或rest key。

约束条件:
- 必填项
senderIdString发送方的UserId。

约束条件:
- 必填项
senderDataJSON对象发送方的user data,用于更新会话列表conversation.data。

约束条件:
- 必填项
to.typeString私聊:private,群聊:group。

约束条件:
- 必填项
to.idString接收方的id,用户Id或群Id。

约束条件:
- to.id和to.data与to.receivers至少存在一种,但不可同时存在
- 必须与to.data一起存在
to.dataJSON对象接收方的data对象,用于更新会话列表conversation.data。

约束条件:
- to.id和to.data与to.receivers至少存在一种,但不可同时存在
- 必须与to.id一起存在
to.receiversArray<Object>群发消息的接收方,用于更新会话列表conversation.data。

约束条件:
- to.id和to.data与to.receivers至少存在一种,但不可同时存在
- 私聊,接收方不可超过500个
- 群聊,接受方不可超过3个
typeString消息类型。

约束条件:
- 必填项
- 目前仅支持文本消息:text,和任意自定义消息(比如:order和chufang),开发者可以根据自己的需要任意指定,但不可以是goeasy已经定义过的类型:image/video/audio/file
payloadString/JSON对象消息内容。

约束条件:
- 必填项
- 若type为text,必须是字符串;若自定义类型,必须传入对象
notification.titleString通知栏提醒的标题。

约束条件:
- 可选项
- 必须与body同时使用
notification.bodyString通知栏提醒的内容 。

约束条件:
- 可选项
- 必须与title同时使用

调用示例


curl -X POST -H "Content-Type: application/json"
http://rest-hz.goeasy.io/v2/im/message
-d '{
"appkey": "BC-xxxx",
"senderId": "user001",
"senderData": {"avatar": "/static/images/Avatar-2.png", "name": "Wallace"},
"to": {
"type": "private",
"id": "user003",
"data": {"avatar": "/static/images/Avatar-1.png", "name": "Mattie"}
},
"type": "order",
"payload": {
"number": "20201818005",
"product": "Mate 30 Pro",
"image": "https://n.sinaimg.cn/sinacn10123/200/w640h360/20190916/e3d2-ietnfsp7076350.jpg",
"price": 3999
},
"notification": {
"title": "hello world",
"body": "你有一条新消息"
}
}'

返回说明

成功返回值示例

{
"code": 200,
"content": "ok"
}

失败返回值示例

{
"code":401,
"content":"Unauthorized"
}