trait ChatRoomTrait (View source)

聊天室

Methods

array
chatRoomCreate(string $creator, string $name, string $announcement, string $broadcastUrl, array $ext = [])

创建聊天室

array
chatRoomGet(int $roomid, bool $needOnlineUserCount = false)

查询聊天室信息

array
chatRoomGetBatch(array $roomids, bool $needOnlineUserCount = false)

批量查询聊天室信息

array
chatRoomUpdate(int $roodId, string $name = '', string $announcement = '', string $broadcastUrl = '', array $ext = [], bool $needNotify = true, array $notifyExt = [])

更新聊天室信息

array
chatRoomToggleCloseStatus(int $roomid, string $operator, bool $valid)

修改聊天室开/关闭状态

array
chatRoomSetMemberRole(int $roomid, string $operator, string $target, string $opt, bool $optValue, array $notifyExt = [])

设置聊天室内用户角色

array
chatRoomRequestAddress(int $roomid, string $accId, int $clientType = null)

请求聊天室地址与令牌

array
chatRoomSendMsg(int $roomid, string $msgId, string $fromAccId, int $msgType = null, int $resendFlag = 0, array $attach = [], array $ext = [], bool $highPriority = false)

发送聊天室消息

array
chatRoomSendTxtMessage(int $roomid, string $msgId, string $fromAccId, string $msg, int $resendFlag = 0, array $ext = [])

发送聊天室文字消息封装

array
chatRoomAddRobot(int $roomid, array $accIds, array $roleExt = [], array $notifyExt = [])

往聊天室内添加机器人,机器人过期时间为24小时。

array
chatRoomRemoveRobot(int $roomid, array $accIds)

从聊天室内删除机器人

array
chatRoomTemporaryMute(int $roomid, string $operator, string $target, string $muteDuration, bool $needNotify = true, array $notifyExt = [])

将聊天室内成员设置为临时禁言

array|bool
chatRoomQueueOffer(int $roomid, string $key, string $value, string $operator = null, string $transient = null)

往聊天室有序队列中新加或更新元素

array
chatRoomQueuePoll(int $roomid, string $key)

从队列中取出元素

array
chatRoomQueueList(int $roomid)

排序列出队列中所有元素

array|bool
chatRoomQueueDrop(int $roomid)

删除清理整个队列

bool|array
chatRoomQueueInit(int $roomid, int $sizeLimit)

初始化队列

array|bool
chatRoomMuteRoom(int $roomid, string $operator, bool $mute = false, bool $needNotify = true, string $notifyExt = '')

设置聊天室整体禁言状态(仅创建者和管理员能发言)

array
chatRoomTopn(int $topn = 100, int $timestamp = null, string $period = 'day', string $orderby = 'active')

查询聊天室统计指标TopN

array
chatRoomMembersByPage(int $roomid, int $type = 0, int $endtime = 0, int $limit = 100)

分页获取成员列表

array
chatRoomQueryMembers(int $roomid, array $accids)

批量获取在线成员信息

array|bool
chatRoomUpdateMyRoomRole(int $roomid, string $accid, bool $save = false, bool $needNotify = false, string $notifyExt = '', string $nick = '', string $avator = '', string $ext = '')

变更聊天室内的角色信息

array
chatRoomQueueBatchUpdateElements(int $roomid, string $operator, array $elements, bool $needNotify = true, string $notifyExt = '')

批量更新聊天室队列元素

array
chatRoomQueryUserRoomIds(string $creator)

查询用户创建的开启状态聊天室列表

Details

array chatRoomCreate(string $creator, string $name, string $announcement, string $broadcastUrl, array $ext = [])

创建聊天室

Parameters

string $creator 聊天室属主的账号accid
string $name 聊天室名称,长度限制128个字符
string $announcement 公告,长度限制4096个字符
string $broadcastUrl 直播地址,长度限制1024个字符
array $ext 扩展字段,最长4096字符

