用户操作

获取用户详情

接口

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 可从用户列表中获取。

代码示例

  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
  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. })
  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);

返回示例

  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_atStringN用户创建的时间,值为时间戳。查询创建时间大于等于 2017-01-01 的用户 created_atgte=1483228800,查询创建时间小于等于 2017-01-01 的用户:created_atlte=1483228800
genderNumberN户的性别,其中 1 表示男,2 表示女
groupStringN给定用户组 ID 查询在用户组下的用户列表。只支持 in 查询:groupin=258,360
limitNumberN限制返回资源的个数,默认为 20 条,最大可设置为 1000
nicknameStringN用户的微信昵称,支持等值查询 nickname=Tom, 模糊查询 nicknamecontains=Tom
offsetNumberN设置返回资源的起始偏移值,默认为 0
openidStringN用户的 OpenID
order_byStringN排序(支持 created_at 进行排序)
unionidStringN用户的 UnionID
user_idStringN用户 ID (对应 _userprofile 表中的 id 字段)

代码示例

  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/
  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. })
  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);

返回示例

{
  "meta": {
    "limit": 20,
    "next": null,
    "offset": 0,
    "previous": null,
    "total_count": 1
  },
  "objects": [{
    "avatar": "https://media.ifanrusercontent.com/media/tavatar/55/c3/55c3dbebcc61891be10d29ded808c84a01dxxxxx.jpg",
    "city": "Guangzhou",
    "country": "China",
    "created_at": 1504504504,
    "gender": 1,
    "id": 550xx,
    "nickname": "PCG",
    "openid": "onzns0KsLKFyg3-VcW0GwTE6xxxx",
    "unionid": "onzns0KsLKFyg3-VcW0GwTE6xxxx",
    "province": "Guangdong",
    "user_group": [
      137
    ],
    "user_id": 366197xx
  }]
}

用户信息处理

支持自定义字段的查询,更新。

批量获取用户信息

接口

GET https://cloud.minapp.com/oserve/v1/user/info/(后续将废弃该接口,推荐使用以下接口)

GET https://cloud.minapp.com/oserve/v1.9/miniapp/user_profile/

参数说明

参数类型必填说明
whereStringN查询语句,参数值应经过 JSON 编码为 JSONString 后,再经过 URL 编码
order_byStringN以下字段不支持排序:gender, country, province, city, language
limitNumberN限制返回资源的个数,默认为 20 条,最大可设置为 1000
offsetNumberN设置返回资源的起始偏移值,默认为 0

where 字段的详细说明请查看:数据模块:数据操作

代码示例

curl -X GET \
  -H "Authorization: Bearer 35919068aa799eccdef160e1da4bf21381" \
  --data-urlencode '{"test": {"$eq":"test"}}'\
  https://cloud.minapp.com/oserve/v1.9/miniapp/user_profile/
var request = require("request");

var options = {
  method: 'GET',
  url: 'https://cloud.minapp.com/oserve/v1.9/miniapp/user_profile/',
  headers:
  {
    'Content-Type': 'application/json',
    Authorization: 'Bearer 35919068aa799eccf19160e1da4bf2138'
  },
  qs: {
    where: JSON.stringify({"test": {"$eq": "test"}})
  }
};

var req = request(options, function (error, response, body) {
  if (error) throw new Error(error);
  console.log(body);
});
<?php
$token = '35919068aa799eccdef19160e1da4bf21381';
$url = "https://cloud.minapp.com/oserve/v1.9/miniapp/user_profile/?";

$ch = curl_init();
$header = array(
  "Authorization: Bearer {$token}",
  'Content-Type: application/json; charset=utf-8'
);

$condition = array(
  'where' => json_encode(['test' => ['$eq' => 'test']]),
);
$url .= http_build_query($condition);

curl_setopt($ch, CURLOPT_HTTPHEADER, $header);
curl_setopt($ch, CURLOPT_TIMEOUT, 30);
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'GET');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, true);

$response = curl_exec($ch);
$err = curl_error($ch);

curl_close($ch);

if ($err) {
  echo "CURL Error #:" . $err;
} else {
  echo $response;
}

返回示例

{
    "meta": {
        "limit": 20,
        "next": null,
        "offset": 0,
        "previous": null,
        "total_count": 2
    },
    "objects": [
        {
            "avatar": "https://media.ifanrusercontent.com/tavatar/73/b2/73b23fbd584699bb31a0317c9d4425dcba9xxxx.jpg",
            "city": "广州",
            "country": "中国",
            "created_at": 1542364387,
            "created_by": 64501217,
            "gender": 1,
            "id": 64501217,
            "is_authorized": true,
            "language": "zh_CN",
            "nickname": "你今天真好看",
            "openid": "o0b495YcphSE24RbTl7K9dMx_QAA",
            "province": "广东",
            "test": "test",
            "unionid": null,
            "updated_at": 1542872767
        },
        {
            "avatar": "https://media.ifanrusercontent.com/tavatar/4d/7c/4d7c5418b262bfa2250fd3b70789ba9d0c6e4603.jpg",
            "city": "广州",
            "country": "中国",
            "created_at": 1542858732,
            "created_by": 70695404,
            "gender": 0,
            "id": 70695404,
            "is_authorized": true,
            "language": "zh_CN",
            "nickname": "你也是",
            "openid": "o0b495agcnGojMQbCnlB9AV6OeDw",
            "province": "广东",
            "test": "test",
            "unionid": null,
            "updated_at": 1542958030
        }
    ]
}

