class NetEaseIM (View source)

网易云信API

Traits

短信功能
网易云通信ID 用户名片、设置、关系托管
历史记录
聊天室
群组功能(高级群)
消息功能

Properties

protected $debug
protected $baseUrl
protected $client
protected $appKey
protected $appSecret
protected string $Nonce
protected int $CurTime
protected $CheckSum

Methods

array
smsSendcode(string $mobile, int $templateid, int $authCode = null, int $codeLen = 4, string $deviceId = null, bool $needUp = false)

发送短信/语音短信验证码

from SmsTrait
array|bool
smsVerifycode(string $mobile, string $code)

校验指定手机号的验证码是否合法。

from SmsTrait
array
smsSendtemplate(int $templateid, array $mobiles, array $params = [], bool $needUp = false)

发送模板短信

from SmsTrait
array
smsQuerystatus(int $sendid)

查询通知类和运营类短信发送状态 根据短信的sendid(sendtemplate.action接口中的返回值),查询短信发送结果。

from SmsTrait
array
userCreateUserId(string $accid, string $mobile = '', string $name = '', int $gender = 0, array $props = [], string $icon = '', string $token = '', string $sign = '', string $email = '', string $birth = '', string $ex = '')

创建云信ID 1.第三方帐号导入到云信平台; 2.注意accid,name长度以及考虑管理秘钥token

from UserTrait
array|bool
userUpdateUserId(string $accid, string $name = '', array $props = [], string $token = '')

更新云信ID

from UserTrait
array
userRefreshToken($accid)

更新并获取新token

from UserTrait
bool|array
userBlockUser(string $accId, bool $needKick = false)

封禁网易云通信ID

from UserTrait
bool|array
userUnBlockUser(string $accId)

解封网易云通信ID

from UserTrait
bool|array
userUpdateUserInfo(string $accId, string $name = null, string $icon = null, string $sign = null, string $email = null, string $birth = null, string $mobile = null, string $gender = null, string $ex = null)

更新用户名片

from UserTrait
array
userGetUserInfo(array $accIds)

获取用户名片

from UserTrait
bool|array
userSetDonnop(string $accId, bool $donnopOpen = false)

设置桌面端在线时,移动端是否需要推送

from UserTrait
bool|array
userMute(string $accid, bool $mute = true)

账号全局禁言 设置或取消账号的全局禁言状态;账号被设置为全局禁言后,不能发送“点对点”、“群”、“聊天室”消息

from UserTrait
bool|array
userMuteAv(string $accid, bool $mute = true)

账号全局禁用音视频 账号被设置为禁用音视频后,不能发起点对点音视频、创建多人音视频、发起点对点白板、创建多人白板

from UserTrait
bool|array
userAddFriend(string $accId, string $fAccId, string $type, string $msg = '')

添加好友

from UserTrait
bool|array
userUpdateFriend(string $accId, string $fAccId, string $alias)

更新好友相关信息

from UserTrait
bool|array
userDeleteFriend(string $accId, string $fAccId)

删除好友

from UserTrait
array
userGetFriend(string $accId, int $createTime = 0)

获取好友关系

from UserTrait
bool|array
userSetSpecialRelation(string $accId, string $targetAcc, int $relationType, int $value)

设置黑名单/静音

from UserTrait
array
userListBlackAndMuteList(string $accId)

查看/获取 指定用户的黑名单和静音列表

from UserTrait
array
historyQuerySessionMsg(string $from, string $to, string $begintime, string $endtime = null, int $limit = 100, int $reverse = 2, string $type = null)

单聊云端历史消息查询

array
historyQueryTeamMsg(string $tid, string $accid, string $begintime, string $endtime = null, int $limit = 100, int $reverse = 2, string $type = null)

群聊云端历史消息查询

array
historyQueryChatroomMsg(int $roomid, string $accid, string $timetag, int $limit = 100, int $reverse = 2, string $type = null)

聊天室云端历史消息查询 此接口有频控限制,每分钟可调用不超过1200次

bool|array
historyDeleteHistoryMessage(int $roomid, string $fromAcc, int $msgTimetag)

删除聊天室云端历史消息

array
historyQueryUserEvents(string $accid, string $begintime, string $endtime, int $limit = 100, int $reverse = 2)

用户登录登出事件记录查询 跟据时间段查询用户的登录登出记录,每次最多返回100条。 不提供分页支持,第三方需要跟据时间段来查询。

array|bool
historyDeleteMediaFile(int $channelid)

删除音视频/白板服务器录制文件

array
historyQueryBroadcastMsg(int $broadcastId = 0, int $limit = 100, int $type = 1)

批量查询广播消息

array
historyQueryBroadcastMsgById(int $broadcastId)

查询单条广播消息

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)

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

array
teamCreate(string $tname, string $owner, string $icon, array $members, string $custom = '', string $msg = 'msg', string $announcement = '', string $intro = '', int $mAgree = null, int $joinMode = null, int $beInviteMode = null, int $inviteMode = null, int $uptInfoMode = null, int $upCustomMode = null)

创建群组

from TeamTrait
array
teamAdd(string $tid, string $owner, array $members, string $msg, int $mAgree = null, string $attach = '')

