IM 即时通讯
Windows/macOS
产品介绍
简介
主要功能
产品优势
海外数据中心
IM平滑迁移方案
接口及业务限制
功能介绍
帐号集成与登录
基础消息功能
群组功能
聊天室功能
聊天室标签功能
圈组功能
多端登录与互踢策略
质量数据监控台
更新日志
Demo 更新日志
NIM SDK 更新日志
快速开始
实现单聊消息收发(不含 UI)
实现圈组消息收发(不含 UI)
开发指南
概要介绍
集成方式(当前版本)
集成方式(Windows旧版本)
集成方式(macOS旧版本)
初始化
登录登出
消息收发
最近会话
历史记录
用户资料托管
好友关系托管
事件订阅
系统通知
系统通知概述
内置系统通知管理
内置系统通知未读数
自定义系统通知收发
群组功能
群组概述
群组管理
群成员管理
群消息管理
超大群功能
开通聊天室功能
聊天室
圈组功能
初始化
登录圈组
圈组服务器管理
圈组服务器成员管理
游客功能
频道相关
频道管理
频道分组
频道分组黑白名单
频道未读数管理
搜索服务器和频道
身份组相关
身份组概述
身份组应用场景
服务器身份组
频道身份组
频道分组身份组
频道用户定制权限
自定义权限项
成员权限判定
身份组相关查询
圈组订阅机制
圈组消息相关
圈组消息收发
圈组消息撤回
圈组消息更新
圈组消息删除
会话消息回复(Thread)
圈组快捷评论
获取频道最后一条消息
消息正在输入
圈组消息搜索
圈组消息查询
查询@我的消息
服务器未读数
圈组系统通知
圈组系统通知概述
圈组系统通知收发
圈组系统通知更新
圈组各端接口命名差异
语音录制与播放
NOS云存储服务
文档转换
API 参考
Windows/macOS API 参考
状态码
IM 控制台指南
创建应用
注册 IM 账号
升级服务
配置应用客户端标识
参考文档
升级指引
开发示例
UI库指南
Demo源码导读
打包发布
类与常量定义说明
常见问题
FAQ
服务协议

频道管理

更新时间: 2023/03/07 20:40:03

使用限制

  • 单个服务器的频道数量上限默认为 100 个。

    可在云信控制台配置单个服务器的频道数量上限在云信控制台选择应用,进入IM 免费版/专业版 > 功能权限开通 > 拓展配置 > 圈组 > 高级配置 > 单server可创建的channel数即可配置。
  • 拥有管理频道的权限(kPermissionManageChannel)才能创建、修改和删除频道。权限通过身份组进行配置和管理,具体请参见身份组概述及其他身份组相关文档。

创建频道

功能介绍

调用 CreateChannel方法创建频道。

参数说明

以下仅列出个别重要参数:

参数 类型 说明
anti_spam_info QChatBusinessAntiSpamInfo 配置反垃圾信息,可配置反垃圾文本业务 ID 或 反垃圾图片业务 ID。
visitor_mode NIMQChatChannelVisitorMode 设置频道是否对游客可见:
  • kNIMQChatChannelVisitorModeVisible:可见
  • kNIMQChatChannelVisitorModeInvisible:不可见
  • kNIMQChatChannelVisitorModeFollow:跟随模式(默认),即如果该频道的查看模式(view_mode)被设置为“公开”则该频道对游客可见,如果被设置为“私密”则对游客不可见
如果频道的 visitor_mode 为跟随模式,且同步模式(sync_mode)为“与频道分组同步”,则当该频道所属的频道分组的查看模式(view_mode)变更后,该频道对游客的可见性也将变更。例如,在这种情况下,频道分组的查看模式由公开变为私密,则此时该频道对游客从“可见”变为“不可见”。

示例代码

