分组模块 - 用户组操作

优质
小牛编辑
141浏览
2023-12-01

获取用户组详情

接口

GET https://cloud.minapp.com/oserve/v1/user-group/:group_id/

其中 :group_id 需替换为你的用户组 ID

代码示例

{% tabs userGroupDetailCurl=”Curl”, userGroupDetailNode=”Node”, userGroupDetailPHP=”PHP” %}

{% content “userGroupDetailCurl” %}

  1. curl -X GET \
  2. -H "Authorization: Bearer 58f6cd9f84b1b0c04941fbd4d87bc5f14a785107" \
  3. -H "Content-Type: application/json" \
  4. https://cloud.minapp.com/oserve/v1/user-group/47/

{% content “userGroupDetailNode” %}

  1. var request = require('request');
  2. var opt = {
  3. uri: 'https://cloud.minapp.com/oserve/v1/user-group/655', // 655 对应 :group_id
  4. method: 'GET',
  5. headers: {
  6. Authorization: `Bearer ${token}`,
  7. }
  8. }
  9. request(opt, function(err, res, body) {
  10. console.log(body)
  11. })

{% content “userGroupDetailPHP”%}

  1. <?php
  2. $group_id = 47; // 用户组 ID
  3. $url = "https://cloud.minapp.com/oserve/v1/user-group/{$group_id}/";
  4. $ch = curl_init();
  5. $header = array(
  6. "Authorization: Bearer {$token}",
  7. 'Content-Type: application/json; charset=utf-8'
  8. );
  9. curl_setopt($ch, CURLOPT_HTTPHEADER, $header);
  10. curl_setopt($ch, CURLOPT_TIMEOUT, 30);
  11. curl_setopt($ch, CURLOPT_URL, $url);
  12. curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'GET');
  13. curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
  14. curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, true);
  15. $res = curl_exec($ch);
  16. curl_close($ch);

{% endtabs %}

返回示例

  1. {
  2. "id": 47,
  3. "members": 0,
  4. "name": "User Group",
  5. "parent": {
  6. "id": 1,
  7. "name": "Super Group"
  8. }
  9. }

members 表示在用户组下的用户数量,parent 表示用户组的组集

获取用户组列表

接口

GET https://cloud.minapp.com/oserve/v1/user-group/

参数说明

参数类型必填说明
parent_idStringN用户组的组集 ID
limitNumberN限制返回资源的个数,默认为 20 条,最大可设置为 1000
offsetNumberN设置返回资源的起始偏移值,默认为 0

代码示例

{% tabs userGroupCurl=”Curl”, userGroupNode=”Node”, userGroupPHP=”PHP” %}

{% content “userGroupCurl” %}

  1. curl -X GET \
  2. -H "Authorization: Bearer 58f6cd9f84b1b0c04941fbd4d87bc5f14a785107" \
  3. -H "Content-Type: application/json" \
  4. -G \
  5. -d parent_id=1 \
  6. https://cloud.minapp.com/oserve/v1/user-group/

{% content “userGroupNode” %}

  1. var request = require('request');
  2. var opt = {
  3. uri: 'https://cloud.minapp.com/oserve/v1/user-group/',
  4. method: 'GET',
  5. headers: {
  6. Authorization: `Bearer ${token}`,
  7. },
  8. qs: { // query string, 被附加到uri的参数
  9. parent_id: "234565423456787645xx", // 可选, 没有用户组的组集 ID, 可以设置为 null 或者不设置
  10. offset: 0, // 可选
  11. limit: 20 // 可选
  12. }
  13. }
  14. request(opt, function(err, res, body) {
  15. console.log(body)
  16. })

{% content “userGroupPHP”%}

  1. <?php
  2. $query['parent_id'] = 1; // 用户组的组集 ID
  3. $query['offset'] = 0; // 资源的起始偏移值
  4. $query['limit'] = 20; // 限制返回资源的个数
  5. $query_string = http_build_query($query);
  6. $url = "https://cloud.minapp.com/oserve/v1/user-group/?".$query_string;
  7. $ch = curl_init();
  8. $header = array(
  9. "Authorization: Bearer {$token}",
  10. 'Content-Type: application/json; charset=utf-8'
  11. );
  12. curl_setopt($ch, CURLOPT_HTTPHEADER, $header);
  13. curl_setopt($ch, CURLOPT_TIMEOUT, 30);
  14. curl_setopt($ch, CURLOPT_URL, $url);
  15. curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'GET');
  16. curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
  17. curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, true);
  18. $res = curl_exec($ch);
  19. curl_close($ch);

