Flutter TIM 项目实现

目录

1. 服务端API

1.1 生成签名

1.1.1 步骤

第一步:获取签名算法

第二步:查看函数输入输出

第三步:nodejs 实现功能

1.1.2 验证签名

小结

1.2 Rest API 调用

1.2.1 签名介绍

1.2.2 腾讯接口

生成管理员 administrator 签名

包装一个 post 请求函数

查询账号

导入单个账号

导入多个账号,一次最多导入 100 个账号

设置用户资料

获取群详细资料

删除群聊

在群组中发送系统通知

小结

1.3 第三方回调

1.3.1 场景举例

1.3.2 回调命令列表

在线状态

资料关系链

单聊消息

群组系统

1.3.3 配置回调

第一步:配置回调服务器

第二步:第三方回调配置

小结

2. IM 用户登录

2.1 类结构设计

2.1.1 正文

类架构图

类设计说明

2.1.2 小结

2.2 工具类 IMManager

重要说明

2.2.1 步骤

常量 Constants

状态枚举,类

SDK 初始化

事件监听 Listener

用户 User

会话 Conversasion

消息 Message

群组 Group

小结

2.3 服务 IMService

2.3.1 关系结构

2.3.2 步骤

创建 IMService

导包

加入 TIM 管理器

初始化 init

SDK 

用户

消息

群聊

会话

小结

2.4 断线重连处理

2.4.1 知识点

断线重连

技术处理

2.4.2 步骤

全局初始 IMService

启动 APP 连接成功

断开网络

恢复网络自动断线重连

小结

2.5 用户登录,登出

2.5.1 用户管理

2.5.2 步骤

保存令牌

用户登录

离线用户登录

用户退出

http 401 授权错误

腾讯后台账号管理

小结

2.6 用户登录过期

2.6.1 知识点

令牌过期

2.6.2 处理过程

2.6.3 步骤

处理 V2TIMListener -> onUserSigExpired 过期回调

小结

2.7 多端登录踢下线

2.7.1 步骤

腾讯云后台配置

i18n 多语言

处理 oKickedOffline 回调

效果

小结

2.8 会话响应 IM 状态

2.8.1 步骤

多语言 i18n

会话首页

浮动提示栏组件

IMService 服务器,用户状态

IM 登录

监听服务器离线

小结

3. 聊天用户选取

3.1 用户列表

3.1.1 步骤

搜索用户 api

控制器翻页拉取用户

视图页刷新控制

会话页面发起选择用户

小结

3.2 选择用户

3.2.1 步骤

选取用户控制器

选取用户视图

会话界面接收选中列表数据

小结

4. 单聊功能

4.1 聊天界面布局

4.1.1 步骤

创建聊天业务

导包

聊天控制器

进入聊天

小结

4.2 底部聊天栏位

4.2.1 步骤

聊天栏 ChaBarWidget

聊天 Chat 控制器

聊天 Chat 视图

小结

4.3 发送文字消息

4.3.1 知识点

SDK 函数和类型

V2TimMessage.tatus 消息状态

V2TimMessage.elemType 消息类型

4.3.2 步骤

聊天控制器

聊天视图

小结

4.4 接收显示文字消息

4.4.1 SDK API 接口

 getC2CHistoryMessageList 获取单聊历史消息

getGroupHistoryMessageList 获取群组历史消息

4.4.2 类结构

4.4.3 步骤

聊天控制器

聊天视图

IMService 服务

小结

4.5 发送失败消息处理

4.5.1 步骤

i18n多语言

删除不合规消息

重新发送消息

显示错误信息

小结

5. 会话管理

5.1 会话列表

5.1.1 会话接口说明

5.1.2 步骤

会话控制器

会话视图

小结

5.2 更新会话

5.2.1 步骤

会话控制器

会话视图

IM 工具类

IM 会话监听更新

小结

6. 群聊功能

6.1 创建群聊

6.1.1 createGroup 接口说明

6.1.2 步骤

会话控制器

聊天控制器

小结

6.2 群本地消息

insertGroupMessageToLocalStorage 接口说明

V2TimMessage.elemType 消息类型

步骤

消息枚举定义

IMService 服务

会话控制器创建本地消息

聊天控制器

聊天视图

小结

6.3 群提示消息

6.3.1 接口说明

消息内容

V2TimGroupTipsElem.type 群Tips类型

6.3.2 步骤

定义消息枚举

消息类型转字符串

聊天界面显示提示

小结

6.4 群管理侧栏

6.4.1 步骤

群设置组件

聊天控制器

聊天视图

小结

6.5 修改群资料

6.5.1 接口说明

入参

6.5.2 步骤

聊天控制器

群设置侧栏组件

IM 工具类

IMService 群消息处理

小结

6.6 邀请加入

6.6.1 接口说明

入参

返回值

6.6.2 步骤

聊天控制器

群聊侧栏管理组件

小结

6.7 踢出群聊

6.7.1 kickGroupMember 接口说明

入参

6.7.2 步骤

聊天控制器

侧栏视图

IMService 服务

聊天界面系统消息

小结

6.8 退出群聊

6.8.1 quitGroup 接口说明

入参

6.8.2 步骤

im 工具类

imservice

聊天控制器

聊天侧栏

聊天视图

小结

6.9 解散群聊

6.9.1 解散群逻辑

6.9.2 接口说明

FLUTTER SDK dismissGroup 接口

服务器端 destroy_group 接口

6.9.3 步骤

IM 工具类

IMService

聊天控制器

聊天侧栏

会话控制器

小结

7. 信息提示

7.1 未读信息提示

7.1.1 步骤

IMService

main 主视图

IM Manager

聊天控制器

小结

7.2 APP 内提示

7.2.1步骤

overlay_support 插件安装

IM 工具类

IMService

小结

7.3 本机提示

7.3.1 步骤

flutter_local_notifications 包

ios 配置

android 配置

本地消息服务

IM 工具类

ConfigService 配置服务

IMService 腾讯聊天服务类

main 控制器

main 视图

小结


博主wx:yuanlai45_csdn 博主qq:2777137742

后期会创建粉丝群,为同学们提供分享交流平台以及提供官方发送的福利奖品~

PS:重新清理依赖,在拷贝新项目的时候用得上

flutter clean

flutter pub get

1. 服务端API

1.1 生成签名

与腾讯通讯时需要带上 UserSig 签名参数,这个是标识这个用户访问被允许,所以这是必须要做的事情。

签名的方式有两种,一个是客户端签名,这种方式缺点容易被反编译后复制出密钥。

另一种方式是服务端签名,虽然消耗点服务器资源,但是这种比较安全。这是推荐的方式。

本文将会以 nodejs 作为后端,来说明签名过程。毕竟 js 语法大家容易理解。

1.1.1 步骤

第一步:获取签名算法

资料 即时通信 IM 生成 UserSig-服务端 API-文档中心-腾讯云

采用服务端计算 UserSig,可以最大限度地保障计算 UserSig 所用的密钥信息不被泄露。您只需将计算代码部署在您的服务器上,并提供面向 App 的服务端接口,在需要 UserSig 时由您的 App 向业务服务器发起请求获取动态 UserSig。 为了简化实现过程,我们提供了下列语言或平台的 UserSig 计算源码,您可以直接下载并集成到您的服务端。

语言版本 关键函数 下载链接
Java HMAC-SHA256 genSig
GO HMAC-SHA256 GenSig
PHP HMAC-SHA256 genSig
Nodejs(这个) HMAC-SHA256 genSig
Python HMAC-SHA256 gen_sig
C# HMAC-SHA256 GenSig
C++ HMAC-SHA256 gen_sig

第二步:查看函数输入输出