拉人入群

from TeamTrait
array|bool
teamKick(string $tid, string $owner, string $member, string $attach)

踢人出群

from TeamTrait
array|bool
teamRemove(string $tid, string $owner)

解散群

from TeamTrait
array|bool
teamUpdate(string $tid, string $tname, string $owner, string $icon = '', string $custom = '', string $announcement = '', string $intro = '', int $joinMode = null, int $beInviteMode = null, int $inviteMode = null, int $uptInfoMode = null, int $upCustomMode = null)

更新群组

from TeamTrait
array
teamQuery(array $tids, int $ope = null)

群信息与成员列表查询 高级群信息与成员列表查询,一次最多查询30个群相关的信息,跟据ope参数来控制是否带上群成员列表; 查询群成员会稍微慢一些,所以如果不需要群成员列表可以只查群信息; 此接口受频率控制,某个应用一分钟最多查询30次,超过会返回416,并且被屏蔽一段时间; 群成员的群列表信息中增加管理员成员admins的返回

from TeamTrait
array
teamQueryDetail(string $tid)

获取群组详细信息 查询指定群的详细信息(群信息+成员详细信息)

from TeamTrait
array
teamGetMarkReadInfo(string $tid, string $msgid, string $fromAccid, bool $snapshot = false)

获取群组已读消息的已读详情信息

from TeamTrait
array|bool
TeamChangeOwner(string $tid, string $owner, string $newOwner, int $leave = null)

移交群主 转换群主身份; 群主可以选择离开此群,还是留下来成为普通成员。

from TeamTrait
array|bool
teamAddManager(string $tid, string $owner, array $members)

任命管理员 提升普通成员为群管理员,可以批量,但是一次添加最多不超过10个人。

from TeamTrait
array|bool
teamRemoveManager(string $tid, string $owner, array $members)

移除管理员 解除管理员身份,可以批量,但是一次解除最多不超过10个人

from TeamTrait
array
teamJoinTeams(string $accid)

获取某个用户所加入高级群的群信息

from TeamTrait
array|bool
teamUpdateTeamNick(string $tid, string $owner, string $accid, string $nick, string $custom = '')

修改群昵称

from TeamTrait
array|bool
teamMuteTeam(string $tid, string $accid, int $ope)

修改消息提醒开关

from TeamTrait
array|bool
teamMuteTlist(string $tid, string $owner, string $accid, int $mute = 0)

禁言群成员

from TeamTrait
array|bool
teamLeave(string $tid, string $accid)

主动退群

from TeamTrait
array|bool
teamMuteTlistAll(string $tid, string $owner, int $mute = 0)

将群组整体禁言

from TeamTrait
array
teamListTeamMute(string $tid, string $owner)

获取群组禁言列表

from TeamTrait
array
messageSendMsg(string $from, string $ope, string $to, string $type, array $body, array $option = [], string $pushContent = '', array $payload = [], array $ext = [], array $forcePushList = [], string $forcePushContent = '', bool $forcePushAll = false)

发送普通消息

array
messageSendTxtMsgToUser(string $from, string $to, string $msg, string $pushContent)

给个人发送文本消息封装

array
messageSendCustomMsgToUser(string $from, string $to, string $msg, string $pushContent)

给个人发送自定义消息封装

array
messageMsgSendBatchMsg($fromAccid, $toAccids, $type, array $body, array $option = [], string $pushcontent = '', string $payload = '', array $ext = [], string $bid = '', string $useYidun = '')

批量发送点对点普通消息 1.给用户发送点对点普通消息,包括文本,图片,语音,视频,地理位置和自定义消息。 2.最大限500人,只能针对个人,如果批量提供的帐号中有未注册的帐号,会提示并返回给用户。 3.此接口受频率控制,一个应用一分钟最多调用120次,超过会返回416状态码,并且被屏蔽一段时间; 具体消息参考官方文档。

bool|array
messageMsgSendAttachMsg(string $from, int $msgtype, string $to, array $attach, array $option = [], string $pushcontent = '', string $payload = '', string $sound = '', int $save = 2)

发送自定义系统通知 1.自定义系统通知区别于普通消息,方便开发者进行业务逻辑的通知; 2.目前支持两种类型:点对点类型和群类型(仅限高级群),根据msgType有所区别。 应用场景:如某个用户给另一个用户发送好友请求信息等,具体attach为请求消息体,第三方可以自行扩展,建议是json格式

array
messageMsgSendBatchAttachMsg($fromAccid, $toAccids, $attach, $option = [], $pushcontent = '', $payload = '', $sound = '', $save = 2)

批量发送点对点自定义系统通知 1.系统通知区别于普通消息,应用接收到直接交给上层处理,客户端可不做展示; 2.目前支持类型:点对点类型; 3.最大限500人,只能针对个人,如果批量提供的帐号中有未注册的帐号,会提示并返回给用户; 4.此接口受频率控制,一个应用一分钟最多调用120次,超过会返回416状态码,并且被屏蔽一段时间; 应用场景:如某个用户给另一个用户发送好友请求信息等,具体attach为请求消息体,第三方可以自行扩展,建议是json格式

