发送群聊、私聊信息,支持Uniapp通知栏提醒。
消息类型支持文本消息和自定义消息的发送,暂不支持服务端图片、语音、视频和文件,但可以用自定义消息里包含路径的方式实现。
POST http://{rest-host}/v2/im/message
杭州: rest-hangzhou.goeasy.io
新加坡: rest-singapore.goeasy.io
{
"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"}
},
"type": "text/[自定义类型]",
"payload":"Hello,GoEasy",
"notification": {
"title": "hello world",
"body": "你有一条新消息"
}
}
参数 | 类型 | 必须 | 描述 |
---|---|---|---|
appkey | String | 是 | common key或rest key |
senderId | String | 是 | 发送方的UserId |
senderData | JSON对象 | 是 | 发送方的user data,用于更新会话列表conversation.data |
to.type | String | 是 | 私聊private,群聊:group |
to.id | String | 是 | 接收方的id,用户Id或群Id |
to.data | JSON对象 | 是 | 接收方的data对象,用于更新会话列表conversation.data |
type | String | 是 | 消息类型,目前仅支持文本消息:text,和任意自定义消息(比如:order和chufang),开发者可以根据自己的需要任意指定,但不可以是goeasy已经定义过的类型:image/video/audio/file |
payload | String/JSON对象 | 是 | 消息内容,若type为text,必须是字符串;若自定义类型,必须传入对象 |
notification.title | String | 否 | 通知栏提醒的标题, 必须与body同时使用 |
notification.body | String | 否 | 通知栏提醒的内容,必须与title同时使用 |
curl -X POST -H "Content-Type: application/json"
http://rest-hangzhou.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"
}