资料 tls-sig-api-v2-node/TLSSigAPIv2.js at master · tencentyun/tls-sig-api-v2-node · GitHub

初始化签名对象,传入 appid, key 密钥

...
var Api = function (sdkappid, key) {
    this.sdkappid = sdkappid;
    this.key = key;
};
...

签名函数,传入 userid 用户编号,expire 过期时间秒,userBuf 默认 null 只有在音视频时才用上

Api.prototype.genSig = function (userid, expire, userBuf) {
    var currTime = Math.floor(Date.now() / 1000);

    var sigDoc = {
        'TLS.ver': "2.0",
        'TLS.identifier': "" + userid,
        'TLS.sdkappid': Number(this.sdkappid),
        'TLS.time': Number(currTime),
        'TLS.expire': Number(expire)
    };

    var sig = '';
    if (null != userBuf) {
        var base64UserBuf = base64encode(userBuf);
        sigDoc['TLS.userbuf'] = base64UserBuf;
        sig = this._hmacsha256(userid, currTime, expire, base64UserBuf);
    } else {
        sig = this._hmacsha256(userid, currTime, expire, null);
    }
    sigDoc['TLS.sig'] = sig;

    var compressed = zlib.deflateSync(newBuffer(JSON.stringify(sigDoc))).toString('base64');
    return base64url.escape(compressed);
}

第三步:nodejs 实现功能

配置环境变量 env

.env

# tim
tim_server=console.tim.qq.com
tim_appid=1400803542
tim_key=密钥xxxxxxxxxxxxxxxxxx

初始签名对象

// 腾讯 tim
const tim = new TLSSigAPIv2.Api(config.tim_appid, config.tim_key);
fastify.decorate("tim", tim);

生成 UserSig 签名        

// tim 签名
const im_sign_expire = 31536000; // 365天
const im_sign = await this.tim.genSig(username, im_sign_expire);

使用 apifox 来测试

下载链接Apifox - API 文档、调试、Mock、测试一体化协作平台。拥有接口文档管理、接口调试、Mock、自动化测试等功能,接口开发、测试、联调效率,提升 10 倍。最好用的接口文档管理工具,接口自动化测试工具。

调用 /users/me 接口

客户端保存好你的 im_sign 。

1.1.2 验证签名

登录 - 腾讯云

输入 userid, 签名 sig, 点击开始校验,输出签名信息查看。

果然有效期是 365 天

小结

本节讲了腾讯签名令牌的后端实现方式,业务里面放在了获取用户资料的接口里面,因为我本来就要用 userid 去查询下数据库,这样就一起返回数据了。

如果发现不能登录、提示签名错误的,可以在腾讯后台点击开始校验看下是否签名正确。

apifox接口——可直接在项目设置选择apifix格式导入