string|array
messageMsgUpload($content, string $type = '', string $ishttps = '', string $expireSec = '', string $tag = '')

文件上传 文件上传,字符流需要base64编码,最大15M。

string|array
messageMsgFileUpload($content, string $type = '', string $ishttps = '', string $expireSec = '', string $tag = '')

文件上传(multipart方式) 文件上传,最大15M

bool|array
messageMsgRecall(string $deleteMsgid, int $timetag, int $type, string $from, string $to, string $msg = '', string $ignoreTime = '')

消息撤回 消息撤回接口,可以撤回一定时间内的点对点与群消息

array
messageMsgBroadcastMsg(string $body, string $from = '', bool $isOffline = false, int $ttl = 168, array $targetOs = [])

发送广播消息 1、广播消息,可以对应用内的所有用户发送广播消息,广播消息目前暂不支持第三方推送(APNS、小米、华为等); 2、广播消息支持离线存储,并可以自定义设置离线存储的有效期,最多保留最近100条离线广播消息; 3、此接口受频率控制,一个应用一分钟最多调用10次,一天最多调用1000次,超过会返回416状态码; 4、该功能目前需申请开通,详情可咨询您的客户经理。

__construct($appKey = null, $appSecret = null)

NetEaseIM constructor.

mixed
post($url, $data)

组装网易云接口必要数据,发送http post请求

void
setDebug(bool $debug)

设置\GuzzleHttp\Client调试

string
boolConvertToString(bool $bool)

布尔转字符串

array
arrCheckAndPush($array, string $key, string $value)

数组检查追加

Details

array smsSendcode(string $mobile, int $templateid, int $authCode = null, int $codeLen = 4, string $deviceId = null, bool $needUp = false)

发送短信/语音短信验证码

Parameters

string $mobile 目标手机号,非中国大陆手机号码需要填写国家代码(如美国:+1-xxxxxxxxxx)或地区代码(如香港:+852-xxxxxxxx)
int $templateid 模板编号(如不指定则使用配置的默认模版)
int $authCode 客户自定义验证码,长度为4~10个数字;如果设置了该参数,则codeLen参数无效
int $codeLen 验证码长度,范围4~10,默认为4
string $deviceId 目标设备号,可选参数
bool $needUp 是否需要支持短信上行。true:需要,false:不需要;说明:如果开通了短信上行抄送功能,该参数需要设置为true,其它情况设置无效

Return Value

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

array|bool smsVerifycode(string $mobile, string $code)

校验指定手机号的验证码是否合法。

Parameters

string $mobile 目标手机号,非中国大陆手机号码需要填写国家代码(如美国:+1-xxxxxxxxxx)或地区代码(如香港:+852-xxxxxxxx)
string $code 验证码

Return Value

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

array smsSendtemplate(int $templateid, array $mobiles, array $params = [], bool $needUp = false)

发送模板短信

Parameters

int $templateid 模板编号(由客户顾问配置之后告知开发者)
array $mobiles 接收者号码列表,JSONArray格式,如["186xxxxxxxx","186xxxxxxxx"],限制接收者号码个数最多为100个;非中国大陆手机号码需要填写国家代码(如美国:+1-xxxxxxxxxx)或地区代码(如香港:+852-xxxxxxxx)
array $params 短信参数列表,用于依次填充模板,JSONArray格式,每个变量长度不能超过30字,如["xxx","yyy"];对于不包含变量的模板,不填此参数表示模板即短信全文内容
bool $needUp 是否需要支持短信上行。true:需要,false:不需要;说明:如果开通了短信上行抄送功能,该参数需要设置为true,其它情况设置无效

Return Value

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

array smsQuerystatus(int $sendid)

查询通知类和运营类短信发送状态 根据短信的sendid(sendtemplate.action接口中的返回值),查询短信发送结果。

Parameters

int $sendid 发送短信的编号sendid

Return Value

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

array userCreateUserId(string $accid, string $mobile = '', string $name = '', int $gender = 0, array $props = [], string $icon = '', string $token = '', string $sign = '', string $email = '', string $birth = '', string $ex = '')

创建云信ID 1.第三方帐号导入到云信平台; 2.注意accid,name长度以及考虑管理秘钥token

Parameters

string $accid [云信ID,最大长度32字节,必须保证一个APP内唯一(只允许字母、数字、半角下划线_、@、半角点以及半角-组成,不区分大小写,会统一小写处理)]
string $mobile 用户mobile,最大长度32字符,只支持国内号码
string $name [云信ID昵称,最大长度64字节,用来PUSH推送时显示的昵称]
int $gender 用户性别,0表示未知,1表示男,2女表示女,其它会报参数错误
array $props [json属性,第三方可选填,最大长度1024字节]
string $icon [云信ID头像URL,第三方可选填,最大长度1024]
string $token [云信ID可以指定登录token值,最大长度128字节,并更新,如果未指定,会自动生成token,并在创建成功后返回]
string $sign 用户签名,最大长度256字符
string $email 用户email,最大长度64字符
string $birth 用户生日,最大长度16字符
string $ex 用户名片扩展字段,最大长度1024字符,用户可自行扩展,建议封装成JSON字符串