QChatChannelCreateParam param;
param.channel_info.server_id = 123456;
param.channel_info.name = "channel name";
param.channel_info.topic = "channel topic";
param.channel_info.custom = "channel custom";
param.channel_info.type = kNIMQChatChannelTypeText;
param.channel_info.view_mode = kNIMQChatChannelViewModePublic;
param.channel_info.visitor_mode = kNIMQChatChannelVisitorModeVisible;
param.anti_spam_info.text_bid = "anti spam text business id";
param.anti_spam_info.pic_bid = "anti spam pic business id";
param.cb = [this](const QChatChannelCreateResp& resp) {
    if (resp.res_code != NIMResCode::kNIMResSuccess) {
        // error handling
        return;
    }
    // process response
    // ...
};
Channel::CreateChannel(param);

删除频道

功能介绍

调用 DeleteChannel 方法删除频道。

示例代码

QChatChannelDeleteParam param;
param.channel_id = 123456;
param.cb = [this, param](const QChatChannelDeleteResp& resp) {
    if (resp.res_code != NIMResCode::kNIMResSuccess) {
        // error handling
        return;
    }
    // process response
    // ...
};
Channel::DeleteChannel(param);

更新频道

功能介绍

调用 UpdateChannel 方法更新频道。

参数说明

参数 类型 说明
anti_spam_info QChatBusinessAntiSpamInfo 配置反垃圾信息,可配置反垃圾文本业务 ID 或 反垃圾图片业务 ID。
visitor_mode NIMQChatChannelVisitorMode 设置频道是否对游客可见:
  • kNIMQChatChannelVisitorModeVisible:可见
  • kNIMQChatChannelVisitorModeInvisible:不可见
  • kNIMQChatChannelVisitorModeFollow:跟随模式(默认),即如果该频道的查看模式(view_mode)被设置为“公开”则该频道对游客可见,如果被设置为“私密”则对游客不可见
如果频道的 visitor_mode 为跟随模式,且同步模式(sync_mode)为“与频道分组同步”,则当该频道所属的频道分组的查看模式(view_mode)变更后,该频道对游客的可见性也将变更。例如,在这种情况下,频道分组的查看模式由公开变为私密,则此时该频道对游客从“可见”变为“不可见”。

示例代码

QChatChannelUpdateParam param;
param.channel_id = 123456;
param.name = "channel name";
param.topic = "channel topic";
param.custom = "channel custom";
param.view_mode = kNIMQChatChannelViewModePublic;
param.visitor_mode = kNIMQChatChannelVisitorModeVisible;
param.anti_spam_info.text_bid = "anti spam text business id";
param.anti_spam_info.pic_bid = "anti spam pic business id";
param.cb = [this](const QChatChannelUpdateResp& resp) {
    if (resp.res_code != NIMResCode::kNIMResSuccess) {
        // error handling
        return;
    }
    // process response
    // ...
};
Channel::UpdateChannel(param);

查询频道

按照频道ID查询

功能介绍

调用 GetChannels 方法查询频道列表。

示例代码

QChatChannelGetChannelsParam param;
param.channel_ids= {123, 456}
param.cb = [this](const QChatChannelGetChannelsResp& resp) {
    if (resp.res_code != NIMResCode::kNIMResSuccess) {
        // error handling
        return;
    }
    // process response
    // ...
};
Channel::GetChannels(param);

按照时间分页查询

功能介绍

调用 GetChannelsByPage 方法查询频道列表(分页)。

示例代码

QChatChannelGetChannelsPageParam param;
param.server_id = 123456;
param.timestamp = 0;
param.limit = 20;
param.cb = [this](const QChatChannelGetChannelsPageResp& resp) {
    if (resp.res_code != NIMResCode::kNIMResSuccess) {
        // error handling
        return;
    }
    // process response
    // ...
};
Channel::GetChannelsByPage(param);

查询频道成员列表

功能介绍

调用 GetMembersByPage 方法查询频道用户列表(分页)。

示例代码

QChatChannelGetMembersPageParam param;
param.server_id = 123456;
param.channel_id = 123456;
param.timestamp = 0;
param.limit = 20;
param.cb = [this](const QChatChannelGetMembersPageResp& resp) {
    if (resp.res_code != NIMResCode::kNIMResSuccess) {
        // error handling
        return;
    }
    // process response
    // ...
};
Channel::GetMembersByPage(param);

