Skip to content

文字Text

HanSon edited this page Mar 16, 2017 · 1 revision

文字信息是最基础的信息之一,该类主要属性为 isAt,用于群组时判断是否@了自己

属性

属性 类型 含义
isAt bool 是否@了自己
msg array 文字消息的原始数组
content string 文字消息

msg

Array
(
    [MsgId] => 6682961776202044788
    [FromUserName] => @@f0c787edb5ee784f56a996de6a51a668e64aa871b454a8485ab030b1a792c9d4
    [ToUserName] => @0f4028485f19d1fe31c8a021b8575185
    [MsgType] => 1
    [Content] => hello world
    [Status] => 3
    [ImgStatus] => 1
    [CreateTime] => 1484626984
    [VoiceLength] => 0
    [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] => 6682961776202044788
    [OriContent] =>
)

方法

Text::send($username, 'hello vbot'); 发送文字消息

栗子

$robot->server->setMessageHandler(function ($message){
    
    // 收到消息时自动回复文字消息
    Text::send($message->from['UserName'], 'Hello, I'm Vbot');

    // @我自动回复
    if($message->isAt){
        return 'Why you @ me?';
    }

    // 直接返回字符串同样有用
    return 'Hello, I'm Vbot';
});
Clone this wiki locally