一、功能描述
注意:说明:
二、搜索云端用户
接口
chat.searchCloudUsers(options);
参数
参数 options 为 Object 类型,包含的属性值如下:
| 参数 | 类型 | 说明 |
| keywordList | Array | required关键字列表,最多支持 5 个。 |
| keywordListMatchType | String | undefined | 关键字列表匹配类型:or:“或”关系搜索(默认)and:“与”关系搜索 |
| gender | String | undefined | 用户性别,不传入时默认搜索所有性别用户。性别表示:TencentCloudChat.TYPES.GENDER_FEMALE 女性TencentCloudChat.TYPES.GENDER_MALE 男性 |
| miniBirthday | Number | undefined | 用户最小生日,如 19900101。 |
| maxBirthday | Number | undefined | 用户最大生日,与 miniBirthday 同时设置时则必须大于等于 miniBirthday,如 20240101。 |
| cursor | String | undefined | 每次搜索云端用户的起始位置。第一次搜索时不要传入 cursor,继续搜索时填入上次调用 searchCloudUsers 接口返回的 cursor 的值。 |
| count | Number | undefined | 每次搜索云端用户结果的数量,默认值为 20, 最大值为100。 |
返回值
Promise
| 参数 | 类型 | 说明 |
| totalCount | Number | 满足搜索条件的用户总数。 |
| searchResultList | Array | 满足搜索条件的用户资料 Profile 列表,仅包括头像 avatar、昵称 nick、用户账号 userID、性别 gender、生日 birthday、个性签名 selfSignature 等信息,能够满足用户搜索结果列表的渲染需求,不包含自定义字段,若要查询详细用户资料,可参见:getUserProfile。 |
| cursor | String | 调用搜索接口续拉时需要填的游标。 |
示例
// 搜索指定关键字列表和出生时间范围搜索// – 搜索用户里出现 'test' 或 'user',且用户出生时间在 20240101 之前的用户let promise = chat.searchCloudUsers({ keywordList: ['test', 'user'], maxBirthday: 20240101,}); promise.then(function(imResponse) { // 搜索用户成功 const { totalCount, cursor, searchResultList } = imResponse.data; console.log(totalCount); // 满足搜索条件的用户总数量 console.log(cursor); // 下一次云端搜索的起始位置, 如果没有表示搜索结果拉取完成 console.log(searchResultList); // 满足搜索条件的用户列表,分页返回分组结果,每页最大返回 100, count 设定 for (let i = 0; i < searchResultList.length; i++) { const profileItem = searchResultList[i]; const { userID, nick, gender, avatar } = profileItem; console.log(userID); // 用户 ID console.log(nick); // 用户昵称 console.log(gender); // 用户性别 console.log(avatar); // 用户头像 }}).catch(function(imError) { console.error(imError); // 搜索用户失败});