• 用户 加入/移出 用户组操作

    用户 加入/移出 用户组操作

    接口

    PATCH https://cloud.minapp.com/oserve/v1/miniapp/group/membership/

    参数说明

    Content-Type: application/json

    参数 类型 必填 说明
    op String N 将要执行的操作,即 add 为将用户加入用户组;remove 将用户从用户组中移出
    path String N 访问的路径,默认为 /membership
    users Integer Array N 用户的 user_id 列表,列表不能为空
    groups Integer Array N 用户组 ID 列表,列表不能为空

    提交的数据是一个数组,数组中包含一系列由上面参数组成的操作。

    代码示例

    {% tabs patchCurl=”Curl”, patchNode=”Node”, patchPHP=”PHP” %}

    {% content “patchCurl”%}

    1. curl -X PATCH \
    2. -H "Authorization: Bearer 58f6cd9f84b1b0c04941fbd4d87bc5f14a785107" \
    3. -H "Content-Type: application/json" \
    4. -d '[
    5. {"op": "add", "path": "/membership", "users": [5, 6], "groups": [53,54]},
    6. {"op": "remove", "path": "/membership", "users": [5, 6], "groups":[53,54]}
    7. ]' \
    8. https://cloud.minapp.com/oserve/v1/miniapp/group/membership/

    {% content “patchNode”%}

    1. var request = require('request');
    2. var opt = {
    3. uri: 'https://cloud.minapp.com/oserve/v1/miniapp/group/membership/',
    4. method: 'PATCH',
    5. headers: {
    6. Authorization: `Bearer ${token}`
    7. },
    8. json: [ // 指定 data 以 "Content-Type": 'application/json' 传送
    9. {"op": "add", "path": "/membership", "users": [36476036], "groups": [561]}
    10. ]
    11. }
    12. request(opt, function(err, res, body) {
    13. console.log(res.statusCode)
    14. })

    {% content “patchPHP”%}

    1. <?php
    2. $param = array(
    3. array(
    4. 'op' => 'add',
    5. 'path' => '/membership',
    6. 'users' => [5, 6],
    7. 'groups' => [53, 54]
    8. ),
    9. array(
    10. 'op' => 'remove',
    11. 'path' => '/membership',
    12. 'users' => [5, 6],
    13. 'groups' => [53, 54]
    14. )
    15. );
    16. $url = "https://cloud.minapp.com/oserve/v1/miniapp/group/membership/";
    17. $ch = curl_init();
    18. $header = array(
    19. "Authorization: Bearer {$token}",
    20. 'Content-Type: application/json; charset=utf-8'
    21. );
    22. curl_setopt($ch, CURLOPT_HTTPHEADER, $header);
    23. curl_setopt($ch, CURLOPT_TIMEOUT, 30);
    24. curl_setopt($ch, CURLOPT_URL, $url);
    25. curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'PATCH');
    26. curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($param));
    27. curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
    28. curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, true);
    29. $res = curl_exec($ch);
    30. curl_close($ch);

    {% endtabs %}

    状态码说明

    204 修改成功,400 参数错误