用户操作

获取用户详情

接口

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

推荐使用用户信息处理中的接口进行用户信息的获取,v1 接口已废弃。

代码示例

  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/

推荐使用用户信息处理中的接口进行用户信息的获取,v1 接口已废弃。

参数说明

参数类型必填说明
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/v2.2/miniapp/user_profile/

该接口支持通过参数 return_total_count 指定是否返回查询对象总数,以协助不关心对象总数只关心查询结果列表的开发者提升接口响应速度。同时,从 v2.2 版本开始该接口默认不返回查询对象总数,欲获取总数的开发者需要显式指定 return_total_count 参数。

参数说明

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

若开发者只需要获取对象总数,则可以通过设置 limit=1 以及 return_total_count=1 来达到该效果,total_count 可从返回的 meta 中获取

请求示例:

https://cloud.minapp.com/oserve/v2.2/miniapp/user_profile/?limit=1&return_total_count=1

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

代码示例

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

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

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/v2.2/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']]),
  'return_total_count' => '1'
);
$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/v2.2/miniapp/user_profile/:id/

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

代码示例

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

var options = {
  method: 'GET',
  url: 'https://cloud.minapp.com/oserve/v2.2/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/v2.2/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/v2.2/miniapp/user_profile/:id/

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

代码示例

curl -X PUT \
  https://cloud.minapp.com/oserve/v2.2/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/v2.2/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/v2.2/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: 用户不存在。

批量修改自定义字段

PUT https://cloud.minapp.com/oserve/v2.2/miniapp/user_profile/

该接口支持通过参数 return_total_count 指定是否返回待更新对象总数,以协助不关心对象总数只关心数据更新结果的开发者提升接口响应速度。同时,从 v2.2 版本开始该接口默认不返回待更新对象总数,欲获取总数的开发者需要显式指定 return_total_count 参数。

Query 参数说明

参数类型必填说明
whereStringN查询语句,参数值应经过 JSON 编码为 JSONString 后,再经过 URL 编码
limitNumberN限制单次请求更新的用户数,默认为 20 条,最大可设置为 1000
offsetNumberN设置更新的偏移值,默认为 0
return_total_countNumberN返回结果中是否包含 total_count,1 为包含,0 为不包含,默认不包含

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

参数说明

参数与更新数据表数据的参数一致,详细说明请查看:数据模块:更新数据。支持数据原子性更新,详细说明请查看:数据模块:数据原子性更新

代码示例

curl -X PUT \
  https://cloud.minapp.com/oserve/v2.2/miniapp/user_profile/ \
  -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/v2.2/miniapp/user_profile/',
  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/v2.2/miniapp/user_profile/";

$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;
}

返回示例

{
  "operation_result": [
    {
      "success": {
        "id": "5a3c51cdceb616ccfc9d5f78",
        "updated_at": 1564411939
      }
    }
  ],
  "succeed": 1,
  "total_count": 1,
  "offset": 0,
  "limit": 1000,
  "next": null
}

返回参数的详细说明请查看:数据模块:同步批量修改数据

状态码说明

200: 成功。

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

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

修改用户登录信息

接口

PUT https://cloud.minapp.com/oserve/v2.1/miniapp/user/account/:id/

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

参数说明

Content-Type: application/json

参数类型必填说明
usernamestringN用户名,不区分大小写
emailstringN邮箱,不区分大小写
new_passwordstringN设置用户密码
phonestringN新的手机号

如果需要为用户强行修改密码, 传入 new_password 即可。当设置新的手机号时,phone_verified 重置为 false,需要重新通过验证码进行验证。

如想重置用户的 email/username/phone,可以将 email/username/phone 的值设置为 null。

代码示例

curl -X PUT \
  https://cloud.minapp.com/oserve/v2.1/miniapp/user/account/70695404/ \
  -H 'Authorization: Bearer 35919068aa799eccdef19160e1da4bf21381d2a2' \
  -H 'Content-Type: application/json' \
  -d '{"username": "pretty_girl"}'
var request = require("request");

var options = {
  method: 'PUT',
  url: 'https://cloud.minapp.com/oserve/v2.1/miniapp/user/account/70695404/',
  headers:
  {
    'Content-Type': 'application/json',
    Authorization: 'Bearer 35919068aa799eccdef19160e1da4bf21381d2a2'
  },
  body: { 'username': 'pretty_girl' },
  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/v2.1/miniapp/user/account/70695404/";

$ch = curl_init();
$header = [
  "Authorization: Bearer {$token}",
  "Content-Type: application/json; charset=utf-8"
];
$payload = json_encode([
  "username" => "pretty_girl_php"]);

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, $payload);

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

curl_close($ch);

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

返回示例

{
  "email": "pretty_girl@example.com",
  "email_verified": false,
  "username": "pretty_girl",
  "phone": "13800138000",
  "phone_verified": true
}

返回参数说明

参数类型说明
emailstring目前的邮箱
email_verifiedboolean邮箱是否已经验证
usernamestring目前的用户名
phonestring手机号码
phone_verifiedboolean手机号码是否已经验证

状态码说明

200: 成功。

400: password 错误、email 不合法、username 或 email 已经存在。

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

404: 用户不存在。