订阅频道

功能介绍

调用 Subscribe 方法订阅频道未读状态、未读数或未读消息。

示例代码

QChatChannelSubscribeParam param;
param.ope_type = kNIMQChatSubscribeOpeTypeSubscribe;
param.sub_type = kNIMQChatSubscribeTypeMsg;
NIMQChatChannelIDInfo id_info;
id_info.server_id = 123456;
id_info.channel_id = 123456;
param.id_infos.push_back(id_info);
param.cb = [this](const QChatChannelSubscribeResp& resp) {
    if (resp.res_code != NIMResCode::kNIMResSuccess) {
        // error handling
        return;
    }
    // process response
    // ...
};
Channel::Subscribe(param);

白/黑名单

更新白/黑名单成员

功能介绍

调用 UpdateWhiteBlackMembers 方法更新频道白/黑名单成员。

单个频道的黑白名单成员人数上限,默认为 1000。可在云信控制台配置该数量上限,配置路径:在云信控制台选择应用,进入IM 免费版/专业版 > 功能权限开通 > 拓展配置 > 圈组 > 高级配置 > 公开私密频道的黑白名单成员数

公开频道更新的为黑名单;私有频道更新的为白名单。

示例代码

QChatChannelUpdateWhiteBlackMembersParam param;
param.server_id = 123456;
param.channel_id = 123456;
param.accids = {"accid1", "accid2"};
param.type = kNIMQChatChannelBlack;
param.ope_type = kNIMQChatChannelWhiteOpeTypeAdd;
param.cb = [this](const QChatChannelUpdateWhiteBlackMembersResp& resp) {
    if (resp.res_code != NIMResCode::kNIMResSuccess) {
        // error handling
        return;
    }
    // process response
    // ...
};
Channel::UpdateWhiteBlackMembers(param);

更新白/黑名单身份组

功能介绍

您可通 UpdateWhiteBlackRole 方法更新频道白/黑名单身份组。

单个频道可设置的黑白名单身份组的数量上限,默认为 20。

可在云信控制台配置该数量上限在云信控制台选择应用,进入IM 免费版/专业版 > 功能权限开通 > 拓展配置 > 圈组 > 高级配置 > channel公开私密频道的黑白名单身份组对象数即可配置。

公开频道更新的为黑名单;私有频道更新的为白名单。

示例代码

QChatChannelUpdateWhiteBlackRoleParam param;
param.server_id = 123456;
param.channel_id = 123456;
param.role_id = 123456;
param.type = kNIMQChatChannelBlack;
param.ope_type = kNIMQChatChannelWhiteOpeTypeAdd;
param.cb = [this](const QChatChannelUpdateWhiteBlackRoleResp& resp) {
    if (resp.res_code != NIMResCode::kNIMResSuccess) {
        // error handling
        return;
    }
    // process response
    // ...
};
Channel::UpdateWhiteBlackRole(param);

查询白/黑名单成员

功能介绍

调用 GetWhiteBlackMembersPage 方法查询频道白/黑名单成员列表(分页)。

示例代码

QChatChannelGetWhiteBlackMembersPageParam param;
param.server_id = 123456;
param.channel_id = 123456;
param.type = kNIMQChatChannelBlack;
param.timestamp = 0;
param.limit = 20;
param.cb = [this](const QChatChannelGetWhiteBlackMembersPageResp& resp) {
    if (resp.res_code != NIMResCode::kNIMResSuccess) {
        // error handling
        return;
    }
    // process response
    // ...
};
Channel::GetWhiteBlackMembersPage(param);

查询白/黑名单身份组

功能介绍

调用 GetWhiteBlackRolesPage 方法查询频道白/黑名单身份组列表(分页)。

示例代码

QChatChannelGetWhiteBlackRolesPageParam param;
param.server_id = 123456;
param.channel_id = 123456;
param.type = kNIMQChatChannelBlack;
param.timestamp = 0;
param.limit = 20;
param.cb = [this](const QChatChannelGetWhiteBlackRolesPageResp& resp) {
    if (resp.res_code != NIMResCode::kNIMResSuccess) {
        // error handling
        return;
    }
    // process response
    // ...
};
Channel::GetWhiteBlackRolesPage(param);