Return Value

array $result['chatroom'] 或 ['error'=>true,'message'=>$message]

array chatRoomGet(int $roomid, bool $needOnlineUserCount = false)

查询聊天室信息

Parameters

int $roomid 聊天室id
bool $needOnlineUserCount 是否需要返回在线人数,true或false,默认false

Return Value

array $result['chatroom'] 或 ['error'=>true,'message'=>$message]

array chatRoomGetBatch(array $roomids, bool $needOnlineUserCount = false)

批量查询聊天室信息

Parameters

array $roomids 多个roomid,格式为:["6001","6002","6003"](JSONArray对应的roomid,如果解析出错,会报414错误),限20个roomid
bool $needOnlineUserCount 是否需要返回在线人数,true或false,默认false

Return Value

array $result 或 ['error'=>true,'message'=>$message]

array chatRoomUpdate(int $roodId, string $name = '', string $announcement = '', string $broadcastUrl = '', array $ext = [], bool $needNotify = true, array $notifyExt = [])

更新聊天室信息

Parameters

int $roodId 聊天室id
string $name 聊天室名称 长度限制128个字符
string $announcement 公告,长度限制4096个字符
string $broadcastUrl 直播地址,长度限制1024个字符
array $ext 扩展字段,长度限制4096个字符
bool $needNotify true或false,是否需要发送更新通知事件,默认true
array $notifyExt 通知事件扩展字段,长度限制2048

Return Value

array $result['chatroom'] 或 ['error'=>true,'message'=>$message]

array chatRoomToggleCloseStatus(int $roomid, string $operator, bool $valid)

修改聊天室开/关闭状态

Parameters

int $roomid 聊天室id
string $operator 操作者账号,必须是创建者才可以操作
bool $valid true或false,false:关闭聊天室;true:打开聊天室

Return Value

array $result['desc'] 或 ['error'=>true,'message'=>$message]

array chatRoomSetMemberRole(int $roomid, string $operator, string $target, string $opt, bool $optValue, array $notifyExt = [])

设置聊天室内用户角色

Parameters

int $roomid 聊天室id
string $operator 操作者账号accid
string $target 被操作者账号accid
string $opt 操作: 1: 设置为管理员,operator必须是创建者 2:设置普通等级用户,operator必须是创建者或管理员 -1:设为黑名单用户,operator必须是创建者或管理员 -2:设为禁言用户,operator必须是创建者或管理员
bool $optValue true或false,true:设置;false:取消设置
array $notifyExt 通知扩展字段,长度限制2048,请使用json格式

备注: 返回的type字段可能为: LIMITED, //受限用户,黑名单+禁言 COMMON, //普通固定成员 CREATOR, //创建者 MANAGER, //管理员 TEMPORARY, //临时用户,非固定成员

Return Value

array $result['desc'] 或 ['error'=>true,'message'=>$message]

Exceptions

NetEaseIMException

array chatRoomRequestAddress(int $roomid, string $accId, int $clientType = null)

请求聊天室地址与令牌

Parameters

int $roomid 聊天室id
string $accId 进入聊天室的账号
int $clientType 1:weblink; 2:commonlink, 默认1

Return Value

array $result['addr'] 或 ['error'=>true,'message'=>$message]

array chatRoomSendMsg(int $roomid, string $msgId, string $fromAccId, int $msgType = null, int $resendFlag = 0, array $attach = [], array $ext = [], bool $highPriority = false)

发送聊天室消息

Parameters

