目前WeRoBot共有以下几种Message: TextMessage , ImageMessage , LocationMessage , EventMessage , VoiceMessage [3]_ 和 UnknownMessage 。他们都继承自 WeChatMessage 。
除了 UnknownMessage, 每一种 Message 都包括以下属性:
name | value |
---|---|
id | 消息id,64位整型 [2] |
target | 信息的目标用户。通常是机器人用户。 |
source | 信息的来源用户。通常是发送信息的用户。 |
time | 信息发送的时间,一个UNIX时间戳。 |
raw | 信息的原始 XML 格式 |
name | value |
---|---|
type | ‘link’ |
title | 消息标题 |
description | 消息描述 |
url | 消息链接 |
LocationMessage的属性:
name | value |
---|---|
type | ‘location’ |
location | 一个元组。(纬度, 经度) |
scale | 地图缩放大小 |
label | 地理位置信息 |
EventMessage的属性:
name | value |
---|---|
type | ‘subscribe’ ‘unsubscribe’ ‘click’ 或 ‘location’ [1] |
key | 事件 key 值。当 type = ‘click’ 时存在。 |
Latitude | 地理位置纬度。当 type = ‘location’ 时存在。 |
Longitude | 地理位置经度。当 type = ‘location’ 时存在。 |
Precision | 地理位置精度。当 type = ‘location’ 时存在。 |
VoiceMessage的属性:
name | value |
---|---|
type | ‘voice’ |
media_id | 微信内部的一个文件ID。 |
format | 声音格式 |
recognition | 未公开字段,猜测为语音识别后的文字。 |
UnknownMessage的属性:
name | value |
---|---|
type | ‘unknown’ |
raw | 请求的正文部分。标准的XML格式。 |
Note
如果你不为 WeRoBot 贡献代码,你完全可以无视掉 UnknownMessage 。在正常的使用中,WeRoBot应该不会收到 UnknownMessage ——除非 WeRoBot 停止开发。
[1] | 当你被用户关注时,会收到 type=’subscribe’ 的事件; 被取消关注时是 type=’unsubscribe’ 。当用户点击自定义菜单按钮时 type 为 click ,用户上报地理位置的数据包 type 为 location |
[2] | 截至目前( 2013.03.16 ),微信机器人所收到的消息中都不包含 MsgID. |