====== 群组管理 ======
更新时间:2021-12-31 该文档已不再维护,请看新版 3.X 文档。
新版文档见:[[ccim:rest:group|群组管理 REST API]]。
----
环信提供了 REST API 来管理 APP 中的群组。
单个APP可以创建的群组数量以及单用户ID可以加入的群数量请参考不同版本[[http://www.easemob.com/pricing/im|数量]],如需增加可根据具体业务联系商务解决。
===== 群组数据结构 =====
^字段名 ^类型 ^描述^
|id |String |群组 ID,群组唯一标识符,由环信服务器生成,等同于单个用户的环信 ID。|
|name |String |群组名称,根据用户输入创建,字符串类型,最大长度为128字符。|
|description |String |群组描述,根据用户输入创建,字符串类型,最大长度为512字符。|
|public |Boolean |群组类型:true:公开群,false:私有群。|
|membersonly |Boolean |加入群组是否需要群主或者群管理员审批。true:是,false:否。|
|allowinvites |Boolean |是否允许群成员邀请别人加入此群。 true:允许群成员邀请人加入此群,false:只有群主才可以往群里加人。由于只有私有群才允许群成员邀请人加入此群,所以当群组为私有群时,该参数设置为true才有效。默认为false|
|maxusers |Integer |群成员上限,创建群组的时候设置需要设置,具体数量请参考不同版本[[http://www.easemob.com/pricing/im|数量]]。|
|affiliations_count |Integer |现有成员总数。|
|affiliations |Array |现有成员列表,包含了 owner 和 member。例如:"affiliations":[{"owner": "13800138001"},{"member":"v3y0kf9arx"},{"member":"xc6xrnbzci"}]。|
|owner |String |群主的环信 ID。例如:{"owner": "13800138001"}。|
|member |String |群成员的环信 ID。例如:{"member":"xc6xrnbzci"}。|
|invite_need_confirm|Boolean|邀请加群,被邀请人是否需要确认。如果是true,表示邀请加群需要被邀请人确认;如果是false,表示不需要被邀请人确认,直接将被邀请人加入群。 该字段的默认值为true。|
|custom |String |群组扩展信息,例如可以给群组添加业务相关的标记,不要超过1024字符。|
|mute |Boolean |是否全员禁言。true:是,false:否。|
===== 群组角色 =====
群组除了群主、普通群成员之外,新增群管理员角色。
群组角色权限范围:群主 > 群管理员 > 普通群成员
* 群主拥有群的所有权限;
* 群管理员拥有管理黑名单、禁言等权限;
* 最多管理员角色数量:1个群主+99个管理员;
----
====== REST API ======
IM 群组集成过程中,需要使用到的 REST API 文档详细说明,可以通过使用文档中嵌入的[[http://api-docs.easemob.com/|Easemob REST API]]进行在线测试。
=====管理群组=====
环信提供多个接口完成群组相关的集成,包括对群组的创建、获取、修改、删除等管理功能。
^名称^请求^描述^
|获取App中所有的群组(可分页)|/{org_name}/{app_name}/chatgroups|获取应用下全部的群组信息|
|获取单个用户加入的所有群组|/{app_name}/users/{username}/joined_chatgroups;分页获取:/{app_name}/users/{username}/joined_chatgroups?pagesize={}&pagenum={}|根据用户名称获取此用户加入的全部群组|
|获取群组详情|/{org_name}/{app_name}/chatgroups/{group_ids}|根据群组ID获取此群组的详情|
|创建一个群组|/{org_name}/{app_name}/chatgroups|创建一个新群组|
|修改群组信息|/{org_name}/{app_name}/chatgroups/{group_id}|修改群组的部分信息|
|删除群组|/{org_name}/{app_name}/chatgroups/{group_id}|删除一个群组|
==== 获取 App 中所有的群组(可分页)====
分页获取应用下全部的群组信息的接口
=== HTTP Request ===
^{{:im:server:basics:get.png?nolink&90|}}^**/{org_name}/{app_name}/chatgroups**^
=== Request Headers ===
^参数^说明^
|Content-Type|application/json|
|Authorization|Bearer ${token}|
=== Response Body ===
在返回值中查看data字段包含的信息
^参数^说明^
|owner|群主的环信 ID。例如:{“owner”: “user1}。|
|groupid|群组ID|
|affiliations|群组现有人数|
|type|“group”群组类型|
|last_modified|最近一次修改的时间戳|
|groupname|群组名称|
''对于返回的数据的排序:例如每页取10个,第一页的10个群组,会是比第二页的10个后创建的。但第一页内的10个,不是有序的,可能会有乱序。''
=== 请求示例 ===
第一页
curl -X GET -H 'Accept: application/json' -H 'Authorization: Bearer YWMt4LqJIul7EeizhBO5TSO_UgAAAAAAAAAAAAAAAAAAAAGL4CTw6XgR6LaXXVmNX4QCAgMAAAFnG7GyAQBPGgDv4ENRUku7fg05Kev0a_aVC8NyA6O6PgpxIRjajSVN3g' 'http://a1.easemob.com/easemob-demo/testapp/chatgroups?limit=2'
=== 可能返回的结果示例 ===
**返回值200,表示获取群组成功**
{
"action": "get",
"params": {
"limit": [
"2"
]
},
"uri": "https://a1.easemob.com/easemob-demo/testapp/chatgroups",
"entities": [],
"data": [
{
"owner": "easemob-demo#testapp_user1",
"groupid": "100743775617286960",
"affiliations": 2,
"type": "group",
"last_modified": "1441021038124",
"groupname": "testgroup1"
},
{
"owner": "easemob-demo#testapp_user2",
"groupid": "100973270123152176",
"affiliations": 1,
"type": "group",
"last_modified": "1441074471486",
"groupname": "testgroup2"
}
],
"timestamp": 1441094193812,
"duration": 14,
"cursor": "Y2hhdGdyb3VwczplYXNlbW9iLWRlbW8vY2hhdGRlbW91aV8z",
"count": 2
}
**返回值401,未授权[无token、token错误、token过期]**
{
"error": "group_authorization",
"timestamp": 1542359035948,
"duration": 0,
"exception": "com.easemob.group.exception.GroupAuthorizationException",
"error_description": "this token is bad, or has expired!"
}
第二页
curl -X GET -H 'Accept: application/json' -H 'Authorization: Bearer YWMt4LqJIul7EeizhBO5TSO_UgAAAAAAAAAAAAAAAAAAAAGL4CTw6XgR6LaXXVmNX4QCAgMAAAFnG7GyAQBPGgDv4ENRUku7fg05Kev0a_aVC8NyA6O6PgpxIRjajSVN3g' 'http://a1.easemob.com/easemob-demo/testapp/chatgroups?limit=2&cursor=ZGNiMjRmNGY1YjczYjlhYTNkYjk1MDY2YmEyNzFmODQ6aW06Z3JvdXA6ZWFzZW1vYi1kZW1vI3Rlc3RhcHA6Mg'
=== 可能返回的结果示例 ===
**返回值200,表示获取群组成功**
{
"action": "get",
"application": "8be024f0-e978-11e8-b697-5d598d5f8402",
"params": {
"cursor": [
"ZGNiMjRmNGY1YjczYjlhYTNkYjk1MDY2YmEyNzFmODQ6aW06Z3JvdXA6ZWFzZW1vYi1kZW1vI3Rlc3RhcHA6Mg"
],
"limit": [
"2"
]
},
"uri": "http://a1.easemob.com/easemob-demo/testapp/chatgroups",
"entities": [],
"data": [
{
"groupid": "66016467025921",
"groupname": "testgroup2",
"owner": "easemob-demo#testapp_user2",
"affiliations": 1,
"lastModified": 1542356609540,
"type": "group",
"created": 1542356609540
},
{
"groupid": "66016480657410",
"groupname": "testgroup3",
"owner": "easemob-demo#testapp_user3",
"affiliations": 1,
"lastModified": 1542356622235,
"type": "group",
"created": 1542356622235
}
],
"timestamp": 1542358693048,
"duration": 0,
"organization": "easemob-demo",
"applicationName": "testapp",
"cursor": "ZGNiMjRmNGY1YjczYjlhYTNkYjk1MDY2YmEyNzFmODQ6aW06Z3JvdXA6ZWFzZW1vYi1kZW1vI3Rlc3RhcHA6Mw",
"count": 2
}
**返回值401,未授权[无token、token错误、token过期]**
{
"error": "group_authorization",
"timestamp": 1542358868326,
"duration": 0,
"exception": "com.easemob.group.exception.GroupAuthorizationException",
"error_description": "this token is bad, or has expired!"
}
如果返回结果是429、503或者其他5xx,有可能代表该接口被限流了,请稍微暂停一下并重试。详见[[im:450errorcode:45restastrict|接口限流说明]]
[[http://api-docs.easemob.com/|使用 Easemob REST API 在线测试]]
----
==== 获取单个用户加入的所有群组(可分页) ====
根据用户名称获取该用户加入的全部群组接口。
=== HTTP Request ===
^{{:im:server:basics:get.png?nolink&90|}}^**/{org_name}/{app_name}/users/{username}/joined_chatgroups**^
需要在请求时对应填写{username},需要获取的 IM 用户名。
分页接入点:''%%https://{host}/{app_name}/users/{username}/joined_chatgroups?pagesize={}&pagenum={}'%%''
=== 路径参数 ===
^参数 ^类型 ^是否必需 ^描述 ^
|''%%host%%'' |String |必需 |你在环信即时通讯 IM 管理后台注册项目时所在的集群服务器地址。 |
|''%%org_name%%'' |String |必需 |你在环信即时通讯 IM 管理后台注册项目时填入的公司(组织)名称。 |
|''%%app_name%%'' |String |必需 |你在环信即时通讯 IM 管理后台注册项目时填入的应用名称。 |
|''%%username%%'' |String |必需 |用户 ID。 |
|''%%pagesize%%'' |String |必需 | 每页获取的群组数量。该参数仅适用于分页获取方法。|
|''%%pagenum%%'' |String |必需 | 当前页码。该参数仅适用于分页获取方法。|
=== Request Headers ===
^参数^说明^
|Content-Type|application/json|
|Authorization|Bearer ${token}|
=== Response Body ===
在返回值中查看data字段包含的信息
^参数^说明^
|groupid|群组ID|
|groupname|群组名称|
=== 请求示例 ===
curl -X GET -H 'Accept: application/json' -H 'Authorization: Bearer YWMt4LqJIul7EeizhBO5TSO_UgAAAAAAAAAAAAAAAAAAAAGL4CTw6XgR6LaXXVmNX4QCAgMAAAFnG7GyAQBPGgDv4ENRUku7fg05Kev0a_aVC8NyA6O6PgpxIRjajSVN3g' 'http://a1.easemob.com/easemob-demo/testapp/users/user1/joined_chatgroups'
分页获取示例:
curl -X GET -H 'Accept: application/json' -H 'Authorization: Bearer YWMt4LqJIul7EeizhBO5TSO_UgAAAAAAAAAAAAAAAAAAAAGL4CTw6XgR6LaXXVmNX4QCAgMAAAFnG7GyAQBPGgDv4ENRUku7fg05Kev0a_aVC8NyA6O6PgpxIRjajSVN3g' 'http://a1.easemob.com/easemob-demo/testapp/users/user1/joined_chatgroups?pagesize=1&pagenum=100'
=== 可能返回的结果示例 ===
**返回值200,表示获取群组成功**
{
"action": "get",
"application": "8be024f0-e978-11e8-b697-5d598d5f8402",
"uri": "http://a1.easemob.com/easemob-demo/testapp/users/user1/joined_chatgroups",
"entities": [],
"data": [
{
"groupid": "66016455491585",
"groupname": "testgroup1"
},
{
"groupid": "66016467025921",
"groupname": "testgroup2"
},
],
"timestamp": 1542359565885,
"duration": 1,
"organization": "easemob-demo",
"applicationName": "testapp",
"count": 2
}
**返回值404,此用户不存在**
{
"error": "resource_not_found",
"timestamp": 1542359607100,
"duration": 0,
"exception": "com.easemob.group.exception.ResourceNotFoundException",
"error_description": "username user20 doesn't exist!"
}
**返回值401,未授权[无token、token错误、token过期]**
{
"error": "group_authorization",
"timestamp": 1542359664255,
"duration": 0,
"exception": "com.easemob.group.exception.GroupAuthorizationException",
"error_description": "this token is bad, or has expired!"
}
如果返回结果是429、503或者其他5xx,有可能代表该接口被限流了,请稍微暂停一下并重试。详见[[im:450errorcode:45restastrict|接口限流说明]]
[[http://api-docs.easemob.com/|使用 Easemob REST API 在线测试]]
----
分页获取响应示例:
{
"action":"get",
"application":"8be024f0-e978-11e8-b697-5d598d5f8402",
"applicationName":"testapp",
"count":0,
"data":[
],
"duration":0,
"entities":[
],
"organization":"easemob-demo",
"params":{
"pagesize":[
"1"
],
"pagenum":[
"100"
]
},
"properties":{
},
"timestamp":1645177932072,
"uri":"http://a1.easemob.com/easemob-demo/testapp/users/user1/joined_chatgroups"
}
====获取群组详情====
可以获取一个或多个群组的详情。当获取多个群组的详情时,会返回所有存在的群组的详情,对于不存在的群组,response body内返回“group id doesn't exist”。
=== HTTP Request ===
^{{:im:server:basics:get.png?nolink&90|}}^**{org_name}/{app_name}/chatgroups/{group_ids}**^
需要在请求时对应填写{group_ids},需要获取的群组 ID 。
=== Request Headers ===
^参数^说明^
|Content-Type|application/json|
|Authorization|Bearer ${token}|
=== Response Body ===
在返回值中查看data字段包含的信息
^参数^说明^
|id|群组 ID,群组唯一标识符,由环信服务器生成,等同于单个用户的环信 ID。|
|name|群组名称,根据用户输入创建,字符串类型。|
|description|群组描述,根据用户输入创建,字符串类型。|
|membersonly|加入群组是否需要群主或者群管理员审批。true:是,false:否。|
|allowinvites|是否允许群成员邀请别人加入此群。 true:允许群成员邀请人加入此群,false:只有群主才可以往群里加人。|
|maxusers|群成员上限,创建群组的时候设置,可修改。|
|owner|群主的环信 ID。例如:{“owner”: “user1”}。|
|created|创建该群组的时间戳|
|affiliations_count|现有成员总数。|
|affiliations|现有成员列表,包含了 owner 和 member。例如:“affiliations”:[{“owner”: “user1”},{“member”:“user2”},{“member”:“user3”}]。|
|public|群组类型:true:公开群,false:私有群。|
=== 请求示例 ===
curl -X GET -H 'Accept: application/json' -H 'Authorization: Bearer YWMt4LqJIul7EeizhBO5TSO_UgAAAAAAAAAAAAAAAAAAAAGL4CTw6XgR6LaXXVmNX4QCAgMAAAFnG7GyAQBPGgDv4ENRUku7fg05Kev0a_aVC8NyA6O6PgpxIRjajSVN3g' 'http://a1.easemob.com/easemob-demo/testapp/chatgroups/66016455491585'
=== 可能返回的结果示例 ===
**返回值200,表示获取群组详情成功**
{
"action": "get",
"application": "8be024f0-e978-11e8-b697-5d598d5f8402",
"uri": "http://a1.easemob.com/easemob-demo/testapp/chatgroups/66016455491585",
"entities": [],
"data": [
{
"id": "66016455491585",
"name": "testgroup1",
"description": "testgroup1",
"membersonly": false,
"allowinvites": false,
"maxusers": 200,
"owner": "user1",
"created": 1542356598609,
"custom": "",
"affiliations_count": 3,
"affiliations": [
{
"member": "user3"
},
{
"member": "user2"
},
{
"owner": "user1"
}
],
"public": true
}
],
"timestamp": 1542360200677,
"duration": 0,
"organization": "easemob-demo",
"applicationName": "testapp",
"count": 1
}
**返回值404,表示此群组ID不存在**
{
"error": "service_resource_not_found",
"timestamp": 1542360292539,
"duration": 0,
"exception": "com.easemob.group.exception.ServiceResourceNotFoundException",
"error_description": "do not find this group:6601645549158"
}
**返回值401,未授权[无token、token错误、token过期]**
{
"error": "group_authorization",
"timestamp": 1542360340446,
"duration": 0,
"exception": "com.easemob.group.exception.GroupAuthorizationException",
"error_description": "this token is bad, or has expired!"
}
如果返回结果是429、503或者其他5xx,有可能代表该接口被限流了,请稍微暂停一下并重试。详见[[im:450errorcode:45restastrict|接口限流说明]]
[[http://api-docs.easemob.com/|使用 Easemob REST API 在线测试]]
----
====创建一个群组====
创建一个群组,并设置群组名称、群组描述、公开群/私有群属性、群成员最大人数(包括群主)、加入公开群是否需要批准、群主、群成员、群组扩展信息。
=== HTTP Request ===
^{{:im:server:basics:post.png?nolink&90|}}^**{org_name}/{app_name}/chatgroups**^
=== Request Headers ===
^参数^说明^
|Content-Type|application/json|
|Authorization|Bearer ${token}|
=== Request Body ===
^参数^说明^
|groupname|群组名称,此属性为必须的,最大长度为128字符|
|desc|群组描述,此属性为必须的,最大长度为512字符|
|public|是否是公开群,此属性为必须的|
|maxusers|群组成员最大数(包括群主),值为数值类型,默认值200,具体上限请参考不同版本[[http://www.easemob.com/pricing/im|数量]]|
|allowinvites|是否允许群成员邀请别人加入此群。 true:允许群成员邀请人加入此群,false:只有群主或者管理员才可以往群里加人。注:如果是公开群(public为true),则不允许群成员邀请别人加入此群|
|members_only|用户申请入群是否需要群主或者群管理员审批,默认是false。注:如果允许了群成员邀请用户进群(allowinvites为true),那么就不需要群主或群管理员审批了|
|owner|群组的管理员,此属性为必须的|
|members|群组成员,此属性为可选的,但是如果加了此项,数组元素至少一个,不能超过100个(注:群主user1不需要写入到members里面)|
|custom|群组扩展信息,例如可以给群组添加业务相关的标记,不要超过1024字符|
=== Response Body ===
在返回值中查看data字段包含的信息
^参数^说明^
|groupid|群组ID|
=== 请求示例 ===
curl -X POST -H 'Content-Type: application/json' -H 'Accept: application/json' -H 'Authorization: Bearer YWMt4LqJIul7EeizhBO5TSO_UgAAAAAAAAAAAAAAAAAAAAGL4CTw6XgR6LaXXVmNX4QCAgMAAAFnG7GyAQBPGgDv4ENRUku7fg05Kev0a_aVC8NyA6O6PgpxIRjajSVN3g' -d '{
"groupname": "testgroup",
"desc": "test",
"public": true,
"maxusers": 300,
"owner": "testuser",
"members": [
"user2"
]
}' 'http://a1.easemob.com/easemob-demo/testapp/chatgroups'
=== 可能返回的结果示例 ===
**返回值200,表示群组创建成功**
{
"action": "post",
"application": "8be024f0-e978-11e8-b697-5d598d5f8402",
"uri": "http://a1.easemob.com/easemob-demo/testapp/chatgroups",
"entities": [],
"data": {
"groupid": "66021836783617"
},
"timestamp": 1542361730243,
"duration": 0,
"organization": "easemob-demo",
"applicationName": "testapp"
}
**返回值404,owner用户不存在**
{
"error": "resource_not_found",
"timestamp": 1542361812517,
"duration": 0,
"exception": "com.easemob.group.exception.ResourceNotFoundException",
"error_description": "username tesuser doesn't exist!"
}
**返回值401,未授权[无token、token错误、token过期]**
{
"error": "resource_not_found",
"timestamp": 1542361812517,
"duration": 0,
"exception": "com.easemob.group.exception.ResourceNotFoundException",
"error_description": "username tesuser doesn't exist!"
}
如果返回结果是429、503或者其他5xx,有可能代表该接口被限流了,请稍微暂停一下并重试。详见[[im:450errorcode:45restastrict|接口限流说明]]
[[http://api-docs.easemob.com/|使用 Easemob REST API 在线测试]]
----
====修改群组信息====
修改成功的数据行会返回 true,失败为 false。请求 body 只接收 groupname、description、maxusers、membersonly、allowinvites、custom 六个属性,传不存在的字段,或者不能修改的字段会抛异常。
=== HTTP Request ===
^{{:im:server:basics:put.png?nolink&90|}}^**/{org_name}/{app_name}/chatgroups/{group_id}**^
需要在请求时对应填写{group_id},需要修改的群组 ID 。
=== Request Headers ===
^参数^说明^
|Content-Type|application/json|
|Authorization|Bearer ${token}|
=== Request Body ===
^参数^说明^
|groupname|群组名称,修改时值不能包含斜杠("/"),最大长度为128字符。|
|description|群组描述,修改时值不能包含斜杠("/"),最大长度为512字符。|
|maxusers|群组成员最大数(包括群主),值为数值类型。|
|membersonly|加入群组是否需要群主或者群管理员审批。true:是,false:否。|
|allowinvites|是否允许群成员邀请别人加入此群。 true:允许群成员邀请人加入此群,false:只有群主才可以往群里加人。|
|custom|群组扩展信息,例如可以给群组添加业务相关的标记,不要超过1024字符。|
=== Response Body ===
在返回值中查看data字段包含的信息
^参数^说明^
|description|群组描述,true表示修改成功,false表示修改失败|
|maxusers|群组成员最大数,true表示修改成功,false表示修改失败|
|groupname|群组名称,true表示修改成功,false表示修改失败|
|membersonly|加入群组是否需要群主或者群管理员审批。true:是,false:否。|
|allowinvites|是否允许群成员邀请别人加入此群。 true:允许群成员邀请人加入此群,false:只有群主才可以往群里加人。|
=== 请求示例 ===
curl -X PUT -H 'Content-Type: application/json' -H 'Accept: application/json' -H 'Authorization: Bearer YWMt4LqJIul7EeizhBO5TSO_UgAAAAAAAAAAAAAAAAAAAAGL4CTw6XgR6LaXXVmNX4QCAgMAAAFnG7GyAQBPGgDv4ENRUku7fg05Kev0a_aVC8NyA6O6PgpxIRjajSVN3g' -d '{
"groupname": "testgroup1",
"description": "test",
"maxusers": 300,
"membersonly": true,
"allowinvites": true
}' 'http://a1.easemob.com/easemob-demo/testapp/chatgroups/66021836783617'
=== 可能返回的结果示例 ===
**返回值200,表示群组信息修改成功**
{
"action": "put",
"application": "8be024f0-e978-11e8-b697-5d598d5f8402",
"uri": "http://a1.easemob.com/easemob-demo/testapp/chatgroups/66021836783617",
"entities": [],
"data": {
"membersonly": true,
"allowinvites": true,
"description": true,
"maxusers": true,
"groupname": true
},
"timestamp": 1542363146301,
"duration": 0,
"organization": "easemob-demo",
"applicationName": "testapp"
}
**返回值404,群组ID不存在**
{
"error": "resource_not_found",
"timestamp": 1542363205192,
"duration": 0,
"exception": "com.easemob.group.exception.ResourceNotFoundException",
"error_description": "grpID 6602183678361 does not exist!"
}
**返回值401,未授权[无token、token错误、token过期]**
{
"error": "group_authorization",
"timestamp": 1542363254128,
"duration": 0,
"exception": "com.easemob.group.exception.GroupAuthorizationException",
"error_description": "this token is bad, or has expired!"
}
如果返回结果是429、503或者其他5xx,有可能代表该接口被限流了,请稍微暂停一下并重试。详见[[im:450errorcode:45restastrict|接口限流说明]]
[[http://api-docs.easemob.com/|使用 Easemob REST API 在线测试]]
----
====删除群组====
删除一个群组的接口。
=== HTTP Request ===
^{{:im:server:basics:delete.png?nolink&90|}}^**/{org_name}/{app_name}/chatgroups/{group_id}**^
需要在请求时对应填写{group_id},需要删除的群组 ID 。
=== Request Headers ===
^参数^说明^
|Content-Type|application/json|
|Authorization|Bearer ${token}|
=== 请求示例 ===
curl -X DELETE -H 'Accept: application/json' -H 'Authorization: Bearer YWMt4LqJIul7EeizhBO5TSO_UgAAAAAAAAAAAAAAAAAAAAGL4CTw6XgR6LaXXVmNX4QCAgMAAAFnG7GyAQBPGgDv4ENRUku7fg05Kev0a_aVC8NyA6O6PgpxIRjajSVN3g' 'http://a1.easemob.com/easemob-demo/testapp/chatgroups/66021836783617'
=== 可能返回的结果示例 ===
**返回值200,表示群组删除成功**
{
"action": "delete",
"application": "8be024f0-e978-11e8-b697-5d598d5f8402",
"uri": "http://a1.easemob.com/easemob-demo/testapp/chatgroups/66021836783617",
"entities": [],
"data": {
"success": true,
"groupid": "66021836783617"
},
"timestamp": 1542363546590,
"duration": 0,
"organization": "easemob-demo",
"applicationName": "testapp"
}
**返回值404,群组ID不存在**
{
"error": "resource_not_found",
"timestamp": 1542363611915,
"duration": 0,
"exception": "com.easemob.group.exception.ResourceNotFoundException",
"error_description": "grpID 6602183678361 does not exist!"
}
**返回值401,未授权[无token、token错误、token过期]**
{
"error": "group_authorization",
"timestamp": 1542363640975,
"duration": 0,
"exception": "com.easemob.group.exception.GroupAuthorizationException",
"error_description": "this token is bad, or has expired!"
}
如果返回结果是429、503或者其他5xx,有可能代表该接口被限流了,请稍微暂停一下并重试。详见[[im:450errorcode:45restastrict|接口限流说明]]
[[http://api-docs.easemob.com/|使用 Easemob REST API 在线测试]]
----
====获取群组公告====
获取指定群组id的群组公告
=== HTTP Request ===
^{{:im:server:basics:get.png?nolink&90|}}^**/{org_name}/{app_name}/chatgroups/{group_id}/announcement**^
需要在请求时对应填写{group_id},需要获取群组公告的群组 ID 。
=== Request Headers ===
^参数^说明^
|Content-Type|application/json|
|Authorization|Bearer ${token}|
=== 请求示例 ===
curl -X GET -H 'Content-Type: application/json' -H 'Accept: application/json' -H 'Authorization: Bearer YWMt4LqJIul7EeizhBO5TSO_UgAAAAAAAAAAAAAAAAAAAAGL4CTw6XgR6LaXXVmNX4QCAgMAAAFnG7GyAQBPGgDv4ENRUku7fg05Kev0a_aVC8NyA6O6PgpxIRjajSVN3g' 'http://a1.easemob.com/easemob-demo/testapp/chatgroups/66021836783617/announcement'
=== 可能返回的结果示例 ===
**返回值200,表示获取群组公告成功**
{
"action": "get",
"application": "8be024f0-e978-11e8-b697-5d598d5f8402",
"uri": "http://a1.easemob.com/easemob-demo/testapp/chatgroups/66021836783617/announcement",
"entities": [],
"data": {
"announcement" : "群组公告..."
},
"timestamp": 1542363546590,
"duration": 0,
"organization": "easemob-demo",
"applicationName": "testapp"
}
**返回值404,群组ID不存在**
{
"error": "resource_not_found",
"timestamp": 1542363611915,
"duration": 0,
"exception": "com.easemob.group.exception.ResourceNotFoundException",
"error_description": "grpID 6602183678361 does not exist!"
}
**返回值401,未授权[无token、token错误、token过期]**
{
"error": "group_authorization",
"timestamp": 1542363640975,
"duration": 0,
"exception": "com.easemob.group.exception.GroupAuthorizationException",
"error_description": "this token is bad, or has expired!"
}
如果返回结果是429、503或者其他5xx,有可能代表该接口被限流了,请稍微暂停一下并重试。详见[[im:450errorcode:45restastrict|接口限流说明]]
[[http://api-docs.easemob.com/|使用 Easemob REST API 在线测试]]
----
====修改群组公告====
修改指定群组id的群组公告,注意群组公告的内容不能超过512个字符。
=== HTTP Request ===
^{{:im:server:basics:post.png?nolink&90|}}^**/{org_name}/{app_name}/chatgroups/{group_id}/announcement**^
需要在请求时对应填写{group_id},需要修改群组公告的群组 ID 。
=== Request Headers ===
^参数^说明^
|Content-Type|application/json|
|Authorization|Bearer ${token}|
=== 请求示例 ===
curl -X POST -H 'Content-Type: application/json' -H 'Accept: application/json' -H 'Authorization: Bearer YWMt4LqJIul7EeizhBO5TSO_UgAAAAAAAAAAAAAAAAAAAAGL4CTw6XgR6LaXXVmNX4QCAgMAAAFnG7GyAQBPGgDv4ENRUku7fg05Kev0a_aVC8NyA6O6PgpxIRjajSVN3g' -d '{"announcement" : "群组公告…"}' 'http://a1.easemob.com/easemob-demo/testapp/chatgroups/66021836783617/announcement'
=== 可能返回的结果示例 ===
**返回值200,表示修改群组公告成功**
{
"action": "post",
"application": "8be024f0-e978-11e8-b697-5d598d5f8402",
"uri": "http://a1.easemob.com/easemob-demo/testapp/chatgroups/66021836783617/announcement",
"entities": [],
"data": {
"id" : "66021836783617",
"result" : true
},
"timestamp": 1542363546590,
"duration": 0,
"organization": "easemob-demo",
"applicationName": "testapp"
}
**返回值404,群组ID不存在**
{
"error": "resource_not_found",
"timestamp": 1542363611915,
"duration": 0,
"exception": "com.easemob.group.exception.ResourceNotFoundException",
"error_description": "grpID 6602183678361 does not exist!"
}
**返回值401,未授权[无token、token错误、token过期]**
{
"error": "group_authorization",
"timestamp": 1542363640975,
"duration": 0,
"exception": "com.easemob.group.exception.GroupAuthorizationException",
"error_description": "this token is bad, or has expired!"
}
如果返回结果是429、503或者其他5xx,有可能代表该接口被限流了,请稍微暂停一下并重试。详见[[im:450errorcode:45restastrict|接口限流说明]]
[[http://api-docs.easemob.com/|使用 Easemob REST API 在线测试]]
----
====获取群组共享文件====
分页获取指定群组id的群组共享文件,之后可以根据response中返回的file_id,file_id是群组共享文件的唯一标识,调用 [[http://docs-im.easemob.com/im/server/basics/group#%E4%B8%8B%E8%BD%BD%E7%BE%A4%E7%BB%84%E5%85%B1%E4%BA%AB%E6%96%87%E4%BB%B6|下载群共享文件]] 接口下载文件,调用 [[http://docs-im.easemob.com/im/server/basics/group#%E5%88%A0%E9%99%A4%E7%BE%A4%E7%BB%84%E5%85%B1%E4%BA%AB%E6%96%87%E4%BB%B6|删除群共享文件]] 接口删除文件。
=== HTTP Request ===
^{{:im:server:basics:get.png?nolink&90|}}^**/{org_name}/{app_name}/chatgroups/{group_id}/share_files**^
需要在请求时对应填写{group_id},需要获取群组共享文件的群组 ID ,默认是从第1页开始获取,1页最多可以获取1000条
^分页 ^**{org_name}/{app_name}/chatgroups/{group_id}/share_files?pagenum=1&pagesize=10**^
=== Request Headers ===
^参数^说明^
|Content-Type|application/json|
|Authorization|Bearer ${token}|
=== Response Body ===
在返回值中查看data字段包含的信息
^参数^说明^
|file_id|群组共享文件的id,如果要下载该文件需要使用到这个file_id|
|file_name|群组共享文件名称|
|file_owner|上传群组共享文件的用户id|
|file_size|群组共享文件大小(字节)|
|created|上传群组共享文件的时间|
=== 请求示例 ===
curl -X GET -H 'Content-Type: application/json' -H 'Accept: application/json' -H 'Authorization: Bearer YWMt4LqJIul7EeizhBO5TSO_UgAAAAAAAAAAAAAAAAAAAAGL4CTw6XgR6LaXXVmNX4QCAgMAAAFnG7GyAQBPGgDv4ENRUku7fg05Kev0a_aVC8NyA6O6PgpxIRjajSVN3g' 'http://a1.easemob.com/easemob-demo/testapp/chatgroups/66021836783617/share_files?pagenum=1&pagesize=10'
=== 可能返回的结果示例 ===
**返回值200,表示获取群组共享文件成功**
{
"action": "get",
"application": "8be024f0-e978-11e8-b697-5d598d5f8402",
"params": {
"pagesize": [
"10"
],
"pagenum": [
"1"
]
},
"uri": "http://a1.easemob.com/easemob-demo/testapp/chatgroups/66021836783617/share_files",
"entities": [],
"data": [
{
"file_id": "dbd88d20-e1d4-11ea-95fc-638fc2d59a8d",
"file_name": "159781149272586.jpg",
"file_owner": "u1",
"file_size": 326127,
"created": 1597811492594
},
{
"file_id": "b30e0be0-e1d4-11ea-8732-172a3f85134f",
"file_name": "159781141836993.jpg",
"file_owner": "u1",
"file_size": 326127,
"created": 1597811424158
}
],
"timestamp": 1542363546590,
"duration": 0,
"organization": "easemob-demo",
"applicationName": "testapp"
}
**返回值404,群组ID不存在**
{
"error": "resource_not_found",
"timestamp": 1542363611915,
"duration": 0,
"exception": "com.easemob.group.exception.ResourceNotFoundException",
"error_description": "grpID 6602183678361 does not exist!"
}
**返回值401,未授权[无token、token错误、token过期]**
{
"error": "group_authorization",
"timestamp": 1542363640975,
"duration": 0,
"exception": "com.easemob.group.exception.GroupAuthorizationException",
"error_description": "this token is bad, or has expired!"
}
如果返回结果是429、503或者其他5xx,有可能代表该接口被限流了,请稍微暂停一下并重试。详见[[im:450errorcode:45restastrict|接口限流说明]]
[[http://api-docs.easemob.com/|使用 Easemob REST API 在线测试]]
----
====上传群组共享文件====
上传指定群组id的群组共享文件。注意上传的文件大小不能超过10MB
=== HTTP Request ===
^{{:im:server:basics:post.png?nolink&90|}}^**/{org_name}/{app_name}/chatgroups/{group_id}/share_files**^
需要在请求时对应填写{group_id},需要上传群组共享文件的群组 ID。
=== Request Headers ===
^参数^说明^
|Content-Type|application/json|
|Authorization|Bearer ${token}|
=== Response Body ===
在返回值中查看data字段包含的信息
^参数^说明^
|file_url|群组共享文件的url,在环信服务器上保存的地址|
|group_id|群组id|
|file_name|群组共享文件名称|
|created|上传群组共享文件的时间|
|file_id|群组共享文件id,可以用于下载共享文件和删除共享文件|
|file_size|群组共享文件大小(字节)|
=== 请求示例 ===
curl -X POST 'http://a1.easemob.com/easemob-demo/testapp/chatgroups/66021836783617/share_files' -H 'Content-Type: application/json' -H 'Authorization: Bearer YWMt4LqJIul7EeizhBO5TSO_UgAAAAAAAAAAAAAAAAAAAAGL4CTw6XgR6LaXXVmNX4QCAgMAAAFnG7GyAQBPGgDv4ENRUku7fg05Kev0a_aVC8NyA6O6PgpxIRjajSVN3g' -H 'content-type: multipart/form-data; boundary=----WebKitFormBoundary7MA4YWxkTrZu0gW' -H 'restrict-access: true' -F file=@/Users/test/image/IMG_3.JPG
=== 可能返回的结果示例 ===
**返回值200,表示上传群组共享文件**
{
"action" : "post",
"application" : "7f7b5180-3f2b-11e5-9558-092397c841ef",
"uri" : "http://a1.easemob.com/easemob-demo/testapp/chatgroups/66021836783617/share_files",
"entities" : [ ],
"data" : {
"file_url" : "https://a1.easemob.com/easemob-demo/testapp/chatgroups/66021836783617/share_files/c6906aa0-ed19-11ea-b480-f3cf141d15c0",
"group_id" : "66021836783617",
"file_name" : "img_3.jpg",
"created" : 1599050554954,
"file_id" : "c6906aa0-ed19-11ea-b480-f3cf141d15c0",
"file_size" : 13512
},
"timestamp" : 1599050554978,
"duration" : 0,
"organization" : "easemob-demo",
"applicationName" : "testapp"
}
**返回值404,群组ID不存在**
{
"error": "resource_not_found",
"timestamp": 1542363611915,
"duration": 0,
"exception": "com.easemob.group.exception.ResourceNotFoundException",
"error_description": "grpID 6602183678361 does not exist!"
}
**返回值401,未授权[无token、token错误、token过期]**
{
"error": "group_authorization",
"timestamp": 1542363640975,
"duration": 0,
"exception": "com.easemob.group.exception.GroupAuthorizationException",
"error_description": "this token is bad, or has expired!"
}
如果返回结果是429、503或者其他5xx,有可能代表该接口被限流了,请稍微暂停一下并重试。详见[[im:450errorcode:45restastrict|接口限流说明]]
[[http://api-docs.easemob.com/|使用 Easemob REST API 在线测试]]
----
====下载群组共享文件====
根据指定的群组id与file_id下载群组共享文件,file_id是通过 [[http://docs-im.easemob.com/im/server/basics/group#%E8%8E%B7%E5%8F%96%E7%BE%A4%E7%BB%84%E5%85%B1%E4%BA%AB%E6%96%87%E4%BB%B6|获取群组共享文件]] 接口获取到的
=== HTTP Request ===
^{{:im:server:basics:get.png?nolink&90|}}^**/{org_name}/{app_name}/chatgroups/{group_id}/share_files/{file_id}**^
需要在请求时对应填写{group_id}和{file_id},需要下载群组共享文件的群组 ID和群组共享文件 ID 。
=== Request Headers ===
^参数^说明^
|Content-Type|application/json|
|Authorization|Bearer ${token}|
=== 请求示例 ===
curl -X GET -H 'Content-Type: application/json' -H 'Accept: application/json' -H 'Authorization: Bearer YWMt4LqJIul7EeizhBO5TSO_UgAAAAAAAAAAAAAAAAAAAAGL4CTw6XgR6LaXXVmNX4QCAgMAAAFnG7GyAQBPGgDv4ENRUku7fg05Kev0a_aVC8NyA6O6PgpxIRjajSVN3g' 'http://a1.easemob.com/easemob-demo/testapp/chatgroups/66021836783617/share_files/b30e0be0-e1d4-11ea-8732-172a3f85134f'
=== 可能返回的结果示例 ===
**返回值200,表示下载群组共享文件成功,返回的是下载文件的字节流**
**返回值404,群组共享文件ID不存在**
{
"error": "not_found",
"timestamp": 1542363611915,
"duration": 0,
"exception": "com.sun.jersey.api.NotFoundException",
"error_description": "null for uri: http://a1.easemob.com/easemob-demo/testapp/chatgroups/66021836783617/share_files/1b30e0be0-e1d4-11ea-8732-172a3f85134f"
}
**返回值401,未授权[无token、token错误、token过期]**
{
"error": "group_authorization",
"timestamp": 1542363640975,
"duration": 0,
"exception": "com.easemob.group.exception.GroupAuthorizationException",
"error_description": "this token is bad, or has expired!"
}
如果返回结果是429、503或者其他5xx,有可能代表该接口被限流了,请稍微暂停一下并重试。详见[[im:450errorcode:45restastrict|接口限流说明]]
[[http://api-docs.easemob.com/|使用 Easemob REST API 在线测试]]
----
====删除群组共享文件====
根据指定的群组id与file_id删除群组共享文件,file_id是通过 [[http://docs-im.easemob.com/im/server/basics/group#%E8%8E%B7%E5%8F%96%E7%BE%A4%E7%BB%84%E5%85%B1%E4%BA%AB%E6%96%87%E4%BB%B6|获取群组共享文件]] 接口获取到的
=== HTTP Request ===
^{{:im:server:basics:delete.png?nolink&90|}}^**/{org_name}/{app_name}/chatgroups/{group_id}/share_files/{file_id}**^
需要在请求时对应填写{group_id}和{file_id},需要删除群组共享文件的群组 ID和群组共享文件 ID 。
=== Request Headers ===
^参数^说明^
|Content-Type|application/json|
|Authorization|Bearer ${token}|
=== Response Body ===
在返回值中查看data字段包含的信息
^参数^说明^
|group_id|群组id|
|file_id|群组共享文件id|
|result|删除群组共享文件的结果,true代表删除成功,false代表删除失败|
=== 请求示例 ===
curl -X DELETE -H 'Content-Type: application/json' -H 'Accept: application/json' -H 'Authorization: Bearer YWMt4LqJIul7EeizhBO5TSO_UgAAAAAAAAAAAAAAAAAAAAGL4CTw6XgR6LaXXVmNX4QCAgMAAAFnG7GyAQBPGgDv4ENRUku7fg05Kev0a_aVC8NyA6O6PgpxIRjajSVN3g' 'http://a1.easemob.com/easemob-demo/testapp/chatgroups/66021836783617/share_files/b30e0be0-e1d4-11ea-8732-172a3f85134f'
=== 可能返回的结果示例 ===
**返回值200,表示删除群组共享文件**
{
"action": "delete",
"application": "8be024f0-e978-11e8-b697-5d598d5f8402",
"uri": "http://a1.easemob.com/easemob-demo/testapp/chatgroups/66021836783617/share_files/b30e0be0-e1d4-11ea-8732-172a3f85134f",
"entities": [],
"data": {
"group_id": "66021836783617",
"file_id": "b30e0be0-e1d4-11ea-8732-172a3f85134f",
"result": true
},
"timestamp": 1599049350114,
"duration": 0,
"organization": "easemob-demo",
"applicationName": "testapp"
}
**返回值404,群组共享文件ID不存在**
{
"error": "not_found",
"timestamp": 1542363611915,
"duration": 0,
"exception": "com.sun.jersey.api.NotFoundException",
"error_description": "null for uri: http://a1.easemob.com/easemob-demo/testapp/chatgroups/66021836783617/share_files/1b30e0be0-e1d4-11ea-8732-172a3f85134f"
}
**返回值401,未授权[无token、token错误、token过期]**
{
"error": "group_authorization",
"timestamp": 1542363640975,
"duration": 0,
"exception": "com.easemob.group.exception.GroupAuthorizationException",
"error_description": "this token is bad, or has expired!"
}
如果返回结果是429、503或者其他5xx,有可能代表该接口被限流了,请稍微暂停一下并重试。详见[[im:450errorcode:45restastrict|接口限流说明]]
[[http://api-docs.easemob.com/|使用 Easemob REST API 在线测试]]
----
=====管理群组成员=====
环信提供多个接口实现对群组成员的管理,包括添加、移除群组成员关系列表,转让群主等
^名称^请求^描述^
|分页获取群组成员|/{org_name}/{app_name}/chatgroups/{group_id}/users|分页获取一个群组的群成员列表|
|添加单个群组成员|/{org_name}/{app_name}/chatgroups/{group_id}/users/{username}|添加用户至群组成员列表|
|批量添加群组成员|/{org_name}/{app_name}/chatgroups/{chatgroupid}/users|批量添加用户至群组成员列表|
|移除单个群组成员|/{org_name}/{app_name}/chatgroups/{group_id}/users/{username}|从群组成员列表中移除用户|
|批量移除群组成员|/{org_name}/{app_name}/chatgroups/{group_id}/users/{usernames}|从群组成员列表中批量移除用户|
|获取群管理员列表|/{org_name}/{app_name}/chatgroups/{group_id}/admin|获取群组管理员列表|
|添加群管理员|/{org_name}/{app_name}/chatgroups/{group_id}/admin|添加用户至群组管理员列表|
|移除群管理员|/{org_name}/{app_name}/chatgroups/{group_id}/admin/{oldadmin}|从群组管理员列表中移除用户|
|转让群组|/{org_name}/{app_name}/chatgroups/{groupid}|转让群组owner|
====分页获取群组成员====
可以分页获取群组成员列表的接口。
=== HTTP Request ===
^{{:im:server:basics:get.png?nolink&90|}}^**/{org_name}/{app_name}/chatgroups/{group_id}/users**^
需要在请求时对应填写{group_id},需要获取的群组 ID 。
=== Request Headers ===
^参数^说明^
|Content-Type|application/json|
|Authorization|Bearer ${token}|
=== Response Body ===
在返回值中查看data字段包含的信息。
^参数^说明^
|owner|群主的环信 ID。例如:{“owner”: “user1”}。|
|member|群成员的环信 ID。例如:{“member”:“user2”}。|
=== 请求示例 ===
curl -X GET HTTP://a1.easemob.com/easemob-demo/testapp/chatgroups/10130212061185/users?pagenum=2&pagesize=2 -H 'Authorization: Bearer YWMtG4T5wkOTEeST5V-9lp7f-wAAAUnafsqrQFnCU4gI0-rQImw4523fWqIasd1'
=== 可能返回的结果示例 ===
**返回值200,表示群组成员获取成功**
{
"action": "get",
"application": "527cd7e0-04b3-11e7-9f59-ef10ecd81ff0",
"params": {
"pagesize": [
"2"
],
"pagenum": [
"2"
]
},
"uri": "http://a1.easemob.com/easemob-demo/testapp/chatgroups/10130212061185/users",
"entities": [],
"data": [
{
"member": "user1"
},
{
"member": "user2"
}
],
"timestamp": 1489074511416,
"duration": 0,
"organization": "easemob-demo",
"applicationName": "testapp",
"count": 2
}
**返回值404,群组ID不存在**
{
"error": "service_resource_not_found",
"timestamp": 1542364673829,
"duration": 0,
"exception": "com.easemob.group.exception.ServiceResourceNotFoundException",
"error_description": "do not find this group:66016455491581"
}
**返回值401,未授权[无token、token错误、token过期]**
{
"error": "group_authorization",
"timestamp": 1542364697076,
"duration": 0,
"exception": "com.easemob.group.exception.GroupAuthorizationException",
"error_description": "this token is bad, or has expired!"
}
如果返回结果是429、503或者其他5xx,有可能代表该接口被限流了,请稍微暂停一下并重试。详见[[im:450errorcode:45restastrict|接口限流说明]]
[[http://api-docs.easemob.com/|使用 Easemob REST API 在线测试]]
----
====添加单个群组成员====
一次给群添加一个成员,不同重复添加同一个成员。如果用户已经是群成员,将添加失败,并返回错误。
=== HTTP Request ===
^{{:im:server:basics:post.png?nolink&90|}}^**/{org_name}/{app_name}/chatgroups/{group_id}/users/{username}**^
需要在请求时对应填写{username},需要添加的 IM 用户名。
=== Request Headers ===
^参数^说明^
|Content-Type|application/json|
|Authorization|Bearer ${token}|
=== Response Body ===
在返回值中查看data字段包含的信息。
^参数^说明^
|result|添加结果,true表示添加成功,false表示添加失败|
|groupid|群组 ID |
|action|执行的操作|
|user|被添加的用户 ID |
=== 请求示例 ===
curl -X POST -H 'Content-Type: application/json' -H 'Accept: application/json' -H 'Authorization: Bearer YWMt4LqJIul7EeizhBO5TSO_UgAAAAAAAAAAAAAAAAAAAAGL4CTw6XgR6LaXXVmNX4QCAgMAAAFnG7GyAQBPGgDv4ENRUku7fg05Kev0a_aVC8NyA6O6PgpxIRjajSVN3g' 'http://a1.easemob.com/easemob-demo/testapp/chatgroups/66016455491585/users/user4'
=== 可能返回的结果示例 ===
**返回值200,表示添加群组成员成功**
{
"action": "post",
"application": "8be024f0-e978-11e8-b697-5d598d5f8402",
"uri": "http://a1.easemob.com/easemob-demo/testapp/chatgroups/66016455491585/users/user4",
"entities": [],
"data": {
"result": true,
"groupid": "66016455491585",
"action": "add_member",
"user": "user4"
},
"timestamp": 1542364958405,
"duration": 0,
"organization": "easemob-demo",
"applicationName": "testapp"
}
**返回值404,此群组id或被添加的人不存在**
{
"error": "resource_not_found",
"timestamp": 1542365038436,
"duration": 0,
"exception": "com.easemob.group.exception.ResourceNotFoundException",
"error_description": "username user8 doesn't exist!"
}
**返回值401,未授权[无token、token错误、token过期]**
{
"error": "group_authorization",
"timestamp": 1542365096789,
"duration": 0,
"exception": "com.easemob.group.exception.GroupAuthorizationException",
"error_description": "this token is bad, or has expired!"
}
如果返回结果是429、503或者其他5xx,有可能代表该接口被限流了,请稍微暂停一下并重试。详见[[im:450errorcode:45restastrict|接口限流说明]]
[[http://api-docs.easemob.com/|使用 Easemob REST API 在线测试]]
----
====批量添加群组成员====
为群组添加多个成员,一次最多可以添加60位成员。如果所有用户均已是群成员,将添加失败,并返回错误。
=== HTTP Request ===
^{{:im:server:basics:post.png?nolink&90|}}^**/{org_name}/{app_name}/chatgroups/{chatgroupid}/users**^
需要在请求时对应填写{chatgroupid},需要添加的群组 ID 。
=== Request Headers ===
^参数^说明^
|Content-Type|application/json|
|Authorization|Bearer ${token}|
=== Request Body ===
^参数^说明^
|usernames|username1/username2 要添加到群中的成员用户名|
=== Response Body ===
在返回值中查看data字段包含的信息。
^参数^说明^
|newmembers|添加的群组成员 ID |
|groupid|群组 ID |
|action|执行的操作|
=== 请求示例 ===
curl -X POST -H 'Content-Type: application/json' -H 'Accept: application/json' -H 'Authorization: Bearer YWMt4LqJIul7EeizhBO5TSO_UgAAAAAAAAAAAAAAAAAAAAGL4CTw6XgR6LaXXVmNX4QCAgMAAAFnG7GyAQBPGgDv4ENRUku7fg05Kev0a_aVC8NyA6O6PgpxIRjajSVN3g' -d '{
"usernames": [
"user4","user5"
]
}' 'http://a1.easemob.com/easemob-demo/testapp/chatgroups/66016455491585/users'
=== 可能返回的结果示例 ===
**返回值200,表示添加群组成员成功**
{
"action": "post",
"application": "8be024f0-e978-11e8-b697-5d598d5f8402",
"uri": "http://a1.easemob.com/easemob-demo/testapp/chatgroups/66016455491585/users",
"entities": [],
"data": {
"newmembers": [
"user5",
"user4"
],
"groupid": "66016455491585",
"action": "add_member"
},
"timestamp": 1542365557942,
"duration": 0,
"organization": "easemob-demo",
"applicationName": "testapp"
}
**返回值404,此群组ID或被添加的人不存在**
{
"error": "resource_not_found",
"timestamp": 1542365626633,
"duration": 0,
"exception": "com.easemob.group.exception.ResourceNotFoundException",
"error_description": "grpID 6601645549158 does not exist!"
}
**返回值401,未授权[无token、token错误、token过期]**
{
"error": "group_authorization",
"timestamp": 1542365740570,
"duration": 0,
"exception": "com.easemob.group.exception.GroupAuthorizationException",
"error_description": "this token is bad, or has expired!"
}
如果返回结果是429、503或者其他5xx,有可能代表该接口被限流了,请稍微暂停一下并重试。详见[[im:450errorcode:45restastrict|接口限流说明]]
[[http://api-docs.easemob.com/|使用 Easemob REST API 在线测试]]
----
====移除单个群组成员====
从群中移除某个成员。如果被移除用户不是群成员,将移除失败,并返回错误。
=== HTTP Request ===
^{{:im:server:basics:delete.png?nolink&90|}}^**/{org_name}/{app_name}/chatgroups/{group_id}/users/{username}**^
需要在请求时对应填写{username},需要移除的 IM 用户名。
=== Request Headers ===
^参数^说明^
|Content-Type|application/json|
|Authorization|Bearer ${token}|
=== Response Body ===
在返回值中查看data字段包含的信息。
^参数^说明^
|result|移除结果,true表示添加成功,false表示添加失败|
|groupid|群组 ID |
|action|执行的操作|
|user|被移除的用户 ID |
=== 请求示例 ===
curl -X DELETE -H 'Accept: application/json' -H 'Authorization: Bearer YWMt4LqJIul7EeizhBO5TSO_UgAAAAAAAAAAAAAAAAAAAAGL4CTw6XgR6LaXXVmNX4QCAgMAAAFnG7GyAQBPGgDv4ENRUku7fg05Kev0a_aVC8NyA6O6PgpxIRjajSVN3g' 'http://a1.easemob.com/easemob-demo/testapp/chatgroups/66016455491585/users/user3'
=== 可能返回的结果示例 ===
**返回值200,表示群组成员移除成功**
{
"action": "delete",
"application": "8be024f0-e978-11e8-b697-5d598d5f8402",
"uri": "http://a1.easemob.com/easemob-demo/testapp/chatgroups/66016455491585/users/user3",
"entities": [],
"data": {
"result": true,
"action": "remove_member",
"user": "user3",
"groupid": "66016455491585"
},
"timestamp": 1542365943067,
"duration": 0,
"organization": "easemob-demo",
"applicationName": "testapp"
}
**返回值403,该成员不在此群组**
{
"error": "forbidden_op",
"timestamp": 1542366087574,
"duration": 0,
"exception": "com.easemob.group.exception.ForbiddenOpException",
"error_description": "users [user8] are not members of this group!"
}
**返回值404,此群组ID不存在**
{
"error": "resource_not_found",
"timestamp": 1542366050953,
"duration": 0,
"exception": "com.easemob.group.exception.ResourceNotFoundException",
"error_description": "grpID 6601645549158 does not exist!"
}
**返回值401,未授权[无token、token错误、token过期]**
{
"error": "group_authorization",
"timestamp": 1542366178894,
"duration": 0,
"exception": "com.easemob.group.exception.GroupAuthorizationException",
"error_description": "this token is bad, or has expired!"
}
如果返回结果是429、503或者其他5xx,有可能代表该接口被限流了,请稍微暂停一下并重试。详见[[im:450errorcode:45restastrict|接口限流说明]]
[[http://api-docs.easemob.com/|使用 Easemob REST API 在线测试]]
----
==== 批量移除群组成员 ====
移除群成员,用户名之间用英文逗号分隔。建议一次最多移除60个群成员。如果所有被移除用户均不是群成员,将移除失败,并返回错误。
=== HTTP Request ===
^{{:im:server:basics:delete.png?nolink&90|}}^**/{org_name}/{app_name}/chatgroups/{group_id}/users/{memebers}**^
需要在请求时对应填写{memebers},需要移除的 IM 用户名。
=== Request Headers ===
^参数^说明^
|Content-Type|application/json|
|Authorization|Bearer ${token}|
=== Response Body ===
在返回值中查看data字段包含的信息。
^参数^说明^
|result|操作结果;true:移除成功,false:移除失败|
|action|执行的操作;remove_member:移除群组成员|
|reason|操作失败的原因|
|user|被移除成员的用户名|
|groupid|操作的群组 ID |
=== 请求示例 ===
curl -X DELETE -H 'Accept: application/json' -H 'Authorization: Bearer YWMtduapFumREei8DkfcegKdAAAAAAAAAAAAAAAAAAAAAAGL4CTw6XgR6LaXXVmNX4QCAgMAAAFnHD8qUwBPGgC0sPDXWLwWYh8ObqXytVlhbUhCTnbiIPi0oNGS8j2pDg' 'http://a1.easemob.com/easemob-demo/testapp/chatgroups/66016455491585/users/ttestuser0015981,user2,user3'
=== 可能返回的结果示例 ===
**返回值200,表示群组成员移除成功**
{
"action": "delete",
"application": "9b848cf0-fafe-11e4-b5b8-0f74e8e740f7",
"uri": "https://a1.easemob.com/easemob-demo/testapp",
"entities": [],
"data": [{
"result": false,
"action": "remove_member",
"reason": "user ttestuser0015981 doesn't exist.",
"user": "user1",
"groupid": "1433492852257879"
},
{
"result": true,
"action": "remove_member",
"user": "user2",
"groupid": "1433492852257879"
},
{
"result": true,
"action": "remove_member",
"user": "user3",
"groupid": "1433492852257879"
}],
"timestamp": 1433492935318,
"duration": 84,
"organization": "easemob-demo",
"applicationName": "testapp"
}
**返回值403,该成员不在此群组**
{
"error": "forbidden_op",
"timestamp": 1542367708303,
"duration": 0,
"exception": "com.easemob.group.exception.ForbiddenOpException",
"error_description": "users [{memebers}] are not members of this group!"
}
**返回值404,此群组ID不存在**
{
"error": "resource_not_found",
"timestamp": 1542367736446,
"duration": 0,
"exception": "com.easemob.group.exception.ResourceNotFoundException",
"error_description": "grpID 6601645549158 does not exist!"
}
**返回值401,未授权[无token、token错误、token过期]**
{
"error": "group_authorization",
"timestamp": 1542367755294,
"duration": 0,
"exception": "com.easemob.group.exception.GroupAuthorizationException",
"error_description": "this token is bad, or has expired!"
}
如果返回结果是429、503或者其他5xx,有可能代表该接口被限流了,请稍微暂停一下并重试。详见[[im:450errorcode:45restastrict|接口限流说明]]
[[http://api-docs.easemob.com/|使用 Easemob REST API 在线测试]]
----
====获取群管理员列表====
获取群组管理员列表的接口。
=== HTTP Request ===
^{{:im:server:basics:get.png?nolink&90|}}^**{org_name}/{app_name}/chatgroups/{group_id}/admin**^
需要在请求时对应填写{group_id},需要获取的群组 ID 。
=== Request Headers ===
^参数^说明^
|Content-Type|application/json|
|Authorization|Bearer ${token}|
=== Response Body ===
^参数^说明^
|data|群组管理员信息|
=== 请求示例 ===
curl -X GET HTTP://a1.easemob.com/easemob-demo/testapp/chatgroups/10130212061185/admin -H 'Authorization: Bearer YWMtG4T5wkOTEeST5V-9lp7f-wAAAUnafsqrQFnCU4gI0-rQImw4523fWqIasd1'
=== 可能返回的结果示例 ===
**返回值200,表示获取群组管理员列表成功**
{
"action": "get",
"application": "527cd7e0-04b3-11e7-9f59-ef10ecd81ff0",
"uri": "http://a1.easemob.com/easemob-demo/testapp/chatgroups/10130212061185/admin",
"entities": [],
"data": ["user1"],
"timestamp": 1489073361210,
"duration": 0,
"organization": "easemob-demo",
"applicationName": "testapp",
"count": 1
}
如果返回结果是429、503或者其他5xx,有可能代表该接口被限流了,请稍微暂停一下并重试。详见[[im:450errorcode:45restastrict|接口限流说明]]
[[http://api-docs.easemob.com/|使用 Easemob REST API 在线测试]]
----
====添加群管理员====
将一个群成员角色提升为群管理员接口。
=== HTTP Request ===
^{{:im:server:basics:post.png?nolink&90|}}^**/{org_name}/{app_name}/chatgroups/{group_id}/admin**^
需要在请求时对应填写{group_id},需要获取的群组 ID 。
=== Request Headers ===
^参数^说明^
|Content-Type|application/json|
|Authorization|Bearer ${token}|
=== Request Body ===
^参数^说明^
|newadmin|添加的新管理员用户 ID |
=== Response Body ===
^参数^说明^
|data|添加的新管理员用户 ID |
=== 请求示例 ===
curl -X POST HTTP://a1.easemob.com/easemob-demo/testapp/chatgroups/10130212061185/admin -d '{"newadmin":"user1"}' -H 'Authorization: Bearer YWMtG4T5wkOTEeST5V-9lp7f-wAAAUnafsqrQFnCU4gI0-rQImw4523fWqIasd1'
=== 可能返回的结果示例 ===
**返回值200,表示获取群组管理员列表成功**
{
"action": "get",
"application": "527cd7e0-04b3-11e7-9f59-ef10ecd81ff0",
"uri": "http://a1.easemob.com/easemob-demo/testapp/chatgroups/10130212061185/admin",
"entities": [],
"data": ["user1"],
"timestamp": 1489073361210,
"duration": 0,
"organization": "easemob-demo",
"applicationName": "testapp",
"count": 1
}
如果返回结果是429、503或者其他5xx,有可能代表该接口被限流了,请稍微暂停一下并重试。详见[[im:450errorcode:45restastrict|接口限流说明]]
[[http://api-docs.easemob.com/|使用 Easemob REST API 在线测试]]
----
====移除群管理员====
将用户的角色从群管理员降为群普通成员接口。
=== HTTP Request ===
^{{:im:server:basics:delete.png?nolink&90|}}^**/{org_name}/{app_name}/chatgroups/{group_id}/admin/{oldadmin}**^
需要在请求时对应填写{group_id}和{oldadmin},需要移除的管理员所在群组和管理员的用户名。
=== Request Headers ===
^参数^说明^
|Content-Type|application/json|
|Authorization|Bearer ${token}|
=== 请求示例 ===
curl -X DELETE HTTP://a1.easemob.com/easemob-demo/testapp/chatgroups/10130212061185/admin/user1 -H 'Authorization: Bearer YWMtG4T5wkOTEeST5V-9lp7f-wAAAUnafsqrQFnCU4gI0-rQImw4523fWqIasd1'
=== 可能返回的结果示例 ===
**返回值200,表示移除群组管理员成功**
{
"action": "delete",
"application": "527cd7e0-04b3-11e7-9f59-ef10ecd81ff0",
"uri": "http://a1.easemob.com/easemob-demo/testapp/chatgroups/10130212061185/admin/user1",
"entities": [],
"data": {
"result": "success",
"oldadmin": "user1"
},
"timestamp": 1489073432732,
"duration": 1,
"organization": "easemob-demo",
"applicationName": "testapp"
}
如果返回结果是429、503或者其他5xx,有可能代表该接口被限流了,请稍微暂停一下并重试。详见[[im:450errorcode:45restastrict|接口限流说明]]
[[http://api-docs.easemob.com/|使用 Easemob REST API 在线测试]]
----
====转让群组====
修改群组 Owner 为同一群组中的其他成员。
=== HTTP Request ===
^{{:im:server:basics:put.png?nolink&90|}}^**/{org_name}/{app_name}/chatgroups/{groupid}**^
需要在请求时对应填写{groupid},需要转让的群组 ID 。
=== Request Headers ===
^参数^说明^
|Content-Type|application/json|
|Authorization|Bearer ${token}|
=== Request Body ===
^参数^说明^
|newowner|群组的新管理员 ID |
=== Response Body ===
在返回值中查看data字段包含的信息。
^参数^说明^
|newowner|群组的新管理员 ID |
=== 请求示例 ===
curl -X PUT -H 'Content-Type: application/json' -H 'Accept: application/json' -H 'Authorization: Bearer YWMt7CoyjusbEeixOi3iod4eDAAAAAAAAAAAAAAAAAAAAAGL4CTw6XgR6LaXXVmNX4QCAgMAAAFnJlhJIwBPGgCqtjiyVnR209iyr8kNbhJhhanNQDdP9CMmpK2G-NIUOQ' -d '{
"newowner": "user2"
}' 'http://a1.easemob.com/easemob-demo/testapp/chatgroups/66016455491585'
=== 可能返回的结果示例 ===
**返回值200,表示群组转移成功**
{
"action": "put",
"application": "8be024f0-e978-11e8-b697-5d598d5f8402",
"uri": "http://a1.easemob.com/easemob-demo/testapp/chatgroups/66016455491585",
"entities": [],
"data": {
"newowner": true
},
"timestamp": 1542537813420,
"duration": 0,
"organization": "easemob-demo",
"applicationName": "testapp"
}
**返回值403,该成员不在此群组**
{
"error": "forbidden_op",
"timestamp": 1542538459201,
"duration": 0,
"exception": "com.easemob.group.exception.ForbiddenOpException",
"error_description": "user: user6 doesn't exist in group: 66016455491585"
}
**返回值404,此群组ID不存在**
{
"error": "resource_not_found",
"timestamp": 1542367736446,
"duration": 0,
"exception": "com.easemob.group.exception.ResourceNotFoundException",
"error_description": "grpID 6601645549158 does not exist!"
}
**返回值401,未授权[无token、token错误、token过期]**
{
"error": "group_authorization",
"timestamp": 1542538513851,
"duration": 0,
"exception": "com.easemob.group.exception.GroupAuthorizationException",
"error_description": "this token is bad, or has expired!"
}
如果返回结果是429、503或者其他5xx,有可能代表该接口被限流了,请稍微暂停一下并重试。详见[[im:450errorcode:45restastrict|接口限流说明]]
[[http://api-docs.easemob.com/|使用 Easemob REST API 在线测试]]
----
=====管理黑名单=====
环信提供多个接口完成群组黑名单管理,包括查看、将用户添加、移除黑名单等。
|查询群组黑名单|/{org_name}/{app_name}/chatgroups/{group_id}/blocks/users|查看群组的黑名单列表|
|添加单个用户至群组黑名单|/{org_name}/{app_name}/chatgroups/{group_id}/blocks/users/{username}|将用户添加至群组的黑名单列表|
|批量添加用户至群组黑名单|/{org_name}/{app_name}/chatgroups/{group_id}/blocks/users|将用户批量添加至群组的黑名单列表|
|从群组黑名单移除单个用户|/{org_name}/{app_name}/chatgroups/{group_id}/blocks/users/{username}|将用户从黑名单列表中移除|
|批量从群组黑名单移除用户|/{org_name}/{app_name}/chatgroups/{group_id}/blocks/users/{usernames}|批量将用户从黑名单列表中移除|
====查询群组黑名单====
查询一个群组黑名单中的用户列表。位于黑名单中的用户查看不到该群组的信息,也无法收到该群组的消息。
=== HTTP Request ===
^{{:im:server:basics:get.png?nolink&90|}}^**/{org_name}/{app_name}/chatgroups/{group_id}/blocks/users**^
需要在请求时对应填写{group_id},需要查询的群组 ID 。
=== Request Headers ===
^参数^说明^
|Content-Type|application/json|
|Authorization|Bearer ${token}|
=== Response Body ===
在返回值中查看data字段包含的信息。
^参数^说明^
|data|群组黑名单用户 ID |
=== 请求示例 ===
curl -X GET -H 'Accept: application/json' -H 'Authorization: Bearer YWMt7CoyjusbEeixOi3iod4eDAAAAAAAAAAAAAAAAAAAAAGL4CTw6XgR6LaXXVmNX4QCAgMAAAFnJlhJIwBPGgCqtjiyVnR209iyr8kNbhJhhanNQDdP9CMmpK2G-NIUOQ' 'http://a1.easemob.com/easemob-demo/testapp/chatgroups/66016455491585/blocks/users'
=== 可能返回的结果示例 ===
**返回值200,表示群组黑名单查询成功**
{
"action": "get",
"application": "8be024f0-e978-11e8-b697-5d598d5f8402",
"uri": "http://a1.easemob.com/easemob-demo/testapp/chatgroups/67178793598977/blocks/users",
"entities": [],
"data": [
"user2",
"user3"
],
"timestamp": 1543466293681,
"duration": 0,
"organization": "easemob-demo",
"applicationName": "testapp",
"count": 2
}
**返回值404,该群组ID不存在**
{
"error": "resource_not_found",
"timestamp": 1542539206941,
"duration": 0,
"exception": "com.easemob.group.exception.ResourceNotFoundException",
"error_description": "grpID 6601645549158 does not exist!"
}
**返回值401,未授权[无token、token错误、token过期]**
{
"error": "group_authorization",
"timestamp": 1542539245149,
"duration": 0,
"exception": "com.easemob.group.exception.GroupAuthorizationException",
"error_description": "this token is bad, or has expired!"
}
如果返回结果是429、503或者其他5xx,有可能代表该接口被限流了,请稍微暂停一下并重试。详见[[im:450errorcode:45restastrict|接口限流说明]]
[[http://api-docs.easemob.com/|使用 Easemob REST API 在线测试]]
----
====添加单个用户至群组黑名单====
添加一个用户进入一个群组的黑名单。群主无法被加入群组的黑名单。
用户进入群组黑名单后,会收到消息:You are kicked out of the group xxx。之后,该用户查看不到该群组的信息,也收不到该群组的消息。
=== HTTP Request ===
^{{:im:server:basics:post.png?nolink&90|}}^**/{org_name}/{app_name}/chatgroups/{group_id}/blocks/users/{username}**^
需要在请求时对应填写{group_id},需要添加黑名单的群组 ID ,以及需{username},要添加的 IM 用户名。
=== Request Headers ===
^参数^说明^
|Content-Type|application/json|
|Authorization|Bearer ${token}|
=== Response Body ===
在返回值中查看data字段包含的信息。
^参数^说明^
|result|添加结果,true表示添加成功,false表示添加失败|
|groupid|群组 ID |
|action|执行操作|
|user|被添加的用户 ID |
=== 请求示例 ===
curl -X POST -H 'Content-Type: application/json' -H 'Accept: application/json' -H 'Authorization: Bearer YWMt7CoyjusbEeixOi3iod4eDAAAAAAAAAAAAAAAAAAAAAGL4CTw6XgR6LaXXVmNX4QCAgMAAAFnJlhJIwBPGgCqtjiyVnR209iyr8kNbhJhhanNQDdP9CMmpK2G-NIUOQ' 'http://a1.easemob.com/easemob-demo/testapp/chatgroups/66016455491585/blocks/users/user1'
=== 可能返回的结果示例 ===
**返回值200,添加用户至群组黑名单成功**
{
"action": "post",
"application": "8be024f0-e978-11e8-b697-5d598d5f8402",
"uri": "http://a1.easemob.com/easemob-demo/testapp/chatgroups/66016455491585/blocks/users/user1",
"entities": [],
"data": {
"result": true,
"action": "add_blocks",
"user": "user1",
"groupid": "66016455491585"
},
"timestamp": 1542539577124,
"duration": 27,
"organization": "easemob-demo",
"applicationName": "testapp"
}
**返回值404,该群组ID不存在**
{
"error": "resource_not_found",
"timestamp": 1542539654833,
"duration": 0,
"exception": "com.easemob.group.exception.ResourceNotFoundException",
"error_description": "grpID 6601645549158 does not exist!"
}
**返回值403,该用户不存在**
{
"error": "forbidden_op",
"timestamp": 1542539679705,
"duration": 0,
"exception": "com.easemob.group.exception.ForbiddenOpException",
"error_description": "users [user10] are not members of this group!"
}
**返回值401,未授权[无token、token错误、token过期]**
{
"error": "group_authorization",
"timestamp": 1542539732510,
"duration": 0,
"exception": "com.easemob.group.exception.GroupAuthorizationException",
"error_description": "this token is bad, or has expired!"
}
如果返回结果是429、503或者其他5xx,有可能代表该接口被限流了,请稍微暂停一下并重试。详见[[im:450errorcode:45restastrict|接口限流说明]]
[[http://api-docs.easemob.com/|使用 Easemob REST API 在线测试]]
----
====批量添加用户至群组黑名单====
添加多个用户进入一个群组的黑名单,一次性最多可以添加60个用户。群主无法被加入群组的黑名单。
用户进入群组黑名单后,会收到消息:You are kicked out of the group xxx。之后,该用户查看不到该群组的信息,也收不到该群组的消息。
=== HTTP Request ===
^{{:im:server:basics:post.png?nolink&90|}}^**/{org_name}/{app_name}/chatgroups/{group_id}/blocks/users**^
需要在请求时对应填写{group_id},需要添加黑名单的群组 ID ,以及需{username},要添加的 IM 用户名。
=== Request Headers ===
^参数^说明^
|Content-Type|application/json|
|Authorization|Bearer ${token}|
=== Request Body ===
^参数^说明^
|usernames|添加的用户名 ID |
=== Response Body ===
在返回值中查看data字段包含的信息。
^参数^说明^
|result|添加结果,true表示添加成功,false表示添加失败|
|reason|添加失败的原因|
|groupid|群组 ID |
|action|执行的操作|
|user|被添加的用户 ID |
=== 请求示例 ===
curl -X POST -H 'Content-Type: application/json' -H 'Accept: application/json' -H 'Authorization: Bearer YWMt7CoyjusbEeixOi3iod4eDAAAAAAAAAAAAAAAAAAAAAGL4CTw6XgR6LaXXVmNX4QCAgMAAAFnJlhJIwBPGgCqtjiyVnR209iyr8kNbhJhhanNQDdP9CMmpK2G-NIUOQ' -d '{
"usernames": [
"user3","user4"
]
}' 'http://a1.easemob.com/easemob-demo/testapp/chatgroups/66016455491585/blocks/users'
=== 可能返回的结果示例 ===
**返回值200,添加用户至群组黑名单成功**
{
"action": "post",
"application": "8be024f0-e978-11e8-b697-5d598d5f8402",
"uri": "http://a1.easemob.com/easemob-demo/testapp/chatgroups/66016455491585/blocks/users",
"entities": [],
"data": [
{
"result": false,
"action": "add_blocks",
"reason": "user: user3 doesn't exist in group: 66016455491585",
"user": "user3",
"groupid": "66016455491585"
},
{
"result": true,
"action": "add_blocks",
"user": "user4",
"groupid": "66016455491585"
}
],
"timestamp": 1542540095540,
"duration": 16,
"organization": "easemob-demo",
"applicationName": "testapp"
}
**返回值404,该群组ID不存在**
{
"error": "resource_not_found",
"timestamp": 1542540155192,
"duration": 1,
"exception": "com.easemob.group.exception.ResourceNotFoundException",
"error_description": "grpID 6601645549158 does not exist!"
}
**返回值403,该用户不存在或不能添加群主至黑名单**
{
"error": "forbidden_op",
"timestamp": 1542540210145,
"duration": 0,
"exception": "com.easemob.group.exception.ForbiddenOpException",
"error_description": "forbidden operation on group owner!"
}
**返回值401,未授权[无token、token错误、token过期]**
{
"error": "group_authorization",
"timestamp": 1542540260660,
"duration": 0,
"exception": "com.easemob.group.exception.GroupAuthorizationException",
"error_description": "this token is bad, or has expired!"
}
如果返回结果是429、503或者其他5xx,有可能代表该接口被限流了,请稍微暂停一下并重试。详见[[im:450errorcode:45restastrict|接口限流说明]]
[[http://api-docs.easemob.com/|使用 Easemob REST API 在线测试]]
----
====从群组黑名单移除单个用户====
从群组黑名单中移除一个用户。对于群组黑名单中的用户,如果需要将其再次加入群组,需要先将其从群组黑名单中移除。
=== HTTP Request ===
^{{:im:server:basics:delete.png?nolink&90|}}^**/{org_name}/{app_name}/chatgroups/{group_id}/blocks/users/{username}**^
需要在请求时对应填写{group_id},需要移除黑名单的群组 ID ,以及需{username},要移除的 IM 用户名。
=== Request Headers ===
^参数^说明^
|Content-Type|application/json|
|Authorization|Bearer ${token}|
=== 请求示例 ===
curl -X DELETE -H 'Accept: application/json' -H 'Authorization: Bearer YWMt7CoyjusbEeixOi3iod4eDAAAAAAAAAAAAAAAAAAAAAGL4CTw6XgR6LaXXVmNX4QCAgMAAAFnJlhJIwBPGgCqtjiyVnR209iyr8kNbhJhhanNQDdP9CMmpK2G-NIUOQ' 'http://a1.easemob.com/easemob-demo/testapp/chatgroups/66016455491585/blocks/users/user1'
=== 可能返回的结果示例 ===
**返回值200,移除用户黑名单成功**
{
"action": "delete",
"application": "8be024f0-e978-11e8-b697-5d598d5f8402",
"uri": "http://a1.easemob.com/easemob-demo/testapp/chatgroups/66016455491585/blocks/users/user1",
"entities": [],
"data": {
"result": true,
"action": "remove_blocks",
"user": "user1",
"groupid": "66016455491585"
},
"timestamp": 1542540470679,
"duration": 45,
"organization": "easemob-demo",
"applicationName": "testapp"
}
**返回值404,该群组ID不存在**
{
"error": "resource_not_found",
"timestamp": 1542540559252,
"duration": 0,
"exception": "com.easemob.group.exception.ResourceNotFoundException",
"error_description": "grpID 6601645549158 does not exist!"
}
**返回值404,该用户不存在**
{
"error": "resource_not_found",
"timestamp": 1542540616864,
"duration": 0,
"exception": "com.easemob.group.exception.ResourceNotFoundException",
"error_description": "username user10 doesn't exist!"
}
**返回值401,未授权[无token、token错误、token过期]**
{
"error": "group_authorization",
"timestamp": 1542540739864,
"duration": 0,
"exception": "com.easemob.group.exception.GroupAuthorizationException",
"error_description": "this token is bad, or has expired!"
}
如果返回结果是429、503或者其他5xx,有可能代表该接口被限流了,请稍微暂停一下并重试。详见[[im:450errorcode:45restastrict|接口限流说明]]
[[http://api-docs.easemob.com/|使用 Easemob REST API 在线测试]]
----
====批量从群组黑名单移除用户====
从群组黑名单中移除多个用户。对于群组黑名单中的用户,如果需要将其再次加入群组,需要先将其从群组黑名单中移除。
=== HTTP Request ===
^{{:im:server:basics:delete.png?nolink&90|}}^**/{org_name}/{app_name}/chatgroups/{group_id}/blocks/users/{usernames}**^
需要在请求时对应填写{group_id},需要移除黑名单的群组 ID ,以及需{username},要移除的 IM 用户名。
=== Request Headers ===
^参数^说明^
|Content-Type|application/json|
|Authorization|Bearer ${token}|
=== 请求示例 ===
curl -X DELETE -H 'Accept: application/json' -H 'Authorization: Bearer YWMt7CoyjusbEeixOi3iod4eDAAAAAAAAAAAAAAAAAAAAAGL4CTw6XgR6LaXXVmNX4QCAgMAAAFnJlhJIwBPGgCqtjiyVnR209iyr8kNbhJhhanNQDdP9CMmpK2G-NIUOQ' 'http://a1.easemob.com/easemob-demo/testapp/chatgroups/66016455491585/blocks/users/user1%2Cuser2'
=== 可能返回的结果示例 ===
**返回值200,移除用户黑名单成功**
{
"action": "delete",
"application": "8be024f0-e978-11e8-b697-5d598d5f8402",
"uri": "http://a1.easemob.com/easemob-demo/testapp/chatgroups/66016455491585/blocks/users/user1%2Cuser2",
"entities": [],
"data": [
{
"result": true,
"action": "remove_blocks",
"user": "user1",
"groupid": "66016455491585"
},
{
"result": true,
"action": "remove_blocks",
"user": "user2",
"groupid": "66016455491585"
}
],
"timestamp": 1542541014655,
"duration": 29,
"organization": "easemob-demo",
"applicationName": "testapp"
}
**返回值404,该群组ID不存在**
{
"error": "resource_not_found",
"timestamp": 1542541067286,
"duration": 0,
"exception": "com.easemob.group.exception.ResourceNotFoundException",
"error_description": "grpID 6601645549158 does not exist!"
}
**返回值404,该用户不存在**
{
"error": "resource_not_found",
"timestamp": 1542541102793,
"duration": 0,
"exception": "com.easemob.group.exception.ResourceNotFoundException",
"error_description": "username user10 doesn't exist!"
}
**返回值401,未授权[无token、token错误、token过期]**
{
"error": "group_authorization",
"timestamp": 1542541134588,
"duration": 0,
"exception": "com.easemob.group.exception.GroupAuthorizationException",
"error_description": "this token is bad, or has expired!"
}
如果返回结果是429、503或者其他5xx,有可能代表该接口被限流了,请稍微暂停一下并重试。详见[[im:450errorcode:45restastrict|接口限流说明]]
[[http://api-docs.easemob.com/|使用 Easemob REST API 在线测试]]
----
=====管理禁言=====
环信提供多个接口群组禁言列表的管理,包括查看、将用户添加、移除禁言列表等。
^名称^请求^描述^
|添加禁言|/{org_name}/{app_name}/chatgroups/{group_id}/mute|添加用户至群组的禁言列表|
|移除禁言|/{org_name}/{app_name}/chatgroups/{group_id}/mute/{member1}(,{member2},…)|从群组的禁言列表中移除用户|
|获取禁言列表|/{org_name}/{app_name}/chatgroups/{group_id}/mute|获取群组的禁言列表|
====添加禁言====
将一个用户禁言。用户被禁言后,将无法在群中发送消息。
=== HTTP Request ===
^{{:im:server:basics:post.png?nolink&90|}}^**/{org_name}/{app_name}/chatgroups/{group_id}/mute**^
需要在请求时对应填写{group_id},需要添加禁言的群组 ID ,以及需{username},要添加禁言的 IM 用户名。
=== Request Headers ===
^参数^说明^
|Content-Type|application/json|
|Authorization|Bearer ${token}|
=== Request Body ===
^参数^说明^
|mute_duration|禁言的时间,单位毫秒,如果是“-1”代表永久(实际的到期时间为固定时间戳4638873600000,即2117-01-01 00:00:00)|
|usernames|要被添加禁言用户的 ID |
=== Response Body ===
^参数^说明^
|result|操作结果;true:添加成功;false:添加失败|
|expire|禁言到期的时间戳(从1970年1月1日开始的毫秒数。如果禁言时间传的值为“-1”,那么该时间戳为固定的4638873600000,请参考 mute_duration 参数的说明)|
|user|被禁言用户的 ID |
=== 请求示例 ===
curl -X POST HTTP://a1.easemob.com/easemob-demo/testuser/chatgroups/10130212061185/mute -d '{"usernames":["user1"], "mute_duration":86400000}' -H 'Authorization: Bearer YWMtG4T5wkOTEeST5V-9lp7f-wAAAUnafsqrQFnCU4gI0-rQImw4523fWqIasd1'
=== 可能返回的结果示例 ===
**返回值200,添加禁言成功**
{
"action": "post",
"application": "527cd7e0-04b3-11e7-9f59-ef10ecd81ff0",
"uri": "http://a1.easemob.com/easemob-demo/testapp/chatgroups/10130212061185/mute",
"entities": [],
"data": [{
"result": true,
"expire": 1489158589481,
"user": "user1"
}],
"timestamp": 1489072189508,
"duration": 0,
"organization": "easemob-demo",
"applicationName": "testapp"
}
如果返回结果是429、503或者其他5xx,有可能代表该接口被限流了,请稍微暂停一下并重试。详见[[im:450errorcode:45restastrict|接口限流说明]]
[[http://api-docs.easemob.com/|使用 Easemob REST API 在线测试]]
----
====移除禁言====
将用户从禁言列表中移除。移除后,用户可以正常在群中发送消息。
=== HTTP Request ===
^{{:im:server:basics:delete.png?nolink&90|}}^**/{org_name}/{app_name}/chatgroups/{group_id}/mute/{member1}(,{member2},…)**^
=== Request Headers ===
^参数^说明^
|Content-Type|application/json|
|Authorization|Bearer ${token}|
=== 请求示例 ===
curl -X DELETE HTTP://a1.easemob.com/easemob-demo/testapp/chatgroups/10130212061185/mute/user1 -H 'Authorization: Bearer YWMtG4T5wkOTEeST5V-9lp7f-wAAAUnafsqrQFnCU4gI0-rQImw4523fWqIasd1'
=== 可能返回的结果示例 ===
**返回值200,表示移除禁言成功**
{
"action": "delete",
"application": "527cd7e0-04b3-11e7-9f59-ef10ecd81ff0",
"uri": "http://a1.easemob.com/easemob-demo/testapp/chatgroups/10130212061185/mute/user1",
"entities": [],
"data": [{
"result": true,
"user": "user1"
}],
"timestamp": 1489072695859,
"duration": 0,
"organization": "easemob-demo",
"applicationName": "testapp"
}
如果返回结果是429、503或者其他5xx,有可能代表该接口被限流了,请稍微暂停一下并重试。详见[[im:450errorcode:45restastrict|接口限流说明]]
[[http://api-docs.easemob.com/|使用 Easemob REST API 在线测试]]
----
====获取禁言列表====
获取当前群组的禁言用户列表。
=== HTTP Request ===
^{{:im:server:basics:get.png?nolink&90|}}^**/{org_name}/{app_name}/chatgroups/{group_id}/mute**^
=== Request Headers ===
^参数^说明^
|Content-Type|application/json|
|Authorization|Bearer ${token}|
=== Response Body ===
^参数^说明^
|expire|禁言到期的时间戳(从1970年1月1日开始的毫秒数。如果禁言时间传的值为“-1”,那么该时间戳为固定的4638873600000,请参考mute_duration参数的说明)|
|user|被禁言用户的 ID |
=== 请求示例 ===
curl -X GET HTTP://a1.easemob.com/easemob-demo/testapp/chatgroups/10130212061185/mute -H 'Authorization: Bearer YWMtG4T5wkOTEeST5V-9lp7f-wAAAUnafsqrQFnCU4gI0-rQImw4523fWqIasd1'
=== 可能返回的结果示例 ===
**返回值200,表示获取禁言列表成功**
{
"action": "post",
"application": "527cd7e0-04b3-11e7-9f59-ef10ecd81ff0",
"uri": "http://a1.easemob.com/easemob-demo/testapp/chatgroups/10130212061185/mute",
"entities": [],
"data": [{
"expire": 1489158589481,
"user": "user1"
}],
"timestamp": 1489072802179,
"duration": 0,
"organization": "easemob-demo",
"applicationName": "testapp"
}
如果返回结果是429、503或者其他5xx,有可能代表该接口被限流了,请稍微暂停一下并重试。详见[[im:450errorcode:45restastrict|接口限流说明]]
[[http://api-docs.easemob.com/|使用 Easemob REST API 在线测试]]
----
上一页:[[im:server:basics:messages|发送消息]]
下一页:[[im:server:basics:chatroom|聊天室管理]]