int $roomid 聊天室id
string $msgId 客户端消息id,使用uuid等随机串,msgId相同的消息会被客户端去重
string $fromAccId 消息发出者的账号accid
int $msgType 消息类型: 0: 表示文本消息, 1: 表示图片, 2: 表示语音, 3: 表示视频, 4: 表示地理位置信息, 6: 表示文件, 10: 表示Tips消息, 100: 自定义消息类型
int $resendFlag 重发消息标记,0:非重发消息,1:重发消息,如重发消息会按照msgid检查去重逻辑
array $attach 消息内容,格式同消息格式示例中的body字段,长度限制2048字符
array $ext 消息扩展字段,内容可自定义,请使用JSON格式,长度限制4096
bool $highPriority 可选,true表示是高优先级消息,云信会优先保障投递这部分消息;false表示低优先级消息。默认false。强烈建议应用恰当选择参数,以便在必要时,优先保障应用内的高优先级消息的投递。若全部设置为高优先级,则等于没有设置。

Return Value

array $result['desc'] 或 ['error'=>true,'message'=>$message]

array chatRoomSendTxtMessage(int $roomid, string $msgId, string $fromAccId, string $msg, int $resendFlag = 0, array $ext = [])

发送聊天室文字消息封装

Parameters

int $roomid 聊天室id
string $msgId 客户端消息id,使用uuid等随机串,msgId相同的消息会被客户端去重
string $fromAccId 消息发出者的账号accid
string $msg 文本消息内容
int $resendFlag 重发消息标记,0:非重发消息,1:重发消息,如重发消息会按照msgid检查去重逻辑
array $ext 消息扩展字段,内容可自定义,请使用JSON格式,长度限制4096

Return Value

array $result['desc'] 或 ['error'=>true,'message'=>$message]

array chatRoomAddRobot(int $roomid, array $accIds, array $roleExt = [], array $notifyExt = [])

往聊天室内添加机器人,机器人过期时间为24小时。

Parameters

int $roomid 聊天室id
array $accIds 机器人账号accid列表,必须是有效账号,账号数量上限100个
array $roleExt 机器人信息扩展字段,请使用json格式,长度4096字符
array $notifyExt 机器人进入聊天室通知的扩展字段,请使用json格式,长度2048字符

Return Value

array $result['desc'] 或 ['error'=>true,'message'=>$message]

array chatRoomRemoveRobot(int $roomid, array $accIds)

从聊天室内删除机器人

Parameters

int $roomid 聊天室id
array $accIds 机器人账号accid列表,必须是有效账号,账号数量上限100个

Return Value

array $result['desc'] 或 ['error'=>true,'message'=>$message]

array chatRoomTemporaryMute(int $roomid, string $operator, string $target, string $muteDuration, bool $needNotify = true, array $notifyExt = [])

将聊天室内成员设置为临时禁言

Parameters

int $roomid
string $operator 操作者accid,必须是管理员或创建者
string $target 被禁言的目标账号accid
string $muteDuration 0:解除禁言;>0设置禁言的秒数,不能超过2592000秒(30天)
bool $needNotify 操作完成后是否需要发广播,true或false,默认true
array $notifyExt 通知广播事件中的扩展字段,长度限制2048字符

Return Value

array $result['desc'] 或 ['error'=>true,'message'=>$message]

array|bool chatRoomQueueOffer(int $roomid, string $key, string $value, string $operator = null, string $transient = null)

往聊天室有序队列中新加或更新元素

Parameters

int $roomid 聊天室id
string $key elementKey,新元素的UniqKey,长度限制128字符
string $value elementValue,新元素内容,长度限制4096字符
string $operator 提交这个新元素的操作者accid,默认为该聊天室的创建者,若operator对应的帐号不存在,会返回404错误。若指定的operator不在线,则添加元素成功后的通知事件中的操作者默认为聊天室的创建者;若指定的operator在线,则通知事件的操作者为operator。
string $transient 这个新元素的提交者operator的所有聊天室连接在从该聊天室掉线或者离开该聊天室的时候,提交的元素是否需要删除。true:需要删除;false:不需要删除。默认false。当指定该参数为true时,若operator当前不在该聊天室内,则会返回403错误。

Return Value

array|bool true 或 ['error'=>true,'message'=>$message]