Return Value

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

array|bool userUpdateUserId(string $accid, string $name = '', array $props = [], string $token = '')

更新云信ID

Parameters

string $accid [云信ID,最大长度32字节,必须保证一个APP内唯一(只允许字母、数字、半角下划线_、@、半角点以及半角-组成,不区分大小写,会统一小写处理)]
string $name [云信ID昵称,最大长度64字节,用来PUSH推送时显示的昵称]
array $props [json属性,第三方可选填,最大长度1024字节]
string $token [云信ID可以指定登录token值,最大长度128字节,并更新,如果未指定,会自动生成token,并在创建成功后返回]

Return Value

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

array userRefreshToken($accid)

更新并获取新token

Parameters

$accid [云信ID,最大长度32字节,必须保证一个APP内唯一(只允许字母、数字、半角下划线_、@、半角点以及半角-组成,不区分大小写,会统一小写处理)]

Return Value

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

bool|array userBlockUser(string $accId, bool $needKick = false)

封禁网易云通信ID

Parameters

string $accId
bool $needKick 是否踢掉被禁用户, 默认 false

Return Value

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

bool|array userUnBlockUser(string $accId)

解封网易云通信ID

Parameters

string $accId

Return Value

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

bool|array userUpdateUserInfo(string $accId, string $name = null, string $icon = null, string $sign = null, string $email = null, string $birth = null, string $mobile = null, string $gender = null, string $ex = null)

更新用户名片

Parameters

string $accId
string $name 用户昵称,最大长度64字符
string $icon 用户icon,最大长度1024字符
string $sign 用户签名,最大长度256字符
string $email 用户email,最大长度64字符
string $birth 用户生日,最大长度16字符
string $mobile 用户mobile,最大长度32字符,只支持国内号码
string $gender 用户性别,0表示未知,1表示男,2女表示女,其它会报参数错误
string $ex 用户名片扩展字段,最大长度1024字符,用户可自行扩展,建议封装成JSON字符串

Return Value

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

array userGetUserInfo(array $accIds)

获取用户名片

Parameters

array $accIds 最多可以200个

Return Value

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

bool|array userSetDonnop(string $accId, bool $donnopOpen = false)

设置桌面端在线时,移动端是否需要推送

Parameters

string $accId
bool $donnopOpen 桌面端在线时,移动端是否不推送:true:移动端不需要推送,false:移动端需要推送

Return Value

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

bool|array userMute(string $accid, bool $mute = true)

账号全局禁言 设置或取消账号的全局禁言状态;账号被设置为全局禁言后,不能发送“点对点”、“群”、“聊天室”消息

Parameters

string $accid 用户帐号
bool $mute 是否全局禁言:true:全局禁言,false:取消全局禁言

Return Value

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

bool|array userMuteAv(string $accid, bool $mute = true)

账号全局禁用音视频 账号被设置为禁用音视频后,不能发起点对点音视频、创建多人音视频、发起点对点白板、创建多人白板

Parameters

string $accid 用户帐号
bool $mute 是否全局禁用音视频:true:全局禁用音视频,false:取消全局禁用音视频

Return Value

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

bool|array userAddFriend(string $accId, string $fAccId, string $type, string $msg = '')

添加好友

Parameters

string $accId 加好友发起者accid
string $fAccId 加好友接收者accid
string $type 1直接加好友,2请求加好友,3同意加好友,4拒绝加好友
string $msg

Return Value

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

Exceptions

NetEaseIMException

bool|array userUpdateFriend(string $accId, string $fAccId, string $alias)

更新好友相关信息

Parameters

string $accId 发起者accid
string $fAccId 要修改朋友的accid
string $alias 给好友增加备注名,限制长度128

Return Value

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

bool|array userDeleteFriend(string $accId, string $fAccId)

删除好友

Parameters

string $accId 发起者accid
string $fAccId 要删除的好友accid

Return Value

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

array userGetFriend(string $accId, int $createTime = 0)

获取好友关系

Parameters

string $accId 发起者accid
int $createTime 更新时间戳,接口返回该时间戳之后有更新的好友列表

Return Value

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

bool|array userSetSpecialRelation(string $accId, string $targetAcc, int $relationType, int $value)

设置黑名单/静音

Parameters

string $accId
string $targetAcc
int $relationType 本次操作的关系类型,1:黑名单操作,2:静音列表操作
int $value 操作值,0:取消黑名单或静音,1:加入黑名单或静音

Return Value

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

Exceptions

NetEaseIMException

array userListBlackAndMuteList(string $accId)

查看/获取 指定用户的黑名单和静音列表

Parameters

string $accId

Return Value

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

array historyQuerySessionMsg(string $from, string $to, string $begintime, string $endtime = null, int $limit = 100, int $reverse = 2, string $type = null)

单聊云端历史消息查询

Parameters

