• 用户模块
    • 获取用户详情
    • 获取用户列表

    用户模块

    获取用户详情

    接口

    GET https://cloud.minapp.com/oserve/v1/miniapp/user-profile/:profile_id/

    其中 :profile_id 需替换为用户 ID(已废弃)

    GET https://cloud.minapp.com/oserve/v1/miniapp/user-profile/?user_id={{ user_id }}

    其中 user_id 可从用户列表中获取。

    代码示例

    {% tabs curl=”Curl”, node=”Node”, php=”PHP” %}

    {% content “curl”%}

    1. curl -X GET \
    2. -H "Authorization: Bearer 58f6cd9f84b1b0c04941fbd4d87bc5f14a785107" \
    3. -H "Content-Type: application/json" \
    4. https://cloud.minapp.com/oserve/v1/miniapp/user-profile/?user_id=55019

    {% content “node” %}

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

    {% content “php”%}

    1. <?php
    2. $user_id = '4271xx'; // 用户 ID
    3. $url = "https://cloud.minapp.com/oserve/v1/miniapp/user-profile/?user_id={$user_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. "avatar": "https://media.ifanrusercontent.com/media/tavatar/55/c3/55c3dbebcc61891be10d29ded808c84a01dxxxxx.jpg",
    3. "city": "Guangzhou",
    4. "country": "China",
    5. "created_at": 1504504504,
    6. "gender": 1,
    7. "id": 550xx,
    8. "nickname": "PCG",
    9. "openid": "onzns0KsLKFyg3-VcW0GwTE6xxxx",
    10. "unionid": "onzns0KsLKFyg3-VcW0GwTE6xxxx",
    11. "province": "Guangdong",
    12. "user_group": [
    13. 137
    14. ],
    15. "user_id": 366197xx
    16. }

    获取用户列表

    接口

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

    参数说明

    参数 类型 必填 说明
    created_at String N 用户创建的时间,值为时间戳。查询创建时间大于等于 2017-01-01 的用户 created_at__gte=1483228800,查询创建时间小于等于 2017-01-01 的用户:created_at__lte=1483228800
    gender Number N 户的性别,其中 1 表示男,2 表示女
    group String N 给定用户组 ID 查询在用户组下的用户列表。只支持 in 查询:group__in=258,360
    limit Number N 限制返回资源的个数,默认为 20 条,最大可设置为 1000
    nickname String N 用户的微信昵称,支持等值查询 nickname=Tom, 模糊查询 nickname__contains=Tom
    offset Number N 设置返回资源的起始偏移值,默认为 0
    openid String N 用户的 OpenID
    order_by String N 排序(支持 created_at 进行排序)
    unionid String N 用户的 UnionID
    user_id String N 用户 ID

    代码示例

    {% tabs first=”Curl”, second=”Node”, third=”PHP” %}

    {% content “first” %}

    1. curl -X GET \
    2. -H "Authorization: Bearer 58f6cd9f84b1b0c04941fbd4d87bc5f14a785107" \
    3. -H "Content-Type: application/json" \
    4. -G \
    5. -d nickname__contains=Tom \
    6. -d gender=1 \
    7. -d created_at__gt=1483228800 \
    8. -d order_by=-created_at \
    9. https://cloud.minapp.com/oserve/v1/miniapp/user-profile/

    {% content “second” %}

    1. var request = require('request');
    2. var opt = {
    3. uri: 'https://cloud.minapp.com/oserve/v1/miniapp/user-profile/',
    4. method: 'GET',
    5. headers: {
    6. Authorization: `Bearer ${token}`,
    7. },
    8. qs: { // query string, 被附加到uri的参数
    9. nickname__contains: 'username',
    10. gender: 1,
    11. created_at__gte: 1483228800,
    12. user_id: '363953xx',
    13. order_by: '-created_at'
    14. }
    15. }
    16. request(opt, function(err, res, body) {
    17. console.log(body)
    18. })

    {% content “third”%}

    1. <?php
    2. $query_data = array(
    3. 'nickname__contains' => 'Tom',
    4. 'gender' => 1,
    5. 'created_at__gte' => 1483228800,
    6. 'order_by' => '-created_at'
    7. );
    8. $query_string = http_build_query($query_data);
    9. $url = "https://cloud.minapp.com/oserve/v1/miniapp/user-profile/?".$query_string;
    10. $ch = curl_init();
    11. $header = array(
    12. "Authorization: Bearer {$token}",
    13. 'Content-Type: application/json; charset=utf-8'
    14. );
    15. curl_setopt($ch, CURLOPT_HTTPHEADER, $header);
    16. curl_setopt($ch, CURLOPT_TIMEOUT, 30);
    17. curl_setopt($ch, CURLOPT_URL, $url);
    18. curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'GET');
    19. curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
    20. curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, true);
    21. $res = curl_exec($ch);
    22. curl_close($ch);

    {% endtabs %}

    返回示例

    1. {
    2. "meta": {
    3. "limit": 20,
    4. "next": null,
    5. "offset": 0,
    6. "previous": null,
    7. "total_count": 1
    8. },
    9. "objects": [{
    10. "avatar": "https://media.ifanrusercontent.com/media/tavatar/55/c3/55c3dbebcc61891be10d29ded808c84a01dxxxxx.jpg",
    11. "city": "Guangzhou",
    12. "country": "China",
    13. "created_at": 1504504504,
    14. "gender": 1,
    15. "id": 550xx,
    16. "nickname": "PCG",
    17. "openid": "onzns0KsLKFyg3-VcW0GwTE6xxxx",
    18. "unionid": "onzns0KsLKFyg3-VcW0GwTE6xxxx",
    19. "province": "Guangdong",
    20. "user_group": [
    21. 137
    22. ],
    23. "user_id": 366197xx
    24. }]
    25. }