{"apifoxProject":"1.0.0","$schema":{"app":"apifox","type":"project","version":"1.2.0"},"info":{"name":"猫哥视频站-课程","description":"","mockRule":{"rules":[],"enableSystemRule":true}},"responseCollection":[],"apiCollection":[{"name":"根目录","parentId":0,"serverId":"","description":"","preProcessors":[{"id":"inheritProcessors","type":"inheritProcessors","data":{}}],"postProcessors":[{"id":"inheritProcessors","type":"inheritProcessors","data":{}}],"inheritPostProcessors":{},"inheritPreProcessors":{},"auth":{},"identityPattern":{"httpApi":{"type":"methodAndPath","bodyType":""}},"items":[{"name":"用户","parentId":0,"serverId":"","description":"","preProcessors":[{"id":"inheritProcessors","type":"inheritProcessors","data":{}}],"postProcessors":[{"id":"inheritProcessors","type":"inheritProcessors","data":{}}],"inheritPostProcessors":{},"inheritPreProcessors":{},"auth":{},"identityPattern":{"httpApi":{"type":"inherit","bodyType":"","fields":[]}},"items":[{"name":"注册","api":{"id":"75406090","method":"post","path":"/users/register","parameters":{"query":[],"path":[]},"auth":{},"commonParameters":{"query":[],"body":[],"cookie":[],"header":[]},"responses":[{"id":"190834219","name":"成功","code":200,"contentType":"json","jsonSchema":{"type":"object","properties":{"id":{"type":"string"}},"required":["id"],"x-apifox-orders":["id"]}}],"responseExamples":[{"name":"成功示例 ","data":"{\n    \"id\": \"7\"\n}","responseId":190834219,"ordering":1}],"requestBody":{"type":"application/json","parameters":[],"jsonSchema":{"title":"","type":"object","properties":{"username":{"type":"string","mock":{"mock":"ducafecat"},"title":""},"password":{"type":"string","mock":{"mock":"123456"}},"email":{"type":"string","mock":{"mock":"ducafecat@gmail.com"}},"verify_code":{"type":"string"}},"x-apifox-orders":["username","password","email","verify_code"],"required":["username","password","email","verify_code"]}},"description":"","tags":[],"status":"developing","serverId":"","operationId":"","sourceUrl":"","ordering":0,"cases":[{"id":81441640,"type":"http","path":null,"name":"成功","responseId":190834219,"parameters":{},"commonParameters":{"query":[],"body":[],"header":[],"cookie":[]},"requestBody":{"parameters":[],"type":"application/json","data":"{\n    \"username\": \"ducafecat\",\n    \"password\": \"123456\",\n    \"email\": \"ducafecat@gmail.com\"\n}"},"preProcessors":[],"postProcessors":[],"inheritPostProcessors":{},"inheritPreProcessors":{},"auth":{},"advancedSettings":{}}],"mocks":[],"customApiFields":"{}","advancedSettings":{},"mockScript":{},"codeSamples":[],"preProcessors":[],"postProcessors":[],"inheritPostProcessors":{},"inheritPreProcessors":{}}},{"name":"获取 Email 验证码","api":{"id":"75406088","method":"post","path":"/users/verify","parameters":{"query":[],"path":[]},"auth":{},"commonParameters":{"query":[],"body":[],"cookie":[],"header":[]},"responses":[{"id":"190834216","name":"成功","code":200,"contentType":"json","jsonSchema":{"type":"object","properties":{},"x-apifox-orders":[]}}],"responseExamples":[],"requestBody":{"type":"application/json","parameters":[],"jsonSchema":{"title":"","type":"object","properties":{"email":{"type":"string","mock":{"mock":"ducafecat@gmail.com"}},"type":{"type":"string","description":"register, findPassword"}},"x-apifox-orders":["email","type"],"required":["email","type"]}},"description":"","tags":[],"status":"developing","serverId":"","operationId":"","sourceUrl":"","ordering":6,"cases":[],"mocks":[],"customApiFields":"{}","advancedSettings":{},"mockScript":{},"codeSamples":[],"preProcessors":[],"postProcessors":[],"inheritPostProcessors":{},"inheritPreProcessors":{}}},{"name":"找回密码","api":{"id":"75406091","method":"post","path":"/users/findpwd","parameters":{"query":[],"path":[]},"auth":{},"commonParameters":{"query":[],"body":[],"cookie":[],"header":[]},"responses":[{"id":"190834218","name":"成功","code":200,"contentType":"json","jsonSchema":{"type":"object","properties":{},"x-apifox-orders":[]}}],"responseExamples":[],"requestBody":{"type":"application/json","parameters":[],"jsonSchema":{"title":"","type":"object","properties":{"email":{"type":"string","mock":{"mock":"ducafecat@gmail.com"}},"verify_code":{"type":"string","description":"验证码"},"password":{"type":"string","description":"密码"}},"x-apifox-orders":["email","verify_code","password"],"required":["email","verify_code","password"]}},"description":"","tags":[],"status":"developing","serverId":"","operationId":"","sourceUrl":"","ordering":12,"cases":[],"mocks":[],"customApiFields":"{}","advancedSettings":{},"mockScript":{},"codeSamples":[],"preProcessors":[],"postProcessors":[],"inheritPostProcessors":{},"inheritPreProcessors":{}}},{"name":"加密","api":{"id":"75406087","method":"post","path":"/users/encrypt","parameters":{"query":[],"path":[]},"auth":{},"commonParameters":{"query":[],"body":[],"cookie":[],"header":[]},"responses":[{"id":"190834215","name":"成功","code":200,"contentType":"json","jsonSchema":{"type":"object","properties":{},"x-apifox-orders":[]}}],"responseExamples":[],"requestBody":{"type":"application/json","parameters":[],"jsonSchema":{"title":"","type":"object","properties":{"password":{"type":"string","description":"密码"}},"x-apifox-orders":["password"],"required":["password"]}},"description":"","tags":[],"status":"developing","serverId":"","operationId":"","sourceUrl":"","ordering":18,"cases":[],"mocks":[],"customApiFields":"{}","advancedSettings":{},"mockScript":{},"codeSamples":[],"preProcessors":[],"postProcessors":[],"inheritPostProcessors":{},"inheritPreProcessors":{}}},{"name":"登录","api":{"id":"75406089","method":"post","path":"/users/login","parameters":{"query":[],"path":[]},"auth":{},"commonParameters":{"query":[],"body":[],"cookie":[],"header":[]},"responses":[{"id":"190834217","name":"成功","code":200,"contentType":"json","jsonSchema":{"type":"object","properties":{"token":{"type":"string"},"profile":{"type":"object","properties":{"username":{"type":"string"},"email":{"type":"string"},"nick_name":{"type":"string"},"avatar":{"type":"string"},"intro":{"type":"null"},"vip_grade":{"type":"string"},"vip_expire_time":{"type":"null"},"total_times":{"type":"integer"},"last_time":{"type":"string"},"reg_time":{"type":"string"}},"required":["username","email","nick_name","avatar","intro","vip_grade","vip_expire_time","total_times","last_time","reg_time"],"x-apifox-orders":["username","email","nick_name","avatar","intro","vip_grade","vip_expire_time","total_times","last_time","reg_time"]}},"required":["token","profile"],"x-apifox-orders":["token","profile"]}}],"responseExamples":[{"name":"成功示例 ","data":"{\n    \"token\": \"eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VyX2lkIjoiNiIsImlhdCI6MTY2MDM5NzM0NSwiZXhwIjoxNjYxMDAyMTQ1fQ.KYSfIeK2Q-9PgPivIIqfIMWF0owSee6LXqoK7gk83F8\"\n}","responseId":190834217,"ordering":1}],"requestBody":{"type":"application/json","parameters":[],"jsonSchema":{"title":"","type":"object","properties":{"username":{"type":"string","mock":{"mock":"ducafecat@gmail.com"}},"password":{"type":"string","mock":{"mock":"kWrIeYCYAYvd3i5fUpjttlvXJC8ftNwNtIuToK9H6dh5zJdTXTA8ghZf46SWZuQn6DYBBEEzZc6FQghjssW/Kw=="}}},"x-apifox-orders":["username","password"],"required":["username","password"]}},"description":"","tags":[],"status":"developing","serverId":"","operationId":"","sourceUrl":"","ordering":24,"cases":[{"id":81441636,"type":"http","path":null,"name":"成功","responseId":190834217,"parameters":{},"commonParameters":{"query":[],"body":[],"header":[],"cookie":[]},"requestBody":{"parameters":[],"type":"application/json","data":"{\n    \"username\": \"ducafecat01\",\n    \"password\": \"cpVDcw/rkyPeYMeVJFa5cA7P5yuH8pI1h1U+thEdkI20Dhb5p66reU/HQHtDGZsTVXIMBLKCOtLmCZfG43m5SA==\"\n}"},"preProcessors":[],"postProcessors":[],"inheritPostProcessors":{},"inheritPreProcessors":{},"auth":{},"advancedSettings":{}}],"mocks":[],"customApiFields":"{}","advancedSettings":{"isDefaultUrlEncoding":1},"mockScript":{},"codeSamples":[],"preProcessors":[],"postProcessors":[],"inheritPostProcessors":{},"inheritPreProcessors":{}}},{"name":"Profile","api":{"id":"75406092","method":"get","path":"/users/me","parameters":{"query":[],"path":[]},"auth":{},"commonParameters":{"query":[],"body":[],"cookie":[],"header":[]},"responses":[{"id":"190834220","name":"成功","code":200,"contentType":"json","jsonSchema":{"type":"object","properties":{"id":{"type":"string"},"im_sig":{"type":"string"},"username":{"type":"string"},"email":{"type":"string"},"nick_name":{"type":"string"},"avatar":{"type":"string"},"intro":{"type":"null"},"vip_grade":{"type":"string"},"vip_expire_time":{"type":"string"},"total_times":{"type":"integer"},"last_time":{"type":"string"},"reg_time":{"type":"string"},"attributes":{"type":"object","properties":{"username":{"type":"string"},"email":{"type":"string"},"nick_name":{"type":"string"},"intro":{"type":"null"},"vip_grade":{"type":"string"},"vip_expire_time":{"type":"null"},"total_times":{"type":"integer"},"ip":{"type":"null"},"country":{"type":"null"},"province":{"type":"null"},"city":{"type":"null"},"last_time":{"type":"string"},"reg_time":{"type":"string"}},"required":["username","email","nick_name","intro","vip_grade","vip_expire_time","total_times","ip","country","province","city","last_time","reg_time"],"x-apifox-orders":["username","email","nick_name","intro","vip_grade","vip_expire_time","total_times","ip","country","province","city","last_time","reg_time"]}},"required":["id","im_sig","username","email","nick_name","avatar","intro","vip_grade","vip_expire_time","total_times","last_time","reg_time","attributes"],"x-apifox-orders":["id","attributes","im_sig","username","email","nick_name","avatar","intro","vip_grade","vip_expire_time","total_times","last_time","reg_time"]}}],"responseExamples":[{"name":"成功示例 ","data":"{\n    \"id\": \"6\",\n    \"attributes\": {\n        \"username\": \"ducafecat\",\n        \"email\": \"ducafecat@gmail.com\",\n        \"nick_name\": \"ducafecat\",\n        \"intro\": null,\n        \"vip_grade\": \"guest\",\n        \"vip_expire_time\": null,\n        \"total_times\": 0,\n        \"ip\": null,\n        \"country\": null,\n        \"province\": null,\n        \"city\": null,\n        \"last_time\": \"2022-08-13T13:28:00.646Z\",\n        \"reg_time\": \"2016-07-20T12:00:15.000Z\"\n    }\n}","responseId":190834220,"ordering":1}],"requestBody":{"type":"application/json","parameters":[],"jsonSchema":{"title":"","type":"object","properties":{},"x-apifox-orders":[]}},"description":"","tags":[],"status":"developing","serverId":"","operationId":"","sourceUrl":"","ordering":30,"cases":[{"id":81441638,"type":"http","path":null,"name":"成功","responseId":190834220,"parameters":{},"commonParameters":{"query":[],"body":[],"header":[],"cookie":[]},"requestBody":{"parameters":[],"type":"application/json"},"preProcessors":[],"postProcessors":[],"inheritPostProcessors":{},"inheritPreProcessors":{},"auth":{},"advancedSettings":{}}],"mocks":[],"customApiFields":"{}","advancedSettings":{},"mockScript":{},"codeSamples":[],"preProcessors":[],"postProcessors":[],"inheritPostProcessors":{},"inheritPreProcessors":{}}},{"name":"更新 Profile","api":{"id":"75406093","method":"put","path":"/users/me","parameters":{"query":[],"path":[]},"auth":{},"commonParameters":{"query":[],"body":[],"cookie":[],"header":[]},"responses":[{"id":"190834221","name":"成功","code":200,"contentType":"json","jsonSchema":{"type":"object","properties":{"id":{"type":"string"},"attributes":{"type":"object","properties":{"username":{"type":"string"},"email":{"type":"string"},"nick_name":{"type":"string"},"intro":{"type":"null"},"vip_grade":{"type":"string"},"vip_expire_time":{"type":"null"},"total_times":{"type":"integer"},"ip":{"type":"null"},"country":{"type":"null"},"province":{"type":"null"},"city":{"type":"null"},"last_time":{"type":"string"},"reg_time":{"type":"string"}},"required":["username","email","nick_name","intro","vip_grade","vip_expire_time","total_times","ip","country","province","city","last_time","reg_time"],"x-apifox-orders":["username","email","nick_name","intro","vip_grade","vip_expire_time","total_times","ip","country","province","city","last_time","reg_time"]}},"required":["id","attributes"],"x-apifox-orders":["id","attributes"]}}],"responseExamples":[{"name":"成功示例 ","data":"{\n    \"id\": \"6\",\n    \"attributes\": {\n        \"username\": \"ducafecat\",\n        \"email\": \"ducafecat@gmail.com\",\n        \"nick_name\": \"ducafecat\",\n        \"intro\": null,\n        \"vip_grade\": \"guest\",\n        \"vip_expire_time\": null,\n        \"total_times\": 0,\n        \"ip\": null,\n        \"country\": null,\n        \"province\": null,\n        \"city\": null,\n        \"last_time\": \"2022-08-13T13:28:00.646Z\",\n        \"reg_time\": \"2016-07-20T12:00:15.000Z\"\n    }\n}","responseId":190834221,"ordering":1}],"requestBody":{"type":"application/json","parameters":[],"jsonSchema":{"title":"","type":"object","properties":{},"x-apifox-orders":[]}},"description":"","tags":[],"status":"developing","serverId":"","operationId":"","sourceUrl":"","ordering":36,"cases":[],"mocks":[],"customApiFields":"{}","advancedSettings":{},"mockScript":{},"codeSamples":[],"preProcessors":[],"postProcessors":[],"inheritPostProcessors":{},"inheritPreProcessors":{}}},{"name":"tim 数据准备","api":{"id":"75406097","method":"post","path":"/users/chatPrepare","parameters":{"query":[],"path":[]},"auth":{},"commonParameters":{"query":[],"body":[],"cookie":[],"header":[]},"responses":[{"id":"190834227","name":"成功","code":200,"contentType":"json","jsonSchema":{"type":"object","properties":{},"x-apifox-orders":[]}}],"responseExamples":[{"name":"成功示例 ","data":"{\n    \"id\": \"7\"\n}","responseId":190834227,"ordering":1}],"requestBody":{"type":"application/json","parameters":[],"jsonSchema":{"title":"","type":"object","properties":{"user_ids":{"type":"array","items":{"type":"string"}}},"x-apifox-orders":["user_ids"],"required":["user_ids"]}},"description":"","tags":[],"status":"developing","serverId":"","operationId":"","sourceUrl":"","ordering":60,"cases":[{"id":81441643,"type":"http","path":null,"name":"成功","responseId":0,"parameters":{},"commonParameters":{"query":[],"body":[],"header":[],"cookie":[]},"requestBody":{"parameters":[],"type":"application/json","data":"{\n    \"password\": \"123456\"\n}"},"preProcessors":[],"postProcessors":[],"inheritPostProcessors":{},"inheritPreProcessors":{},"auth":{},"advancedSettings":{}}],"mocks":[],"customApiFields":"{}","advancedSettings":{},"mockScript":{},"codeSamples":[],"preProcessors":[],"postProcessors":[],"inheritPostProcessors":{},"inheritPreProcessors":{}}},{"name":"tim 解散聊天群","api":{"id":"75406098","method":"post","path":"/users/chatDeleteGroup","parameters":{"query":[],"path":[]},"auth":{},"commonParameters":{"query":[],"body":[],"cookie":[],"header":[]},"responses":[{"id":"190834226","name":"成功","code":200,"contentType":"json","jsonSchema":{"type":"object","properties":{},"x-apifox-orders":[]}}],"responseExamples":[],"requestBody":{"type":"application/json","parameters":[],"jsonSchema":{"title":"","type":"object","properties":{"userId":{"type":"string"},"groupId":{"type":"string"}},"x-apifox-orders":["userId","groupId"],"required":["userId","groupId"]}},"description":"","tags":[],"status":"developing","serverId":"","operationId":"","sourceUrl":"","ordering":66,"cases":[{"id":81441642,"type":"http","path":null,"name":"成功","responseId":0,"parameters":{},"commonParameters":{"query":[],"body":[],"header":[],"cookie":[]},"requestBody":{"parameters":[],"type":"application/json","data":"{\n    \"password\": \"123456\"\n}"},"preProcessors":[],"postProcessors":[],"inheritPostProcessors":{},"inheritPreProcessors":{},"auth":{},"advancedSettings":{}}],"mocks":[],"customApiFields":"{}","advancedSettings":{},"mockScript":{},"codeSamples":[],"preProcessors":[],"postProcessors":[],"inheritPostProcessors":{},"inheritPreProcessors":{}}},{"name":"用户列表","api":{"id":"75406100","method":"post","path":"/users/findList","parameters":{"query":[],"path":[]},"auth":{},"commonParameters":{"query":[],"body":[],"cookie":[],"header":[]},"responses":[{"id":"190834228","name":"成功","code":200,"contentType":"json","jsonSchema":{"type":"array","items":{"type":"object","properties":{"id":{"type":"string"},"attributes":{"type":"object","properties":{"username":{"type":"string"},"nick_name":{"type":"string"},"avatar":{"type":"string"}},"required":["username","nick_name","avatar"],"x-apifox-orders":["username","nick_name","avatar"]}},"required":["id","attributes"],"x-apifox-orders":["id","attributes"]}}}],"responseExamples":[{"name":"成功示例","data":"[\n    {\n        \"id\": \"186\",\n        \"attributes\": {\n            \"username\": \"bruce-bnu\",\n            \"nick_name\": \"bruce-bnu\",\n            \"avatar\": \"00258VC3ly1gty0r05zh2j60ut0u0tce02.jpg\"\n        }\n    },\n    {\n        \"id\": \"187\",\n        \"attributes\": {\n            \"username\": \"hbz_la\",\n            \"nick_name\": \"hbz_la\",\n            \"avatar\": \"00258VC3ly1gty0qy7h06j60hj0hjdhh02.jpg\"\n        }\n    },\n    {\n        \"id\": \"188\",\n        \"attributes\": {\n            \"username\": \"jiezaichan\",\n            \"nick_name\": \"jiezaichan\",\n            \"avatar\": \"00258VC3ly1gty0qzj6d9j60go0goabi02.jpg\"\n        }\n    },\n    {\n        \"id\": \"189\",\n        \"attributes\": {\n            \"username\": \"tyrSwift\",\n            \"nick_name\": \"tyrSwift\",\n            \"avatar\": \"71bdf8ebly1gty0qz6q32j20e80e8my9.jpg\"\n        }\n    },\n    {\n        \"id\": \"190\",\n        \"attributes\": {\n            \"username\": \"dy6429829\",\n            \"nick_name\": \"dy6429829\",\n            \"avatar\": \"00258VC3ly1gty0qxcj1cj609w09w3yy02.jpg\"\n        }\n    },\n    {\n        \"id\": \"191\",\n        \"attributes\": {\n            \"username\": \"leebin17\",\n            \"nick_name\": \"leebin17\",\n            \"avatar\": \"71bdf8ebly1gty1ti7lruj208c08bgm0.jpg\"\n        }\n    },\n    {\n        \"id\": \"192\",\n        \"attributes\": {\n            \"username\": \"CoderTiany\",\n            \"nick_name\": \"CoderTiany\",\n            \"avatar\": \"00258VC3ly1gty0qxcj1cj609w09w3yy02.jpg\"\n        }\n    },\n    {\n        \"id\": \"193\",\n        \"attributes\": {\n            \"username\": \"vijayh\",\n            \"nick_name\": \"vijayh\",\n            \"avatar\": \"71bdf8ebly1gty1th3xlyj20ch0cjmyb.jpg\"\n        }\n    },\n    {\n        \"id\": \"194\",\n        \"attributes\": {\n            \"username\": \"s365790504\",\n            \"nick_name\": \"s365790504\",\n            \"avatar\": \"00258VC3ly1gty0qwvax1j60gn0gngno02.jpg\"\n        }\n    },\n    {\n        \"id\": \"195\",\n        \"attributes\": {\n            \"username\": \"andy-wangzhenhua\",\n            \"nick_name\": \"andy-wangzhenhua\",\n            \"avatar\": \"00258VC3ly1gty0qyxpv1j60hj0hjtak02.jpg\"\n        }\n    },\n    {\n        \"id\": \"196\",\n        \"attributes\": {\n            \"username\": \"hasenharrison\",\n            \"nick_name\": \"hasenharrison\",\n            \"avatar\": \"00258VC3ly1gty1tgwpqvj60cj0cimyi02.jpg\"\n        }\n    },\n    {\n        \"id\": \"197\",\n        \"attributes\": {\n            \"username\": \"chenjiahui1024\",\n            \"nick_name\": \"chenjiahui1024\",\n            \"avatar\": \"00258VC3ly1gty1tgwpqvj60cj0cimyi02.jpg\"\n        }\n    },\n    {\n        \"id\": \"198\",\n        \"attributes\": {\n            \"username\": \"bjipattorney\",\n            \"nick_name\": \"bjipattorney\",\n            \"avatar\": \"71bdf8ebly1gty1th3xlyj20ch0cjmyb.jpg\"\n        }\n    },\n    {\n        \"id\": \"199\",\n        \"attributes\": {\n            \"username\": \"ljr13512765863\",\n            \"nick_name\": \"ljr13512765863\",\n            \"avatar\": \"00258VC3ly1gty0r05zh2j60ut0u0tce02.jpg\"\n        }\n    },\n    {\n        \"id\": \"200\",\n        \"attributes\": {\n            \"username\": \"jqc5656\",\n            \"nick_name\": \"jqc5656\",\n            \"avatar\": \"71bdf8ebly1gty0r1f5x4j20go0gogna.jpg\"\n        }\n    },\n    {\n        \"id\": \"201\",\n        \"attributes\": {\n            \"username\": \"subaoxiang\",\n            \"nick_name\": \"subaoxiang\",\n            \"avatar\": \"00258VC3ly1gty0r265hmj60u00u041y02.jpg\"\n        }\n    },\n    {\n        \"id\": \"202\",\n        \"attributes\": {\n            \"username\": \"XrZxHn521\",\n            \"nick_name\": \"XrZxHn521\",\n            \"avatar\": \"00258VC3ly1gty0qxmdwoj60hs0hs0tw02.jpg\"\n        }\n    },\n    {\n        \"id\": \"203\",\n        \"attributes\": {\n            \"username\": \"_shukNgan\",\n            \"nick_name\": \"_shukNgan\",\n            \"avatar\": \"00258VC3ly1gty1tgwpqvj60cj0cimyi02.jpg\"\n        }\n    },\n    {\n        \"id\": \"204\",\n        \"attributes\": {\n            \"username\": \"kevin02040\",\n            \"nick_name\": \"kevin02040\",\n            \"avatar\": \"00258VC3ly1gty1tgwpqvj60cj0cimyi02.jpg\"\n        }\n    },\n    {\n        \"id\": \"205\",\n        \"attributes\": {\n            \"username\": \"XDH2023\",\n            \"nick_name\": \"XDH2023\",\n            \"avatar\": \"00258VC3ly1gty0qxw06hj60u00u0dkf02.jpg\"\n        }\n    }\n]","responseId":190834228,"ordering":1}],"requestBody":{"type":"application/json","parameters":[],"jsonSchema":{"title":"","type":"object","properties":{"keyword":{"type":"string"},"page":{"type":"integer"},"pageSize":{"type":"integer"}},"x-apifox-orders":["keyword","page","pageSize"],"required":["keyword","pageSize","page"]}},"description":"","tags":[],"status":"developing","serverId":"","operationId":"","sourceUrl":"","ordering":72,"cases":[{"id":81441645,"type":"http","path":null,"name":"成功","responseId":0,"parameters":{},"commonParameters":{"query":[],"body":[],"header":[],"cookie":[]},"requestBody":{"parameters":[],"type":"application/json","data":"{\n    \"password\": \"123456\"\n}"},"preProcessors":[],"postProcessors":[],"inheritPostProcessors":{},"inheritPreProcessors":{},"auth":{},"advancedSettings":{}}],"mocks":[],"customApiFields":"{}","advancedSettings":{"isDefaultUrlEncoding":1},"mockScript":{},"codeSamples":[],"preProcessors":[],"postProcessors":[],"inheritPostProcessors":{},"inheritPreProcessors":{}}}]},{"name":"博客","parentId":0,"serverId":"","description":"","preProcessors":[{"id":"inheritProcessors","type":"inheritProcessors","data":{}}],"postProcessors":[{"id":"inheritProcessors","type":"inheritProcessors","data":{}}],"inheritPostProcessors":{},"inheritPreProcessors":{},"auth":{},"identityPattern":{"httpApi":{"type":"inherit","bodyType":"","fields":[]}},"items":[{"name":"博客列表","api":{"id":"75406111","method":"get","path":"/blog","parameters":{"query":[{"required":false,"description":"页码 1","type":"integer","id":"WQTlENHs9g","example":"1","enable":true,"name":"page"},{"required":false,"description":"分类","type":"string","id":"QxVh259QPd","example":"flutter","enable":true,"name":"category"},{"required":false,"description":"查询词","type":"string","id":"Y8xke36dym","example":"","enable":true,"name":"keyword"},{"required":false,"description":"标签","type":"string","id":"Xg0Pz2Nhna","example":"","enable":true,"name":"tag"}]},"auth":{},"commonParameters":{"query":[],"body":[],"cookie":[],"header":[]},"responses":[{"id":"190834239","name":"成功","code":200,"contentType":"json","jsonSchema":{"type":"array","items":{"type":"object","properties":{"id":{"type":"string"},"attributes":{"type":"object","properties":{"uri":{"type":"string"},"title":{"type":"string"},"keyword":{"type":"null"},"description":{"type":"string"},"tags":{"type":"string"},"cover":{"type":"string"},"pv":{"type":"integer"}},"required":["uri","title","keyword","description","tags","cover","pv"],"x-apifox-orders":["uri","title","keyword","description","tags","cover","pv"]}},"x-apifox-orders":["id","attributes"]}}}],"responseExamples":[],"requestBody":{"type":"none","parameters":[]},"description":"","tags":[],"status":"released","serverId":"","operationId":"","sourceUrl":"","ordering":0,"cases":[{"id":81441655,"type":"http","path":null,"name":"成功","responseId":190834239,"parameters":{"query":[{"id":"4WvPGW73gU","relatedId":"WQTlENHs9g","relatedName":"page","value":"1","enable":true,"isDelete":false},{"id":"eRvyxDKKwF","relatedId":"Y8xke36dym","relatedName":"keyword","value":"","enable":true,"isDelete":false},{"id":"mkSYtdT3Zb","relatedId":"QxVh259QPd","relatedName":"category","value":"flutter","enable":true,"isDelete":false},{"id":"TlWyzMx1OY","relatedId":"Xg0Pz2Nhna","relatedName":"tag","value":"","enable":true,"isDelete":false}],"path":[],"cookie":[],"header":[]},"commonParameters":{"query":[],"body":[],"header":[],"cookie":[]},"requestBody":{"parameters":[],"generateMode":"normal"},"preProcessors":[],"postProcessors":[],"inheritPostProcessors":{},"inheritPreProcessors":{},"auth":{},"advancedSettings":{"isDefaultUrlEncoding":1}}],"mocks":[],"customApiFields":"{}","advancedSettings":{"isDefaultUrlEncoding":1},"mockScript":{},"codeSamples":[],"preProcessors":[],"postProcessors":[],"inheritPostProcessors":{},"inheritPreProcessors":{}}},{"name":"博客详情","api":{"id":"75406112","method":"get","path":"/blog/{uri}","parameters":{"query":[],"path":[{"id":"uri#0","name":"uri","required":true,"description":"唯一标识","enable":true,"example":"flutter-autocomplete-debounce"}]},"auth":{},"commonParameters":{"query":[],"body":[],"cookie":[],"header":[]},"responses":[{"id":"190834240","name":"成功","code":200,"contentType":"json","jsonSchema":{"type":"object","properties":{"id":{"type":"string"},"attributes":{"type":"object","properties":{"uri":{"type":"string"},"title":{"type":"string"},"keyword":{"type":"null"},"description":{"type":"string"},"tags":{"type":"string"},"cover":{"type":"string"},"pv":{"type":"integer"},"content":{"type":"string"}},"required":["uri","title","keyword","description","tags","cover","pv","content"],"x-apifox-orders":["uri","title","keyword","description","tags","cover","pv","content"]}},"required":["id","attributes"],"x-apifox-orders":["id","attributes"]}}],"responseExamples":[],"requestBody":{"type":"none","parameters":[]},"description":"","tags":[],"status":"released","serverId":"","operationId":"","sourceUrl":"","ordering":6,"cases":[{"id":81441656,"type":"http","path":null,"name":"成功","responseId":190834240,"parameters":{"query":[],"path":[{"id":"uri#0","name":"uri","relatedId":"uri#0","enable":true,"isDelete":false,"value":"flutter-autocomplete-debounce","relatedName":"uri"}],"cookie":[],"header":[]},"commonParameters":{"query":[],"body":[],"header":[],"cookie":[]},"requestBody":{"parameters":[],"generateMode":"normal"},"preProcessors":[],"postProcessors":[],"inheritPostProcessors":{},"inheritPreProcessors":{},"auth":{},"advancedSettings":{"isDefaultUrlEncoding":1}}],"mocks":[],"customApiFields":"{}","advancedSettings":{"isDefaultUrlEncoding":1},"mockScript":{},"codeSamples":[],"preProcessors":[],"postProcessors":[],"inheritPostProcessors":{},"inheritPreProcessors":{}}},{"name":"博客路径","api":{"id":"75406113","method":"get","path":"/blog/paths","parameters":{"query":[],"path":[]},"auth":{},"commonParameters":{"query":[],"body":[],"cookie":[],"header":[]},"responses":[{"id":"190834241","name":"成功","code":200,"contentType":"json","jsonSchema":{"type":"array","items":{"type":"object","properties":{"params":{"type":"object","properties":{"uri":{"type":"string"}},"required":["uri"],"x-apifox-orders":["uri"]}},"x-apifox-orders":["params"]}}}],"responseExamples":[],"requestBody":{"type":"none","parameters":[]},"description":"","tags":[],"status":"released","serverId":"","operationId":"","sourceUrl":"","ordering":12,"cases":[],"mocks":[],"customApiFields":"{}","advancedSettings":{"isDefaultUrlEncoding":1},"mockScript":{},"codeSamples":[],"preProcessors":[],"postProcessors":[],"inheritPostProcessors":{},"inheritPreProcessors":{}}}]},{"name":"腾讯 tim 接口","parentId":0,"serverId":"","description":"","preProcessors":[{"id":"inheritProcessors","type":"inheritProcessors","data":{}}],"postProcessors":[{"id":"inheritProcessors","type":"inheritProcessors","data":{}}],"inheritPostProcessors":{},"inheritPreProcessors":{},"auth":{},"identityPattern":{"httpApi":{"type":"inherit","bodyType":"","fields":[]}},"items":[{"name":"用户","parentId":15032824,"serverId":"","description":"","preProcessors":[{"id":"inheritProcessors","type":"inheritProcessors","data":{}}],"postProcessors":[{"id":"inheritProcessors","type":"inheritProcessors","data":{}}],"inheritPostProcessors":{},"inheritPreProcessors":{},"auth":{},"identityPattern":{"httpApi":{"type":"inherit","bodyType":"","fields":[]}},"items":[{"name":"导入单个帐号","api":{"id":"75406114","method":"post","path":"https://{
  {tim_server}}/v4/im_open_login_svc/account_import","parameters":{"query":[{"id":"VA6fwOfAMc","name":"sdkappid","example":"{
  {tim_sdkappid}}","required":false,"description":"","enable":true,"type":"string"},{"id":"7XXQds5SKG","name":"identifier","example":"{
  {tim_identifier}}","required":false,"description":"","enable":true,"type":"string"},{"id":"EnzbxrrpU4","name":"usersig","example":"{
  {tim_usersig}}","required":false,"description":"","enable":true,"type":"string"},{"id":"349Hx9sGPJ","name":"random","example":"{% mock 'timestamp' %}","required":false,"description":"","enable":true,"type":"string"},{"id":"JAUX2MzawK","name":"contenttype","example":"json","required":false,"description":"","enable":true,"type":"string"}],"path":[]},"auth":{},"commonParameters":{"query":[],"body":[],"cookie":[],"header":[]},"responses":[{"id":"190834242","name":"成功","code":200,"contentType":"json","jsonSchema":{"type":"object","properties":{"ActionStatus":{"type":"string"},"ErrorCode":{"type":"integer"},"ErrorInfo":{"type":"string"}},"required":["ActionStatus","ErrorCode","ErrorInfo"],"x-apifox-orders":["ActionStatus","ErrorCode","ErrorInfo"]}}],"responseExamples":[{"name":"成功示例","data":"{\n    \"ActionStatus\": \"OK\",\n    \"ErrorCode\": 0,\n    \"ErrorInfo\": \"\"\n}","responseId":190834242,"ordering":1}],"requestBody":{"type":"application/json","parameters":[],"jsonSchema":{"type":"object","properties":{"UserID":{"type":"string","mock":{"mock":"ducafecat"}},"Nick":{"type":"string","mock":{"mock":"猫哥"}},"FaceUrl":{"type":"string","mock":{"mock":"https://ducafecat.oss-cn-beijing.aliyuncs.com/ducafecat-video-flutter/avatar/00258VC3ly1gty0qztbhmj60e80e83zk02.jpg"}}},"x-apifox-orders":["UserID","Nick","FaceUrl"],"required":["UserID","Nick","FaceUrl"]},"example":"{\n    \"UserID\": \"52\",\n    \"Nick\": \"段涛\",\n    \"FaceUrl\": \"{
  {avatar_url}}\"\n}"},"description":"","tags":[],"status":"developing","serverId":"","operationId":"","sourceUrl":"","ordering":0,"cases":[{"id":81441657,"type":"http","path":null,"name":"成功","responseId":190834242,"parameters":{"query":[{"id":"skMbfmqv1H","relatedId":"VA6fwOfAMc","relatedName":"sdkappid","value":"{
  {tim_sdkappid}}","enable":true,"isDelete":false},{"id":"umLImBnSzD","relatedId":"7XXQds5SKG","relatedName":"identifier","value":"{
  {tim_identifier}}","enable":true,"isDelete":false},{"id":"1CFsX7WF5o","relatedId":"EnzbxrrpU4","relatedName":"usersig","value":"{
  {tim_usersig}}","enable":true,"isDelete":false},{"id":"ihdtVexZx1","relatedId":"349Hx9sGPJ","relatedName":"random","value":"{% mock 'timestamp' %}","enable":true,"isDelete":false},{"id":"yCvm17mpTL","relatedId":"JAUX2MzawK","relatedName":"contenttype","value":"json","enable":true,"isDelete":false}],"path":[],"cookie":[],"header":[]},"commonParameters":{"query":[],"body":[],"header":[],"cookie":[]},"requestBody":{"parameters":[],"data":"{\n    \"UserID\": \"ducafecat\",\n    \"Nick\": \"猫哥\",\n    \"FaceUrl\": \"https://ducafecat.oss-cn-beijing.aliyuncs.com/ducafecat-video-flutter/avatar/00258VC3ly1gty0qztbhmj60e80e83zk02.jpg\"\n}","generateMode":"normal"},"preProcessors":[],"postProcessors":[],"inheritPostProcessors":{},"inheritPreProcessors":{},"auth":{},"advancedSettings":{"isDefaultUrlEncoding":1}}],"mocks":[],"customApiFields":"{}","advancedSettings":{"isDefaultUrlEncoding":1},"mockScript":{},"codeSamples":[],"preProcessors":[],"postProcessors":[],"inheritPostProcessors":{},"inheritPreProcessors":{}}}]},{"name":"群组","parentId":15032824,"serverId":"","description":"","preProcessors":[{"id":"inheritProcessors","type":"inheritProcessors","data":{}}],"postProcessors":[{"id":"inheritProcessors","type":"inheritProcessors","data":{}}],"inheritPostProcessors":{},"inheritPreProcessors":{},"auth":{},"identityPattern":{"httpApi":{"type":"inherit","bodyType":"","fields":[]}},"items":[]}]}]}],"socketCollection":[],"docCollection":[],"schemaCollection":[],"webSocketCollection":[],"apiTestCaseCollection":[{"name":"根目录","children":[{"name":"默认分组","children":[],"items":[]}],"items":[]}],"apiTestSuiteCollection":[],"testCaseReferences":[],"environments":[],"commonScripts":[],"databaseConnections":[],"globalVariables":[{"variables":[{"name":"tim_server","value":"","description":""},{"name":"tim_sdkappid","value":"","description":""},{"name":"tim_identifier","value":"","description":""},{"name":"tim_usersig","value":"","description":""}],"id":"2593114"}],"commonParameters":{"parameters":{"body":[]},"id":436205,"projectId":2593114,"creatorId":563818,"editorId":563818,"createdAt":"2023-04-14T09:51:34.000Z","updatedAt":"2023-04-14T09:51:34.000Z","deletedAt":null},"projectSetting":{"apiStatuses":["developing","testing","released","deprecated"],"servers":[{"id":"default","name":"默认服务"}],"preProcessors":[],"postProcessors":[],"auth":{"type":"bearer","bearer":{"token":"eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VyX2lkIjoiMjY3IiwiaWF0IjoxNjgxMTEzMTU3LCJleHAiOjE2ODE3MTc5NTd9.QJEEGc8rTOkp9XQc4oldC89qcvwtdkhwd4CT-RNnmVk"}},"initialDisabledMockIds":[],"mockSettings":{},"gateway":[],"advancedSettings":{},"language":"zh-CN","id":"2062407","cloudMock":{"security":"free","enable":false,"tokenKey":"apifoxToken"}}}