string $from 发送者accid
string $to 接收者accid
string $begintime 开始时间,ms
string $endtime 截止时间,ms
int $limit 本次查询的消息条数上限(最多100条),小于等于0,或者大于100,会提示参数错误
int $reverse 1按时间正序排列,2按时间降序排列。其它返回参数414错误.默认是按降序排列
string $type 查询指定的多个消息类型,类型之间用","分割,不设置该参数则查询全部类型消息格式示例: 0,1,2,3;类型支持: 1:图片,2:语音,3:视频,4:地理位置,5:通知,6:文件,10:提示,11:Robot,100:自定义

Return Value

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

array historyQueryTeamMsg(string $tid, string $accid, string $begintime, string $endtime = null, int $limit = 100, int $reverse = 2, string $type = null)

群聊云端历史消息查询

Parameters

string $tid 群id
string $accid 查询用户对应的accid
string $begintime 开始时间,ms
string $endtime 截止时间,ms
int $limit 本次查询的消息条数上限(最多100条),小于等于0,或者大于100,会提示参数错误
int $reverse 1按时间正序排列,2按时间降序排列。其它返回参数414错误.默认是按降序排列
string $type 查询指定的多个消息类型,类型之间用","分割,不设置该参数则查询全部类型消息格式示例: 0,1,2,3;类型支持: 1:图片,2:语音,3:视频,4:地理位置,5:通知,6:文件,10:提示,11:Robot,100:自定义

Return Value

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

array historyQueryChatroomMsg(int $roomid, string $accid, string $timetag, int $limit = 100, int $reverse = 2, string $type = null)

聊天室云端历史消息查询 此接口有频控限制,每分钟可调用不超过1200次

Parameters

int $roomid 聊天室id
string $accid 查询用户对应的accid
string $timetag 查询的时间戳锚点,13位。reverse=1时timetag为起始时间戳,reverse=2时timetag为终止时间戳
int $limit 本次查询的消息条数上限(最多200条),小于等于0,或者大于200,会提示参数错误
int $reverse 1按时间正序排列,2按时间降序排列。其它返回参数414错误.默认是按降序排列
string $type 查询指定的多个消息类型,类型之间用","分割,不设置该参数则查询全部类型消息格式示例: 0,1,2,3;类型支持: 1:图片,2:语音,3:视频,4:地理位置,5:通知,6:文件,10:提示,11:Robot,100:自定义

Return Value

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

bool|array historyDeleteHistoryMessage(int $roomid, string $fromAcc, int $msgTimetag)

删除聊天室云端历史消息

Parameters

int $roomid 聊天室id
string $fromAcc 消息发送者的accid
int $msgTimetag 消息的时间戳,单位毫秒,应该拿到原始消息中的时间戳为参数

Return Value

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

array historyQueryUserEvents(string $accid, string $begintime, string $endtime, int $limit = 100, int $reverse = 2)

用户登录登出事件记录查询 跟据时间段查询用户的登录登出记录,每次最多返回100条。 不提供分页支持,第三方需要跟据时间段来查询。

Parameters

string $accid 要查询用户的accid
string $begintime 开始时间,ms
string $endtime 截止时间,ms
int $limit 本次查询的消息条数上限(最多100条),小于等于0,或者大于100,会提示参数错误
int $reverse 1按时间正序排列,2按时间降序排列。其它返回参数414错误。默认是按降序排列

Return Value

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

array|bool historyDeleteMediaFile(int $channelid)

删除音视频/白板服务器录制文件

Parameters

int $channelid 需要删除的文件的通道号

Return Value

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

array historyQueryBroadcastMsg(int $broadcastId = 0, int $limit = 100, int $type = 1)

批量查询广播消息

Parameters

int $broadcastId 查询的起始ID,0表示查询最近的limit条。默认0。
int $limit 查询的条数,最大100。默认100。
int $type 查询的类型,1表示所有,2表示查询存离线的,3表示查询不存离线的。默认1。

Return Value

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

array historyQueryBroadcastMsgById(int $broadcastId)

查询单条广播消息

Parameters

int $broadcastId 广播消息ID,应用内唯一。

Return Value

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

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]

array teamCreate(string $tname, string $owner, string $icon, array $members, string $custom = '', string $msg = 'msg', string $announcement = '', string $intro = '', int $mAgree = null, int $joinMode = null, int $beInviteMode = null, int $inviteMode = null, int $uptInfoMode = null, int $upCustomMode = null)

创建群组

创建高级群,以邀请的方式发送给用户; custom 字段是给第三方的扩展字段,第三方可以基于此字段扩展高级群的功能,构建自己需要的群; 建群成功会返回tid,需要保存,以便于加人与踢人等后续操作; 每个用户可创建的群数量有限制,限制值由 IM 套餐的群组配置决定,可登录管理后台查看。

Parameters

string $tname 群名称,最大长度64字符
string $owner 群主用户帐号,最大长度32字符
string $icon 群头像,最大长度1024字符
array $members "aaa","bbb",一次最多拉200个成员
string $custom 自定义高级群扩展属性,第三方可以跟据此属性自定义扩展自己的群属性。(建议为json),最大长度1024字符
string $msg 邀请发送的文字,最大长度150字符
string $announcement 群公告,最大长度1024字符
string $intro 群描述,最大长度512字符
int $mAgree 管理后台建群时,0不需要被邀请人同意加入群,1需要被邀请人同意才可以加入群。其它会返回414
int $joinMode 群建好后,sdk操作时,0不用验证,1需要验证,2不允许任何人加入。其它返回414
int $beInviteMode 被邀请人同意方式,0-需要同意(默认),1-不需要同意。其它返回414
int $inviteMode 谁可以邀请他人入群,0-管理员(默认),1-所有人。其它返回414
int $uptInfoMode 谁可以修改群资料,0-管理员(默认),1-所有人。其它返回414
int $upCustomMode 谁可以更新群自定义属性,0-管理员(默认),1-所有人。其它返回414