{% endtabs %}

创建用户组

接口

POST https://cloud.minapp.com/oserve/v1/user-group/

参数说明

Content-Type: application/json

参数类型必填说明
nameStringY用户组的名称
parentStringN组集 ID

代码示例

{% tabs createUserGroupCurl=”Curl”, createUserGroupNode=”Node”, createUserGroupPHP=”PHP” %}

{% content “createUserGroupCurl” %}

  1. curl -X POST \
  2. -H "Authorization: Bearer 58f6cd9f84b1b0c04941fbd4d87bc5f14a785107" \
  3. -H "Content-Type: application/json" \
  4. -d '{"name": "User Group"}' \
  5. https://cloud.minapp.com/oserve/v1/user-group/

{% content “createUserGroupNode” %}

  1. var request = require('request');
  2. var opt = {
  3. uri: 'https://cloud.minapp.com/oserve/v1/user-group/',
  4. method: 'POST',
  5. headers: {
  6. Authorization: `Bearer ${token}`,
  7. },
  8. json: { // 指定 data 以 "Content-Type": 'application/json' 传送
  9. name: 'testGroup'
  10. }
  11. }
  12. request(opt, function(err, res, body) {
  13. console.log(res.statusCode, body)
  14. })

{% content “createUserGroupPHP” %}

  1. <?php
  2. $param = array(
  3. 'name' =>'User Group'
  4. );
  5. $url = 'https://cloud.minapp.com/oserve/v1/user-group/';
  6. $ch = curl_init();
  7. $header = array(
  8. "Authorization: Bearer {$token}",
  9. 'Content-Type: application/json; charset=utf-8'
  10. );
  11. curl_setopt($ch, CURLOPT_HTTPHEADER, $header);
  12. curl_setopt($ch, CURLOPT_TIMEOUT, 30);
  13. curl_setopt($ch, CURLOPT_URL, $url);
  14. curl_setopt($ch, CURLOPT_POST, true);
  15. curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($param));
  16. curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
  17. curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, true);
  18. $res['response'] = curl_exec($ch); // 反馈结果
  19. $res['status_code'] = curl_getinfo($ch, CURLINFO_HTTP_CODE); // 返回状态码
  20. curl_close($ch);

{% endtabs %}

状态码说明

201 写入成功

修改用户组

接口

PUT https://cloud.minapp.com/oserve/v1/user-group/:group_id/

其中 :group_id 需替换为你的用户组 ID

代码示例

{% tabs updateGroupCurl=”Curl”, updateGroupNode=”Node”, updateGroupPHP=”PHP” %}

{% content “updateGroupCurl” %}

  1. curl -X PUT \
  2. -H "Authorization: Bearer 58f6cd9f84b1b0c04941fbd4d87bc5f14a785107" \
  3. -H "Content-Type: application/json" \
  4. -d '{"name": "user group"}' \
  5. https://cloud.minapp.com/oserve/v1/user-group/47/

{% content “updateGroupNode” %}

  1. var request = require('request');
  2. var opt = {
  3. uri: 'https://cloud.minapp.com/oserve/v1/user-group/655/', // 655 对应 :group_id
  4. method: 'PUT',
  5. headers: {
  6. Authorization: `Bearer ${token}`,
  7. },
  8. json: { // 指定 data 以 "Content-Type": 'application/json' 传送
  9. name: 'testGroup_3' // 修改后的用户组名
  10. }
  11. }
  12. request(opt, function(err, res, body) {
  13. console.log(res.statusCode)
  14. })

{% content “updateGroupPHP” %}

  1. <?php
  2. $group_id = 47; // 用户组 ID
  3. $url = "https://cloud.minapp.com/oserve/v1/user-group/{$group_id}/";
  4. $param = array(
  5. 'name' =>'user group'
  6. );
  7. $ch = curl_init();
  8. $header = array(
  9. "Authorization: Bearer {$token}",
  10. 'Content-Type: application/json; charset=utf-8'
  11. );
  12. curl_setopt($ch, CURLOPT_HTTPHEADER, $header);
  13. curl_setopt($ch, CURLOPT_TIMEOUT, 30);
  14. curl_setopt($ch, CURLOPT_URL, $url);
  15. curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'PUT');
  16. curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($param));
  17. curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
  18. curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, true);
  19. $res['response'] = curl_exec($ch); // 反馈结果
  20. $res['status_code'] = curl_getinfo($ch, CURLINFO_HTTP_CODE); // 状态码
  21. curl_close($ch);

