Skip to content

语音Voice

HanSon edited this page Mar 16, 2017 · 1 revision

语音是较为特殊的消息类型,因为其并不能转发

语音文件会自动下载至缓存目录的mp3目录中,命名方式为 {msgID}.mp3

属性

属性 类型 含义
msg array 消息的原始数组

msg

Array
(
    [MsgId] => 4922959788134761128
    [FromUserName] => @2aefd23a286785769c6be1cd61d53efc
    [ToUserName] => @2aefd23a286785769c6be1cd61d53efc
    [MsgType] => 34
    [Content] => <msg><voicemsg endflag="1" cancelflag="0" forwardflag="0" voiceformat="4" voicelength="3353" length="4880" bufid="364633803086168409" clientmsgid="41393262376465323334653663393200321521011717b8182190d45100" fromusername="fasdsfsa" /></msg>
    [Status] => 3
    [ImgStatus] => 1
    [CreateTime] => 1484637691
    [VoiceLength] => 3353
    [PlayLength] => 0
    [FileName] =>
    [FileSize] =>
    [MediaId] =>
    [Url] =>
    [AppMsgType] => 0
    [StatusNotifyCode] => 0
    [StatusNotifyUserName] =>
    [RecommendInfo] => Array
        (
            [UserName] =>
            [NickName] =>
            [QQNum] => 0
            [Province] =>
            [City] =>
            [Content] =>
            [Signature] =>
            [Alias] =>
            [Scene] => 0
            [VerifyFlag] => 0
            [AttrStatus] => 0
            [Sex] => 0
            [Ticket] =>
            [OpCode] => 0
        )

    [ForwardFlag] => 0
    [AppInfo] => Array
        (
            [AppID] =>
            [Type] => 0
        )

    [HasProductId] => 0
    [Ticket] =>
    [ImgHeight] => 0
    [ImgWidth] => 0
    [SubMsgType] => 0
    [NewMsgId] => 4922959788134761128
    [OriContent] =>
)

栗子

$robot->server->setMessageHandler(function ($message){
    
    if($message instanceof Voice){
        return '收到一条语音并下载在' . $message->getPath($message::$folder) . "/{$message->msg['MsgId']}.mp3";
    }
});
Clone this wiki locally