差别
这里会显示出您选择的修订版和当前版本之间的差别。
两侧同时换到之前的修订记录 前一修订版 后一修订版 | 前一修订版 后一修订版 两侧同时换到之后的修订记录 | ||
im:server:basics:messages [2019/08/09 09:21] huanxinfudh [发送文本消息] |
im:server:basics:messages [2019/12/23 06:44] lizg |
||
---|---|---|---|
行 134: | 行 134: | ||
<code php> | <code php> | ||
- | curl -X POST -i 'https://a1.easemob.com/easemob-demo/testapp/messages' -H 'Authorization: Bearer YWMtsFVigGSuEeSTc7k5183Z5QAAAUqzeFx_9IjRch-ZxNbIlBIvx_4GWvzheSU' -d '{"target_type":"users","target":["user2"],"from":"user1","msg":{"type":"img","filename":"testimg.jpg","secret":"VfEpSmSvEeS7yU8dwa9rAQc-DIL2HhmpujTNfSTsrDt6eNb_","url":"https://a1.easemob.com/easemob-demo/testapp/chatfiles/55f12940-64af-11e4-8a5b-ff2336f03252"},"size":{"width":480,"height":720}}' | + | curl -X POST -i 'https://a1.easemob.com/easemob-demo/testapp/messages' -H 'Authorization: Bearer YWMtsFVigGSuEeSTc7k5183Z5QAAAUqzeFx_9IjRch-ZxNbIlBIvx_4GWvzheSU' -d '{"target_type":"users","target":["user2"],"from":"user1","msg":{"type":"img","filename":"testimg.jpg","secret":"VfEpSmSvEeS7yU8dwa9rAQc-DIL2HhmpujTNfSTsrDt6eNb_","url":"https://a1.easemob.com/easemob-demo/testapp/chatfiles/55f12940-64af-11e4-8a5b-ff2336f03252","size":{"width":480,"height":720}}}' |
</code> | </code> | ||
行 366: | 行 366: | ||
[[http://api-docs.easemob.com/|使用 Easemob REST API 在线测试]] | [[http://api-docs.easemob.com/|使用 Easemob REST API 在线测试]] | ||
---- | ---- | ||
+ | ===== 发送位置消息 ===== | ||
+ | 位置消息:获取到地址的经纬度,填写正确地址发送。 | ||
+ | <WRAP clear/> | ||
+ | **注意**:在调用程序中,请求体如果超过 5kb 会导致413错误,需要拆成几个更小的请求体重试,同时用户消息+扩展字段的长度在40k字节以内。详见[[im:server:help:restastrict|接口限流说明]]。 | ||
+ | === HTTP Request === | ||
+ | |||
+ | ^{{:im:server:ready:post.png?nolink&90 |}}^/**/{org_name}/{app_name}/messages**^ | ||
+ | |||
+ | === Request Headers === | ||
+ | |||
+ | ^参数^说明^ | ||
+ | |Content-Type|application/json| | ||
+ | |Authorization|Bearer ${token}| | ||
+ | |||
+ | === Request Body === | ||
+ | |||
+ | ^参数^说明^ | ||
+ | |target_type|发送的目标类型;users:给用户发消息,chatgroups:给群发消息,chatrooms:给聊天室发消息| | ||
+ | |target|发送的目标;注意这里需要用数组,数组长度建议不大于20,即使只有一个用户,也要用数组 ['u1'];给用户发送时数组元素是用户名,给群组发送时,数组元素是groupid| | ||
+ | |msg|消息内容| | ||
+ | |type|消息类型;txt:文本消息,img:图片消息,loc:位置消息,audio:语音消息,video:视频消息,file:文件消息| | ||
+ | |from|表示消息发送者;无此字段Server会默认设置为"from":"admin",有from字段但值为空串("")时请求失败| | ||
+ | |||
+ | === Response Body === | ||
+ | 在返回值中查看data字段包含的信息 | ||
+ | ^参数^说明^ | ||
+ | |username|接受消息的用户名| | ||
+ | |success|表示消息发送成功| | ||
+ | |||
+ | |||
+ | === 请求示例 === | ||
+ | |||
+ | <code php> | ||
+ | curl -X POST -H 'Content-Type: application/json' -H 'Accept: application/json' -H 'Authorization: Bearer YWMtP5n9zvOQEei7KclxPqJTkgAAAAAAAAAAAAAAAAAAAAGL4CTw6XgR6LaXXVmNX4QCAgMAAAFnXcBpfQBPGgDC09w5IdrfqG_H8_F53VLVTG0_82GXyEF8ZdMCt9-UpQ' -d '{"target_type": "users","target": ["user2"],"msg": {"type": "loc","lat": "39.966","lng":"116.322",."addr":"中国北京市海淀区中关村"},"from": "user1"}' 'http://a1.easemob.com/easemob-demo/testapp/messages' | ||
+ | </code> | ||
+ | |||
+ | === 可能返回的结果示例 === | ||
+ | |||
+ | **返回值200,表示消息发送成功** | ||
+ | |||
+ | <code json> | ||
+ | { | ||
+ | "action": "post", | ||
+ | "application": "8be024f0-e978-11e8-b697-5d598d5f8402", | ||
+ | "path": "/messages", | ||
+ | "uri": "https://a1.easemob.com/easemob-demo/testapp/messages", | ||
+ | "data": { | ||
+ | "user2": "success" | ||
+ | }, | ||
+ | "timestamp": 1543922150902, | ||
+ | "duration": 1, | ||
+ | "organization": "easemob-demo", | ||
+ | "applicationName": "testapp" | ||
+ | } | ||
+ | </code> | ||
+ | |||
+ | **返回值400,表示 massage 结构错误** | ||
+ | <code json> | ||
+ | { | ||
+ | "error": "json_parse", | ||
+ | "timestamp": 1543922465246, | ||
+ | "duration": 0, | ||
+ | "exception": "org.codehaus.jackson.JsonParseException", | ||
+ | "error_description": "Unexpected character ('}' (code 125)): was expecting double-quote to start field name\n at [Source: java.io.BufferedInputStream@7ba7eef2; line: 11, column: 2]" | ||
+ | } | ||
+ | </code> | ||
+ | |||
+ | **返回值401,表示未授权[无token、token错误、token过期]** | ||
+ | <code json> | ||
+ | { | ||
+ | "error": "auth_bad_access_token", | ||
+ | "timestamp": 1543922590032, | ||
+ | "duration": 0, | ||
+ | "exception": "org.apache.usergrid.rest.exceptions.SecurityException", | ||
+ | "error_description": "Unable to authenticate due to corrupt access token" | ||
+ | } | ||
+ | </code> | ||
+ | |||
+ | 如果返回结果是<wrap em>429、503</wrap>或者其他<wrap em>5xx</wrap>,有可能代表该接口被限流了,请稍微暂停一下并重试。详见[[im:server:help:restastrict|接口限流说明]] | ||
+ | |||
+ | [[http://api-docs.easemob.com/|使用 Easemob REST API 在线测试]] | ||
+ | ---- | ||
===== 发送透传消息 ===== | ===== 发送透传消息 ===== | ||
行 390: | 行 472: | ||
|target|发送的目标;注意这里需要用数组,数组长度建议不大于20,即使只有一个用户,也要用数组 ['u1'];给用户发送时数组元素是用户名,给群组发送时,数组元素是groupid| | |target|发送的目标;注意这里需要用数组,数组长度建议不大于20,即使只有一个用户,也要用数组 ['u1'];给用户发送时数组元素是用户名,给群组发送时,数组元素是groupid| | ||
|msg|消息内容| | |msg|消息内容| | ||
- | |type|消息类型;txt:文本消息,img:图片消息,loc:位置消息,audio:语音消息,video:视频消息,file:文件消息| | + | |type|消息类型;txt:文本消息,img:图片消息,loc:位置消息,audio:语音消息,video:视频消息,file:文件消息,cmd:透传消息| |
|from|表示消息发送者;无此字段Server会默认设置为"from":"admin",有from字段但值为空串("")时请求失败| | |from|表示消息发送者;无此字段Server会默认设置为"from":"admin",有from字段但值为空串("")时请求失败| | ||