1.2 Rest API 调用

腾讯提供了一系列的 api 接口,方便我们维护聊天业务功能,本文会对常见接口做一个介绍。

后面涉及到服务端调用问题不再重复。

用到的接口有用户、聊天群、消息推送。

1.2.1 签名介绍

即时通信 IM REST API 简介-服务端 API-文档中心-腾讯云

REST API 的 URL 格式如下:

https://xxxxxx/$ver/$servicename/$command?sdkappid=$SDKAppID&identifier=$identifier&usersig=$usersig&random=99999999&contenttype=json

其中各个参数的含义以及取值如下(参数名称及其取值均区分大小写):

参数 含义 取值
https 请求协议 请求协议为 HTTPS,请求方式为 POST
xxxxxx 专属域名 中国:console.tim.qq.com新加坡:adminapisgp.im.qcloud.com首尔: adminapikr.im.qcloud.com法兰克福:adminapiger.im.qcloud.com孟买:adminapiind.im.qcloud.com硅谷:adminapiusa.im.qcloud.com
ver 协议版本号 固定为v4
servicename 内部服务名,不同的 servicename 对应不同的服务类型 示例:v4/im_open_login_svc/account_import,其中im_open_login_svcservicename更多详情请参见 REST API 接口列表
command 命令字,与 servicename 组合用来标识具体的业务功能 示例:v4/im_open_login_svc/account_import,其中account_importcommand更多详情请参见 REST API 接口列表
sdkappid App 在即时通信 IM 控制台获取的应用标识 在申请接入时获得
identifier 用户名,调用 REST API 时必须为 App 管理员帐号 参见 App 管理员
usersig 用户名对应的密码 参见 生成 UserSig
random 标识当前请求的随机数参数 32位无符号整数随机数,取值范围0 - 4294967295
contenttype 请求格式 固定值为json