array chatRoomQueuePoll(int $roomid, string $key)

从队列中取出元素

Parameters

int $roomid
string $key 目前元素的elementKey,长度限制128字符,不填表示取出头上的第一个

Return Value

array $result['desc'] 或 ['error'=>true,'message'=>$message]

array chatRoomQueueList(int $roomid)

排序列出队列中所有元素

Parameters

int $roomid

Return Value

array $result['desc']['list'] 或 ['error'=>true,'message'=>$message]

array|bool chatRoomQueueDrop(int $roomid)

删除清理整个队列

Parameters

int $roomid

Return Value

array|bool true 或 ['error'=>true,'message'=>$message]

bool|array chatRoomQueueInit(int $roomid, int $sizeLimit)

初始化队列

Parameters

int $roomid
int $sizeLimit 队列长度限制,0~1000

Return Value

bool|array true 或 ['error'=>true,'message'=>$message]

Exceptions

NetEaseIMException

array|bool chatRoomMuteRoom(int $roomid, string $operator, bool $mute = false, bool $needNotify = true, string $notifyExt = '')

设置聊天室整体禁言状态(仅创建者和管理员能发言)

Parameters

int $roomid 聊天室id
string $operator 操作者accid,必须是管理员或创建者
bool $mute true或false
bool $needNotify true或false,默认true
string $notifyExt 通知扩展字段

Return Value

array|bool true 或 ['error'=>true,'message'=>$message]

array chatRoomTopn(int $topn = 100, int $timestamp = null, string $period = 'day', string $orderby = 'active')

查询聊天室统计指标TopN

Parameters

int $topn topn值,可选值 1~500,默认值100
int $timestamp 需要查询的指标所在的时间坐标点,不提供则默认当前时间,单位秒/毫秒皆可
string $period 统计周期,可选值包括 hour/day, 默认hour
string $orderby 取排序值,可选值 active/enter/message,分别表示按日活排序,进入人次排序和消息数排序, 默认active

Return Value

array $result['data'] 或 ['error'=>true,'message'=>$message]

array chatRoomMembersByPage(int $roomid, int $type = 0, int $endtime = 0, int $limit = 100)

分页获取成员列表

Parameters

int $roomid 聊天室id
int $type 需要查询的成员类型,0:固定成员;1:非固定成员;2:仅返回在线的固定成员
int $endtime 单位毫秒,按时间倒序最后一个成员的时间戳,0表示系统当前时间
int $limit 返回条数,<=100

Return Value

array $result['desc']['data'] 或 ['error'=>true,'message'=>$message]

array chatRoomQueryMembers(int $roomid, array $accids)

批量获取在线成员信息

Parameters

int $roomid 聊天室id
array $accids 账号列表,最多200条

Return Value

array $result['desc']['data'] 或 ['error'=>true,'message'=>$message]

array|bool chatRoomUpdateMyRoomRole(int $roomid, string $accid, bool $save = false, bool $needNotify = false, string $notifyExt = '', string $nick = '', string $avator = '', string $ext = '')

变更聊天室内的角色信息

Parameters

int $roomid
string $accid
bool $save
bool $needNotify
string $notifyExt
string $nick
string $avator
string $ext

Return Value

array|bool true 或 ['error'=>true,'message'=>$message]

array chatRoomQueueBatchUpdateElements(int $roomid, string $operator, array $elements, bool $needNotify = true, string $notifyExt = '')

批量更新聊天室队列元素

Parameters

int $roomid
string $operator
array $elements
bool $needNotify
string $notifyExt

Return Value

array $result['desc'] 或 ['error'=>true,'message'=>$message]

array chatRoomQueryUserRoomIds(string $creator)

查询用户创建的开启状态聊天室列表

Parameters

string $creator 聊天室创建者accid

Return Value

array $result['desc']['roomids'] 或 ['error'=>true,'message'=>$message]