状态码说明

200: 成功。

400: where 中的操作符或值错误,排序字段不支持。

401: 未授权,请检查请求头中的 Authorization 字段是否正确。

获取单个用户信息

接口

GET https://cloud.minapp.com/oserve/v1/user/info/:id/(后续将废弃该接口,推荐使用以下接口)

GET https://cloud.minapp.com/oserve/v1.9/miniapp/user_profile/:id/

其中 :id 是用户在 _userprofile 表中的 id

代码示例

curl -X GET \
-H "Authorization: Bearer 35919068aa799eccdef19160e1da4bf21381d2a2" \
https://cloud.minapp.com/oserve/v1.9/miniapp/user_profile/70695404/
var request = require("request");

var options = {
  method: 'GET',
  url: 'https://cloud.minapp.com/oserve/v1.9/miniapp/user_profile/70695404/',
  headers:
  {
    'Content-Type': 'application/json',
    Authorization: 'Bearer 35919068aa799eccdef19160e1da4bf21381d2a2'
  },
};

var req = request(options, function (error, response, body) {
  if (error) throw new Error(error);
  console.log(body);
});
<?php
$token = '35919068aa799eccdef19160e1da4bf21381d2a2';
$url = "https://cloud.minapp.com/oserve/v1.9/miniapp/user_profile/70695404/";

$ch = curl_init();
$header = array(
  "Authorization: Bearer {$token}",
  'Content-Type: application/json; charset=utf-8'
);

curl_setopt($ch, CURLOPT_HTTPHEADER, $header);
curl_setopt($ch, CURLOPT_TIMEOUT, 30);
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'GET');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, true);

$response = curl_exec($ch);
$err = curl_error($ch);

curl_close($ch);

if ($err) {
  echo "CURL Error #:" . $err;
} else {
  echo $response;
}

返回示例

{
    "avatar": "https://media.ifanrusercontent.com/tavatar/73/b2/73b23fbd584699bb31a0317c9d4425dcba9a.jpg",
    "city": "广州",
    "country": "中国",
    "created_at": 1542364387,
    "created_by": 88888,
    "gender": 1,
    "id": 88888,
    "is_authorized": true,
    "language": "zh_CN",
    "nickname": "你今天真好看",
    "openid": "o0b495YcphSE24RbTl7K9dMx_A",
    "province": "广东",
    "test": "test",
    "unionid": null,
    "updated_at": 1542872767
}

状态码说明

200: 成功。

401: 未授权,请检查请求头中的 Authorization 字段是否正确。

404: 用户不存在。

更新单个用户信息

接口

PUT https://cloud.minapp.com/oserve/v1/user/info/:id/(后续将废弃该接口,推荐使用以下接口)

PUT https://cloud.minapp.com/oserve/v1.9/miniapp/user_profile/:id/

其中 :id 是用户在 _userprofile 表中的 id

代码示例

curl -X PUT \
  https://cloud.minapp.com/oserve/v1.9/miniapp/user_profile/70695404/ \
  -H 'Authorization: Bearer 35919068aa799eccdef19160e1da4bf21381d2a2' \
  -H 'Content-Type: application/json' \
  -d '{"test": "test"}'
var request = require("request");

var options = {
  method: 'PUT',
  url: 'https://cloud.minapp.com/oserve/v1.9/miniapp/user_profile/70695404/',
  headers:
  {
    'Content-Type': 'application/json',
    Authorization: 'Bearer 35919068aa799eccdef19160e1da4bf21381d2a2'
  },
  body: { "test": "test" },
  json: true
};

var req = request(options, function (error, response, body) {
  if (error) throw new Error(error);
  console.log(body);
});
<?php
$token = '35919068aa799eccdef19160e1da4bf21381d2a2';
$url = "https://cloud.minapp.com/oserve/v1.9/miniapp/user_profile/70695404/";

$ch = curl_init();
$header = array(
  "Authorization: Bearer {$token}",
  'Content-Type: application/json; charset=utf-8'
);

curl_setopt($ch, CURLOPT_HTTPHEADER, $header);
curl_setopt($ch, CURLOPT_TIMEOUT, 30);
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'PUT');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, "{\"test\": \"test\"}");

$response = curl_exec($ch);
$err = curl_error($ch);

curl_close($ch);

if ($err) {
  echo "CURL Error #:" . $err;
} else {
  echo $response;
}

返回示例

{
    "avatar": "https://media.ifanrusercontent.com/tavatar/4d/7c/4d7c5418b262bfa2250fd3b70789ba9d0c6e4603.jpg",
    "city": "广州",
    "country": "中国",
    "created_at": 1542858732,
    "created_by": 70695404,
    "gender": 1,
    "id": 70695404,
    "is_authorized": true,
    "language": "zh_CN",
    "nickname": "Guoch",
    "openid": "o0b495agcnGojMQbCnlB9AV6OeDw",
    "province": "广东",
    "test": "changed_from_open_api",
    "unionid": null,
    "updated_at": 1542957870
}

状态码说明

200: 成功。

400: 字段类型不匹配,更新非自定义字段或不存在的字段。

401: 未授权,请检查请求头中的 Authorization 字段是否正确。

404: 用户不存在。