1.2.2 腾讯接口

生成管理员 administrator 签名

登录 - 腾讯云

进入后台 辅助工具->UserSig生成&校验

配置到项目的 env 中

# tim

tim_server=console.tim.qq.com tim_appid=1400803542 tim_key=4d461a6e470248ffeeb75484xxxxxsssss7ee5b27126c5a728 tim_admin_sig=eJwtzEELgkAUxxxsssszexVNhkrV9VgTbMthZ3JxXBx8n-n7NjRVNn6-Z9weliDXv

包装一个 post 请求函数
    async _post(path, jsonValue) {
        // 随机的32位无符号整数
        const random = Math.floor(Math.random() * 4294967295)
        const url = `https://${config.tim_server}/${path}?sdkappid=${config.tim_appid}&identifier=administrator&usersig=${config.tim_admin_sig}&random=${random}&contenttype=json`
        const res = await superagent.post(url).send(jsonValue).set('accept', 'json')
        const json = JSON.parse(res.text)
        return json
    }
查询账号

即时通信 IM 查询账号-服务端 API-文档中心-腾讯云

用于查询自有帐号是否已导入即时通信 IM,支持批量查询。


    async queryUser(username) {
        const req = {
            CheckItem: [
                {
                    UserID: username
                }
            ]
        }
        const res = await this._post('v4/im_open_login_svc/account_check', req)
        if (res.ActionStatus != 'OK') {
            throw new Error(res)
        }

        return res
    }