Return Value

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

array teamAdd(string $tid, string $owner, array $members, string $msg, int $mAgree = null, string $attach = '')

拉人入群

Parameters

string $tid 网易云通信服务器产生,群唯一标识,创建群时会返回,最大长度128字符
string $owner 群主用户帐号,最大长度32字符
array $members "aaa","bbb",一次最多拉200个成员
string $msg 邀请发送的文字,最大长度150字符
int $mAgree 管理后台建群时,0不需要被邀请人同意加入群,1需要被邀请人同意才可以加入群。其它会返回414
string $attach 自定义扩展字段,最大长度512

Return Value

array $result 或 ['error'=>true,'message'=>$message],如果邀请的人中存在加群数量超限的情况,会返回faccid

array|bool teamKick(string $tid, string $owner, string $member, string $attach)

踢人出群

Parameters

string $tid 网易云通信服务器产生,群唯一标识,创建群时会返回,最大长度128字符
string $owner 群主用户帐号,最大长度32字符
string $member 被移除人的accid,用户账号,最大长度字符
string $attach 自定义扩展字段,最大长度512

Return Value

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

array|bool teamRemove(string $tid, string $owner)

解散群

Parameters

string $tid 网易云通信服务器产生,群唯一标识,创建群时会返回,最大长度128字符
string $owner 群主用户帐号,最大长度32字符

Return Value

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

array|bool teamUpdate(string $tid, string $tname, string $owner, string $icon = '', string $custom = '', string $announcement = '', string $intro = '', int $joinMode = null, int $beInviteMode = null, int $inviteMode = null, int $uptInfoMode = null, int $upCustomMode = null)

更新群组

Parameters

string $tid 易云通信服务器产生,群唯一标识,创建群时会返回
string $tname 群名称,最大长度64字符
string $owner 群主用户帐号,最大长度32字符
string $icon 群头像,最大长度1024字符
string $custom 自定义高级群扩展属性,第三方可以跟据此属性自定义扩展自己的群属性。(建议为json),最大长度1024字符
string $announcement 群公告,最大长度1024字符
string $intro 群描述,最大长度512字符
int $joinMode 群建好后,sdk操作时,0不用验证,1需要验证,2不允许任何人加入。其它返回414
int $beInviteMode 被邀请人同意方式,0-需要同意(默认),1-不需要同意。其它返回414
int $inviteMode 谁可以邀请他人入群,0-管理员(默认),1-所有人。其它返回414
int $uptInfoMode 谁可以修改群资料,0-管理员(默认),1-所有人。其它返回414
int $upCustomMode 谁可以更新群自定义属性,0-管理员(默认),1-所有人。其它返回414

Return Value

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

array teamQuery(array $tids, int $ope = null)

群信息与成员列表查询 高级群信息与成员列表查询,一次最多查询30个群相关的信息,跟据ope参数来控制是否带上群成员列表; 查询群成员会稍微慢一些,所以如果不需要群成员列表可以只查群信息; 此接口受频率控制,某个应用一分钟最多查询30次,超过会返回416,并且被屏蔽一段时间; 群成员的群列表信息中增加管理员成员admins的返回

Parameters

array $tids 群id列表,如["3083","3084"]
int $ope 1表示带上群成员列表,0表示不带群成员列表,只返回群信息

Return Value

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

array teamQueryDetail(string $tid)

获取群组详细信息 查询指定群的详细信息(群信息+成员详细信息)

Parameters

string $tid 群id

Return Value

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

array teamGetMarkReadInfo(string $tid, string $msgid, string $fromAccid, bool $snapshot = false)

获取群组已读消息的已读详情信息

Parameters

string $tid
string $msgid
string $fromAccid
bool $snapshot

Return Value

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

array|bool TeamChangeOwner(string $tid, string $owner, string $newOwner, int $leave = null)

移交群主 转换群主身份; 群主可以选择离开此群,还是留下来成为普通成员。

Parameters

string $tid 网易云通信服务器产生,群唯一标识,创建群时会返回,最大长度128字符
string $owner 群主用户帐号,最大长度32字符
string $newOwner 新群主帐号,最大长度32字符
int $leave 1:群主解除群主后离开群,2:群主解除群主后成为普通成员。其它414

Return Value

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

array|bool teamAddManager(string $tid, string $owner, array $members)

任命管理员 提升普通成员为群管理员,可以批量,但是一次添加最多不超过10个人。

Parameters

string $tid 群id
string $owner 群主用户accid
array $members 用户accid 数组

Return Value

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

array|bool teamRemoveManager(string $tid, string $owner, array $members)

