trait MessageTrait (View source)

消息功能

Methods

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、该功能目前需申请开通,详情可咨询您的客户经理。

Details

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]