导入单个账号

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:/a/756962.html

如若内容造成侵权/违法违规/事实不符,请联系我们进行投诉反馈qq邮箱809451989@qq.com,一经查实,立即删除!

相关文章

ATL新能源科技薪资待遇及Verify测评语言理解数字推理题型简介

一、走进ATL新能源科技 ATL新能源公司,即东莞新能源科技有限公司,是全球领先的可充式锂离子电池研发、生产和营销企业。成立于2004年,总部位于香港,产品广泛应用于消费电子产品和电动汽车领域。ATL以其技术创新和与苹果等大客户的…

websocket基础使用学习

websocket基础使用学习 一、websocket是什么?二、使用步骤1.websocket服务的安装与启动安装服务连接与发消息 总结 一、websocket是什么? 以前,很多网站为了实现推送技术,所用的技术都是Ajax 轮询。轮询是在特定的的时间间隔&…

RocketMQ源码学习笔记:Broker接受消息和发送消息

这是本人学习的总结,主要学习资料如下 马士兵教育rocketMq官方文档 目录 1、Overview2、技术亮点2.1、消息写入时的自旋锁和可重入锁2.2、堆外内存机制2.2.1、Overview2.2.2、源码2.2.2.1、开启堆外内存的条件2.2.2.2、堆外内存的初始化2.2.2.3、写消息到堆外内存2…