移除管理员 解除管理员身份,可以批量,但是一次解除最多不超过10个人

Parameters

string $tid 群唯一标识,创建群时网易云通信服务器产生并返回
string $owner 群主 accid
array $members 用户accid 数组

Return Value

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

array teamJoinTeams(string $accid)

获取某个用户所加入高级群的群信息

Parameters

string $accid 要查询用户的accid

Return Value

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

array|bool teamUpdateTeamNick(string $tid, string $owner, string $accid, string $nick, string $custom = '')

修改群昵称

Parameters

string $tid 群唯一标识,创建群时网易云通信服务器产生并返回
string $owner 群主 accid
string $accid 要修改群昵称的群成员 accid
string $nick accid 对应的群昵称,最大长度32字符
string $custom 自定义扩展字段,最大长度1024字节

Return Value

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

array|bool teamMuteTeam(string $tid, string $accid, int $ope)

修改消息提醒开关

Parameters

string $tid 群唯一标识,创建群时网易云通信服务器产生并返回
string $accid 要操作的群成员accid
int $ope 1:关闭消息提醒,2:打开消息提醒,其他值无效

Return Value

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

array|bool teamMuteTlist(string $tid, string $owner, string $accid, int $mute = 0)

禁言群成员

Parameters

string $tid 群唯一标识,创建群时网易云通信服务器产生并返回
string $owner 要操作的群成员accid
string $accid 禁言对象的accid
int $mute 1-禁言,0-解禁

Return Value

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

array|bool teamLeave(string $tid, string $accid)

主动退群

Parameters

string $tid 群唯一标识,创建群时网易云通信服务器产生并返回
string $accid 禁言对象的accid

Return Value

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

array|bool teamMuteTlistAll(string $tid, string $owner, int $mute = 0)

将群组整体禁言

Parameters

string $tid 群唯一标识,创建群时网易云通信服务器产生并返回
string $owner 要操作的群成员accid
int $mute 1-禁言,0-解禁

Return Value

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

array teamListTeamMute(string $tid, string $owner)

获取群组禁言列表

Parameters

string $tid 群唯一标识,创建群时网易云通信服务器产生并返回
string $owner 群主的accid

Return Value

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

array messageSendMsg(string $from, string $ope, string $to, string $type, array $body, array $option = [], string $pushContent = '', array $payload = [], array $ext = [], array $forcePushList = [], string $forcePushContent = '', bool $forcePushAll = false)

发送普通消息

Parameters

string $from
string $ope 0:点对点个人消息,1:群消息,其他返回414
string $to ope==0是表示accid即用户id,ope==1表示tid即群id
string $type 0 表示文本消息, 1 表示图片, 2 表示语音, 3 表示视频, 4 表示地理位置信息, 6 表示文件, 100 自定义消息类型
array $body
array $option 发消息时特殊指定的行为选项,Json格式,可用于指定消息的漫游,存云端历史,发送方多端同步,推送,消息抄送等特殊行为;option中字段不填时表示默认值 option示例: {"push":false,"roam":true,"history":false,"sendersync":true,"route":false,"badge":false,"needPushNick":true}

                  字段说明:
                  1. roam: 该消息是否需要漫游,默认true(需要app开通漫游消息功能);
                  2. history: 该消息是否存云端历史,默认true;
                  3. sendersync: 该消息是否需要发送方多端同步,默认true;
                  4. push: 该消息是否需要APNS推送或安卓系统通知栏推送,默认true;
                  5. route: 该消息是否需要抄送第三方;默认true (需要app开通消息抄送功能);
                  6. badge:该消息是否需要计入到未读计数中,默认true;
                  7. needPushNick: 推送文案是否需要带上昵称,不设置该参数时默认true;
string $pushContent ios推送内容,不超过150字符,option选项中允许推送(push=true),此字段可以指定推送内容
array $payload ios 推送对应的payload,必须是JSON,不能超过2k字符
array $ext 开发者扩展字段,长度限制1024字符
array $forcePushList 发送群消息时的强推(@操作)用户列表 格式为JSONArray,如["accid1","accid2"]。若forcepushall为true,则forcepushlist为除发送者外的所有有效群成员
string $forcePushContent 发送群消息时,针对强推(@操作)列表forcepushlist中的用户,强制推送的内容
bool $forcePushAll 发送群消息时,强推(@操作)列表是否为群里除发送者外的所有有效成员,true或false,默认为false

Return Value

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

array messageSendTxtMsgToUser(string $from, string $to, string $msg, string $pushContent)

给个人发送文本消息封装

Parameters

string $from 发送者accid
string $to 个人用户accid
string $msg 消息内容
string $pushContent ios推送内容

Return Value

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

array messageSendCustomMsgToUser(string $from, string $to, string $msg, string $pushContent)

给个人发送自定义消息封装

Parameters

string $from 发送者accid
string $to 个人用户accid
string $msg 消息内容
string $pushContent ios推送内容

Return Value

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

array messageMsgSendBatchMsg($fromAccid, $toAccids, $type, array $body, array $option = [], string $pushcontent = '', string $payload = '', array $ext = [], string $bid = '', string $useYidun = '')