查询已存在白/黑名单成员

功能介绍

通过 GetExistingWhiteBlackMembers 方法,您可根据成员ID查询已存在的白/黑名单成员。

示例代码

QChatChannelGetExistingWhiteBlackMembersParam param;
param.server_id = 123456;
param.channel_id = 123456;
param.type = kNIMQChatChannelBlack;
param.accids= {"accid1", "accid2"};
param.cb = [this](const QChatChannelGetExistingWhiteBlackMembersResp& resp) {
    if (resp.res_code != NIMResCode::kNIMResSuccess) {
        // error handling
        return;
    }
    // process response
    // ...
};
Channel::GetExistingWhiteBlackMembers(param);

查询已存在白/黑名单身份组

功能介绍

通过GetExistingWhiteBlackRoles方法, 您可根据身份组ID查询已存在的白/黑名单身份组。

示例代码

QChatChannelGetExistingWhiteBlackRolesParam param;
param.server_id = params["server_id"].asUInt64();
param.channel_id = params["channel_id"].asUInt64();
param.type = (NIMQChatChannelWhiteBlackType)params["type"].asUInt();
param.role_ids = {123, 456};
param.cb = [this](const QChatChannelGetExistingWhiteBlackRolesResp& resp) {
    if (resp.res_code != NIMResCode::kNIMResSuccess) {
        // error handling
        return;
    }
    // process response
    // ...
};
Channel::GetExistingWhiteBlackRoles(param);

查询未读数

功能介绍

通过 QueryUnreadInfo 方法,您可批量查询消息未读数。

  • 该方法调用存在频控,200ms 内最多可调用一次。
  • 单次最多查询频道数量为 100。

示例代码

QChatChannelQueryUnreadInfoParam param;
NIMQChatChannelIDInfo id_info;
id_info.server_id = 123456;
id_info.channel_id = 123456;
param.id_infos.push_back(id_info);
param.cb = [this](const QChatChannelQueryUnreadInfoResp& resp) {
    if (resp.res_code != NIMResCode::kNIMResSuccess) {
        // error handling
        return;
    }
    // process response
    // ...
};
Channel::QueryUnreadInfo(param);

未读数回调

功能介绍

调用 RegUnreadCb 方法注册未读数变更回调

示例代码

QChatChannelRegUnreadCbParam reg_unread_cb_param;
reg_unread_cb_param.cb = [this](const QChatChannelUnreadResp& resp) {
    if (resp.res_code != NIMResCode::kNIMResSuccess) {
        // error handling
        return;
    }
    // process response
    // ...
};
Channel::RegUnreadCb(reg_unread_cb_param);
此文档是否对你有帮助?
有帮助
我要吐槽
  • 使用限制
  • 创建频道
  • 功能介绍
  • 参数说明
  • 示例代码
  • 删除频道
  • 功能介绍
  • 示例代码
  • 更新频道
  • 功能介绍
  • 参数说明
  • 示例代码
  • 查询频道
  • 按照频道ID查询
  • 功能介绍
  • 示例代码
  • 按照时间分页查询
  • 功能介绍
  • 示例代码
  • 查询频道成员列表
  • 功能介绍
  • 示例代码
  • 订阅频道
  • 功能介绍
  • 示例代码
  • 白/黑名单
  • 更新白/黑名单成员
  • 功能介绍
  • 示例代码
  • 更新白/黑名单身份组
  • 功能介绍
  • 示例代码
  • 查询白/黑名单成员
  • 功能介绍
  • 示例代码
  • 查询白/黑名单身份组
  • 功能介绍
  • 示例代码
  • 查询已存在白/黑名单成员
  • 功能介绍
  • 示例代码
  • 查询已存在白/黑名单身份组
  • 功能介绍
  • 示例代码
  • 查询未读数
  • 功能介绍
  • 示例代码
  • 未读数回调
  • 功能介绍
  • 示例代码