医院消防设施设备管理系统

医院为人员密集场所,且多为各类病患及其陪护人员,一旦发生火灾,人员疏散逃生困难,容易造成较严重的生命与财产损失。为规范医院的消防设施设备管理,通过凡尔码系统对医院消防设施设备进行信息化管理,提高医…

动手学深度学习(Pytorch版)代码实践 -卷积神经网络-21多输入多输出通道

21多输入多输出通道 import torch from d2l import torch as d2ldef corr2d(X, K):"""计算二维互相关运算"""h, w K.shapeY torch.zeros((X.shape[0] - h 1, X.shape[1] - w 1))for i in range(Y.shape[0]):for j in range(Y.shape[1]):Y[i,…

大创项目推荐 题目:基于机器视觉opencv的手势检测 手势识别 算法 - 深度学习 卷积神经网络 opencv python

文章目录 1 简介2 传统机器视觉的手势检测2.1 轮廓检测法2.2 算法结果2.3 整体代码实现2.3.1 算法流程 3 深度学习方法做手势识别3.1 经典的卷积神经网络3.2 YOLO系列3.3 SSD3.4 实现步骤3.4.1 数据集3.4.2 图像预处理3.4.3 构建卷积神经网络结构3.4.4 实验训练过程及结果 3.5 …

HarmonyOS开发:应用完整性校验

简介 为了确保应用的完整性和来源可靠,OpenHarmony需要对应用进行签名和验签。 应用开发阶段: 开发者完成开发并生成安装包后,需要开发者对安装包进行签名,以证明安装包发布到设备的过程中没有被篡改。OpenHarmony的应用完整性校…

【Docker0】网络更改

目录 1. 停止docker服务 2. 关闭docker默认桥接网络接口 3. 从系统删除docker0接口 4. 创建一个名为bridge0的新接口 5. 添加ip地址和子网掩码 6. 启用bridge0接口 7. (如果没起来就执行该句) 8. 查看ip 1. 停止docker服务 sudo service docker…

SpringBoot: Eureka入门

1. IP列表 公司发展到一定的规模之后,应用拆分是无可避免的。假设我们有2个服务(服务A、服务B),如果服务A要调用服务B,我们能怎么做呢?最简单的方法是让服务A配置服务B的所有节点的IP,在服务A内部做负载均衡调用服务B…

Linux之进程控制(上)

目录 进程创建 进程终止 进程退出码 进程终止的方式 进程等待 进程等待的方式 status概述 总结 上期我们学习了Linux中进程地址空间的概念,至此进程的所有基本概念已经全部学习完成,今天我们将开始学习进程相关的操作。 进程创建 进程创建其实…

7 个不容忽视的开源安全工具

专业人士选择的第一个工具通常是开源选项,因为它们得到了广泛社区的保证和支持。此代码是支持安全可靠的互联网的基础的一部分。 最近,XZ Utils 等丑闻让用户犹豫不决。开放性是否是攻击的危险载体?还有其他问题在等着他们吗? 辩护者指出,虽然开放性可以让某些攻击变得更…

刷代码随想录有感(120):贪心算法——买卖股票的最佳时机

题干&#xff1a; 代码&#xff1a; class Solution { public:int maxProfit(vector<int>& prices) {int low INT_MAX;int res INT_MIN;for(int i 0; i < prices.size(); i){low min(low, prices[i]);res max(res, prices[i] - low);}return res;} }; 贪心…

在本地和Linux之间传输文件

1.打开本地的cmd窗口 2. 然后按这个链接的说法在cmd中远程连接Linux&#xff08;技术|如何在 Linux 中使用 sFTP 上传或下载文件与文件夹&#xff09; 3. 看这个链接里面的sftp命令进行本地和Linux之间的文件互传 &#xff08;https://www.cnblogs.com/niuben/p/13324099.htm…

动态规划基础练习

我们需要先从数组较大的开始进行处理&#xff0c;每次考察上下左右的&#xff0c;比较当前存储的最大值和转移来的值&#xff0c;哪一个大一点 #define _CRT_SECURE_NO_WARNINGS #include<bits/stdc.h> using namespace std;int n, m; int a[105][105]; int addx[] { 0,…

远程过程调用协议gRPC及在go环境下的使用

1. 远程过程调用协议 1.1 定义 远程过程调用(Remote Procedure Call&#xff0c;PRC是一种进程间通信技术&#xff0c;它使得程序可以像调用本地函数一样调用远程服务器上的函数。RPC 屏蔽了底层的通信细节&#xff0c;让开发者能够更专注于业务逻辑&#xff0c;而无需关心网络…

C语言力扣刷题4——删除链表的倒数第 N 个结点[双指针],只遍历一遍

力扣刷题4——删除链表的倒数第 N 个结点[双指针] 一、博客声明二、题目描述三、解题思路1、思路说明 四、解题代码&#xff08;附注释&#xff09; 一、博客声明 找工作逃不过刷题&#xff0c;为了更好的督促自己学习以及理解力扣大佬们的解题思路&#xff0c;开辟这个系列来记…

“用友审批,兴业付款”,YonSuite让企业资金调拨更高效

随着企业规模的扩大和经营的不断深入&#xff0c;企业的分支机构分布各地&#xff0c;在多银行多账户的资金管理上面临着诸多挑战。传统的资金管理方式往往效率低下、风险较高&#xff0c;难以满足企业快速发展的需求。 为了解决这些痛点&#xff0c;用友网络科技股份有限公司…

MathType2024最新破解版在哪里可以下载?

在当今科技日益发展的时代&#xff0c;我们每个人都可能遇到需要在电子文档、网页或其他平台中输入复杂数学公式的情况。这时&#xff0c;一个强大且易用的数学公式编辑器就成了我们迫切需要的工具。而MathType&#xff0c;作为一款专业、精准的数学公式编辑器&#xff0c;无疑…

Redis为什么设计多个数据库

​关于Redis的知识前面已经介绍过很多了,但有个点没有讲,那就是一个Redis的实例并不是只有一个数据库,一般情况下,默认是Databases 0。 一 内部结构 设计如下: Redis 的源码中定义了 redisDb 结构体来表示单个数据库。这个结构有若干重要字段,比如: dict:该字段存储了…

人生最有力,最棒的十句话!

人生最有力&#xff0c;最棒的十句话 1、允许一切事发生&#xff0c;所有一切发生的事不是你能阻挡了的&#xff0c;你接受&#xff0c;他也发生&#xff0c;你不接受&#xff0c;他也发生&#xff0c;你还不如坦然面对接受现实。 2、你焦虑的时候千万不要躺着啥也不干&#xf…