批量发送点对点普通消息 1.给用户发送点对点普通消息,包括文本,图片,语音,视频,地理位置和自定义消息。 2.最大限500人,只能针对个人,如果批量提供的帐号中有未注册的帐号,会提示并返回给用户。 3.此接口受频率控制,一个应用一分钟最多调用120次,超过会返回416状态码,并且被屏蔽一段时间; 具体消息参考官方文档。

Parameters

$fromAccid
$toAccids
$type
array $body
array $option
string $pushcontent
string $payload
array $ext
string $bid
string $useYidun

Return Value

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

bool|array messageMsgSendAttachMsg(string $from, int $msgtype, string $to, array $attach, array $option = [], string $pushcontent = '', string $payload = '', string $sound = '', int $save = 2)

发送自定义系统通知 1.自定义系统通知区别于普通消息,方便开发者进行业务逻辑的通知; 2.目前支持两种类型:点对点类型和群类型(仅限高级群),根据msgType有所区别。 应用场景:如某个用户给另一个用户发送好友请求信息等,具体attach为请求消息体,第三方可以自行扩展,建议是json格式

Parameters

string $from 发送者accid
int $msgtype 0:点对点自定义通知,1:群消息自定义通知,其他返回414
string $to msgtype==0是表示accid即用户id,msgtype==1表示tid即群id
array $attach
array $option
string $pushcontent
string $payload
string $sound
int $save

Return Value

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

array messageMsgSendBatchAttachMsg($fromAccid, $toAccids, $attach, $option = [], $pushcontent = '', $payload = '', $sound = '', $save = 2)

批量发送点对点自定义系统通知 1.系统通知区别于普通消息,应用接收到直接交给上层处理,客户端可不做展示; 2.目前支持类型:点对点类型; 3.最大限500人,只能针对个人,如果批量提供的帐号中有未注册的帐号,会提示并返回给用户; 4.此接口受频率控制,一个应用一分钟最多调用120次,超过会返回416状态码,并且被屏蔽一段时间; 应用场景:如某个用户给另一个用户发送好友请求信息等,具体attach为请求消息体,第三方可以自行扩展,建议是json格式

Parameters

$fromAccid
$toAccids
$attach
$option
$pushcontent
$payload
$sound
$save

Return Value

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

string|array messageMsgUpload($content, string $type = '', string $ishttps = '', string $expireSec = '', string $tag = '')

文件上传 文件上传,字符流需要base64编码,最大15M。

Parameters

$content
string $type
string $ishttps
string $expireSec
string $tag

Return Value

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

string|array messageMsgFileUpload($content, string $type = '', string $ishttps = '', string $expireSec = '', string $tag = '')

文件上传(multipart方式) 文件上传,最大15M

Parameters

$content
string $type
string $ishttps
string $expireSec
string $tag

Return Value

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

bool|array messageMsgRecall(string $deleteMsgid, int $timetag, int $type, string $from, string $to, string $msg = '', string $ignoreTime = '')

消息撤回 消息撤回接口,可以撤回一定时间内的点对点与群消息

Parameters

string $deleteMsgid 要撤回消息的msgid
int $timetag 要撤回消息的创建时间
int $type 7:表示点对点消息撤回,8:表示群消息撤回,其它为参数错误
string $from 发消息的accid
string $to 如果点对点消息,为接收消息的accid,如果群消息,为对应群的tid
string $msg 可以带上对应的描述
string $ignoreTime 1表示忽略撤回时间检测,其它为非法参数,如果需要撤回时间检测,不填即可

Return Value

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

array messageMsgBroadcastMsg(string $body, string $from = '', bool $isOffline = false, int $ttl = 168, array $targetOs = [])

发送广播消息 1、广播消息,可以对应用内的所有用户发送广播消息,广播消息目前暂不支持第三方推送(APNS、小米、华为等); 2、广播消息支持离线存储,并可以自定义设置离线存储的有效期,最多保留最近100条离线广播消息; 3、此接口受频率控制,一个应用一分钟最多调用10次,一天最多调用1000次,超过会返回416状态码; 4、该功能目前需申请开通,详情可咨询您的客户经理。

Parameters

string $body 广播消息内容,最大4096字符
string $from 发送者accid
bool $isOffline 是否存离线,true或false,默认false
int $ttl 存离线状态下的有效期,单位小时,默认7天
array $targetOs 目标客户端,默认所有客户端,jsonArray,格式:['ios','aos','pc','web','mac']

Return Value

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

__construct($appKey = null, $appSecret = null)

NetEaseIM constructor.

Parameters

$appKey
$appSecret

Exceptions

NetEaseIMException

mixed post($url, $data)

组装网易云接口必要数据,发送http post请求

Parameters

$url
$data

Return Value

mixed

Exceptions

NetEaseIMException
Exception

void setDebug(bool $debug)

设置\GuzzleHttp\Client调试

Parameters

bool $debug

Return Value

void

string boolConvertToString(bool $bool)

布尔转字符串

Parameters

bool $bool

Return Value

string

array arrCheckAndPush($array, string $key, string $value)

数组检查追加

Parameters

$array
string $key
string $value

Return Value

array