package message import "encoding/xml" //MsgType 基本消息类型 type MsgType string //EventType 事件类型 type EventType string const ( //MsgTypeText 表示文本消息 MsgTypeText MsgType = "text" //MsgTypeImage 表示图片消息 MsgTypeImage = "image" //MsgTypeVoice 表示语音消息 MsgTypeVoice = "voice" //MsgTypeVideo 表示视频消息 MsgTypeVideo = "video" //MsgTypeShortVideo 表示短视频消息[限接收] MsgTypeShortVideo = "shortvideo" //MsgTypeLocation 表示坐标消息[限接收] MsgTypeLocation = "location" //MsgTypeLink 表示链接消息[限接收] MsgTypeLink = "link" //MsgTypeMusic 表示音乐消息[限回复] MsgTypeMusic = "music" //MsgTypeNews 表示图文消息[限回复] MsgTypeNews = "news" //MsgTypeTransfer 表示消息消息转发到客服 MsgTypeTransfer = "transfer_customer_service" ) const ( //EventSubscribe 订阅 EventSubscribe EventType = "subscribe" //EventUnsubscribe 取消订阅 EventUnsubscribe EventType = "unsubscribe" //EventScan 用户已经关注公众号,则微信会将带场景值扫描事件推送给开发者 EventScan EventType = "SCAN" //EventLocation 上报地理位置事件 EventLocation EventType = "LOCATION" //EventClick 点击菜单拉取消息时的事件推送 EventClick EventType = "CLICK" //EventView 点击菜单跳转链接时的事件推送 EventView EventType = "VIEW" ) //MixMessage 存放所有微信发送过来的消息和事件 type MixMessage struct { CommonToken //基本消息 MsgID int64 `xml:"MsgId"` Content string `xml:"Content"` PicURL string `xml:"PicUrl"` MediaID string `xml:"MediaId"` Format string `xml:"Format"` ThumbMediaID string `xml:"ThumbMediaId"` LocationX float64 `xml:"Location_X"` LocationY float64 `xml:"Location_Y"` Scale float64 `xml:"Scale"` Label string `xml:"Label"` Title string `xml:"Title"` Description string `xml:"Description"` URL string `xml:"Url"` //事件相关 Event string `xml:"Event"` EventKey string `xml:"EventKey"` Ticket string `xml:"Ticket"` Latitude string `xml:"Latitude"` Longitude string `xml:"Longitude"` Precision string `xml:"Precision"` } //EncryptedXMLMsg 安全模式下的消息体 type EncryptedXMLMsg struct { XMLName struct{} `xml:"xml" json:"-"` ToUserName string `xml:"ToUserName" json:"ToUserName"` EncryptedMsg string `xml:"Encrypt" json:"Encrypt"` } //ResponseEncryptedXMLMsg 需要返回的消息体 type ResponseEncryptedXMLMsg struct { XMLName struct{} `xml:"xml" json:"-"` EncryptedMsg string `xml:"Encrypt" json:"Encrypt"` MsgSignature string `xml:"MsgSignature" json:"MsgSignature"` Timestamp int64 `xml:"TimeStamp" json:"TimeStamp"` Nonce string `xml:"Nonce" json:"Nonce"` } // CommonToken 消息中通用的结构 type CommonToken struct { XMLName xml.Name `xml:"xml"` ToUserName string `xml:"ToUserName"` FromUserName string `xml:"FromUserName"` CreateTime int64 `xml:"CreateTime"` MsgType MsgType `xml:"MsgType"` } //SetToUserName set ToUserName func (msg *CommonToken) SetToUserName(toUserName string) { msg.ToUserName = toUserName } //SetFromUserName set FromUserName func (msg *CommonToken) SetFromUserName(fromUserName string) { msg.FromUserName = fromUserName } //SetCreateTime set createTime func (msg *CommonToken) SetCreateTime(createTime int64) { msg.CreateTime = createTime } //SetMsgType set MsgType func (msg *CommonToken) SetMsgType(msgType MsgType) { msg.MsgType = msgType }