{% endtabs %}

状态码说明

200 修改成功

删除用户组

接口

DELETE https://cloud.minapp.com/oserve/v1/user-group/:group_id/

代码示例

{% tabs deleteGroupCurl=”Curl”, deleteGroupNode=”Node”, deleteGroupPHP=”PHP” %}

{% content “deleteGroupCurl” %}

  1. curl -X DELETE \
  2. -H "Authorization: Bearer 58f6cd9f84b1b0c04941fbd4d87bc5f14a785107" \
  3. -H "Content-Type: application/json" \
  4. https://cloud.minapp.com/oserve/v1/user-group/47/

{% content “deleteGroupNode” %}

  1. var request = require('request');
  2. var opt = {
  3. uri: 'https://cloud.minapp.com/oserve/v1/user-group/655/', // 655 对应 :group_id
  4. method: 'DELETE',
  5. headers: {
  6. Authorization: `Bearer ${token}`,
  7. }
  8. }
  9. request(opt, function(err, res, body) {
  10. console.log(res.statusCode)
  11. })

{% content “deleteGroupPHP” %}

  1. <?php
  2. $group_id = 47; // 用户组 ID
  3. $url = "https://cloud.minapp.com/oserve/v1/user-group/{$group_id}/";
  4. $ch = curl_init();
  5. $header = array(
  6. "Authorization: Bearer {$token}",
  7. 'Content-Type: application/json; charset=utf-8'
  8. );
  9. curl_setopt($ch, CURLOPT_HTTPHEADER, $header);
  10. curl_setopt($ch, CURLOPT_TIMEOUT, 30);
  11. curl_setopt($ch, CURLOPT_URL, $url);
  12. curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'DELETE');
  13. curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
  14. curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, true);
  15. $res['response'] = curl_exec($ch); // 反馈结果
  16. $res['status_code'] = curl_getinfo($ch, CURLINFO_HTTP_CODE); // 请求状态码
  17. curl_close($ch);

{% endtabs %}

状态码说明

204 删除成功

批量删除用户组

接口

DELETE https://cloud.minapp.com/oserve/v1/user-group/?id__in=:group_id,group1_id

代码示例

{% tabs patchDeleteGroupCurl=”Curl”, patchDeleteGroupNode=”Node”, patchDeleteGroupPHP=”PHP” %}

{% content “patchDeleteGroupCurl” %}

  1. curl -X DELETE \
  2. -H "Authorization: Bearer 58f6cd9f84b1b0c04941fbd4d87bc5f14a785107" \
  3. -H "Content-Type: application/json" \
  4. https://cloud.minapp.com/oserve/v1/user-group/?id__in=48,50

{% content “patchDeleteGroupNode” %}

  1. var request = require('request');
  2. var opt = {
  3. uri: 'https://cloud.minapp.com/oserve/v1/user-group/?id__in=652,653', // id__in=652,653 对应 id__in=:group_id,group1_id
  4. method: 'DELETE',
  5. headers: {
  6. Authorization: `Bearer ${token}`,
  7. }
  8. }
  9. request(opt, function(err, res, body) {
  10. console.log(res.statusCode)
  11. })

{% content “patchDeleteGroupPHP” %}

  1. <?php
  2. // 用户组 ID 集
  3. $group_id[] = 48;
  4. $group_id[] = 50;
  5. $url = 'https://cloud.minapp.com/oserve/v1/user-group/?'.implode(',',$group_id);
  6. $ch = curl_init();
  7. $header = array(
  8. "Authorization: Bearer {$token}",
  9. 'Content-Type: application/json; charset=utf-8'
  10. );
  11. curl_setopt($ch, CURLOPT_HTTPHEADER, $header);
  12. curl_setopt($ch, CURLOPT_TIMEOUT, 30);
  13. curl_setopt($ch, CURLOPT_URL, $url);
  14. curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'DELETE');
  15. curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
  16. curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, true);
  17. $res['response'] = curl_exec($ch); // 反馈结果
  18. $res['status_code'] = curl_getinfo($ch, CURLINFO_HTTP_CODE); // 请求状态码
  19. curl_close($ch);

{% endtabs %}

状态码说明

204 删除成功