message.go 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186
  1. package message
  2. import "encoding/xml"
  3. // MsgType 基本消息类型
  4. type MsgType string
  5. // EventType 事件类型
  6. type EventType string
  7. // InfoType 第三方平台授权事件类型
  8. type InfoType string
  9. const (
  10. //MsgTypeText 表示文本消息
  11. MsgTypeText MsgType = "text"
  12. //MsgTypeImage 表示图片消息
  13. MsgTypeImage = "image"
  14. //MsgTypeVoice 表示语音消息
  15. MsgTypeVoice = "voice"
  16. //MsgTypeVideo 表示视频消息
  17. MsgTypeVideo = "video"
  18. //MsgTypeShortVideo 表示短视频消息[限接收]
  19. MsgTypeShortVideo = "shortvideo"
  20. //MsgTypeLocation 表示坐标消息[限接收]
  21. MsgTypeLocation = "location"
  22. //MsgTypeLink 表示链接消息[限接收]
  23. MsgTypeLink = "link"
  24. //MsgTypeMusic 表示音乐消息[限回复]
  25. MsgTypeMusic = "music"
  26. //MsgTypeNews 表示图文消息[限回复]
  27. MsgTypeNews = "news"
  28. //MsgTypeTransfer 表示消息消息转发到客服
  29. MsgTypeTransfer = "transfer_customer_service"
  30. //MsgTypeEvent 表示事件推送消息
  31. MsgTypeEvent = "event"
  32. )
  33. const (
  34. //EventSubscribe 订阅
  35. EventSubscribe EventType = "subscribe"
  36. //EventUnsubscribe 取消订阅
  37. EventUnsubscribe = "unsubscribe"
  38. //EventScan 用户已经关注公众号,则微信会将带场景值扫描事件推送给开发者
  39. EventScan = "SCAN"
  40. //EventLocation 上报地理位置事件
  41. EventLocation = "LOCATION"
  42. //EventClick 点击菜单拉取消息时的事件推送
  43. EventClick = "CLICK"
  44. //EventView 点击菜单跳转链接时的事件推送
  45. EventView = "VIEW"
  46. //EventScancodePush 扫码推事件的事件推送
  47. EventScancodePush = "scancode_push"
  48. //EventScancodeWaitmsg 扫码推事件且弹出“消息接收中”提示框的事件推送
  49. EventScancodeWaitmsg = "scancode_waitmsg"
  50. //EventPicSysphoto 弹出系统拍照发图的事件推送
  51. EventPicSysphoto = "pic_sysphoto"
  52. //EventPicPhotoOrAlbum 弹出拍照或者相册发图的事件推送
  53. EventPicPhotoOrAlbum = "pic_photo_or_album"
  54. //EventPicWeixin 弹出微信相册发图器的事件推送
  55. EventPicWeixin = "pic_weixin"
  56. //EventLocationSelect 弹出地理位置选择器的事件推送
  57. EventLocationSelect = "location_select"
  58. //EventTemplateSendJobFinish 发送模板消息推送通知
  59. EventTemplateSendJobFinish = "TEMPLATESENDJOBFINISH"
  60. )
  61. const (
  62. // InfoTypeVerifyTicket 返回ticket
  63. InfoTypeVerifyTicket InfoType = "component_verify_ticket"
  64. // InfoTypeAuthorized 授权
  65. InfoTypeAuthorized = "authorized"
  66. // InfoTypeUnauthorized 取消授权
  67. InfoTypeUnauthorized = "unauthorized"
  68. // InfoTypeUpdateAuthorized 更新授权
  69. InfoTypeUpdateAuthorized = "updateauthorized"
  70. )
  71. //MixMessage 存放所有微信发送过来的消息和事件
  72. type MixMessage struct {
  73. CommonToken
  74. //基本消息
  75. MsgID int64 `xml:"MsgId"`
  76. Content string `xml:"Content"`
  77. Recognition string `xml:"Recognition"`
  78. PicURL string `xml:"PicUrl"`
  79. MediaID string `xml:"MediaId"`
  80. Format string `xml:"Format"`
  81. ThumbMediaID string `xml:"ThumbMediaId"`
  82. LocationX float64 `xml:"Location_X"`
  83. LocationY float64 `xml:"Location_Y"`
  84. Scale float64 `xml:"Scale"`
  85. Label string `xml:"Label"`
  86. Title string `xml:"Title"`
  87. Description string `xml:"Description"`
  88. URL string `xml:"Url"`
  89. //事件相关
  90. Event EventType `xml:"Event"`
  91. EventKey string `xml:"EventKey"`
  92. Ticket string `xml:"Ticket"`
  93. Latitude string `xml:"Latitude"`
  94. Longitude string `xml:"Longitude"`
  95. Precision string `xml:"Precision"`
  96. MenuID string `xml:"MenuId"`
  97. Status string `xml:"Status"`
  98. SessionFrom string `xml:"SessionFrom"`
  99. ScanCodeInfo struct {
  100. ScanType string `xml:"ScanType"`
  101. ScanResult string `xml:"ScanResult"`
  102. } `xml:"ScanCodeInfo"`
  103. SendPicsInfo struct {
  104. Count int32 `xml:"Count"`
  105. PicList []EventPic `xml:"PicList>item"`
  106. } `xml:"SendPicsInfo"`
  107. SendLocationInfo struct {
  108. LocationX float64 `xml:"Location_X"`
  109. LocationY float64 `xml:"Location_Y"`
  110. Scale float64 `xml:"Scale"`
  111. Label string `xml:"Label"`
  112. Poiname string `xml:"Poiname"`
  113. }
  114. // 第三方平台相关
  115. InfoType InfoType `xml:"InfoType"`
  116. AppID string `xml:"AppId"`
  117. ComponentVerifyTicket string `xml:"ComponentVerifyTicket"`
  118. AuthorizerAppid string `xml:"AuthorizerAppid"`
  119. AuthorizationCode string `xml:"AuthorizationCode"`
  120. AuthorizationCodeExpiredTime int64 `xml:"AuthorizationCodeExpiredTime"`
  121. PreAuthCode string `xml:"PreAuthCode"`
  122. }
  123. //EventPic 发图事件推送
  124. type EventPic struct {
  125. PicMd5Sum string `xml:"PicMd5Sum"`
  126. }
  127. //EncryptedXMLMsg 安全模式下的消息体
  128. type EncryptedXMLMsg struct {
  129. XMLName struct{} `xml:"xml" json:"-"`
  130. ToUserName string `xml:"ToUserName" json:"ToUserName"`
  131. EncryptedMsg string `xml:"Encrypt" json:"Encrypt"`
  132. }
  133. //ResponseEncryptedXMLMsg 需要返回的消息体
  134. type ResponseEncryptedXMLMsg struct {
  135. XMLName struct{} `xml:"xml" json:"-"`
  136. EncryptedMsg string `xml:"Encrypt" json:"Encrypt"`
  137. MsgSignature string `xml:"MsgSignature" json:"MsgSignature"`
  138. Timestamp int64 `xml:"TimeStamp" json:"TimeStamp"`
  139. Nonce string `xml:"Nonce" json:"Nonce"`
  140. }
  141. // CommonToken 消息中通用的结构
  142. type CommonToken struct {
  143. XMLName xml.Name `xml:"xml"`
  144. ToUserName string `xml:"ToUserName"`
  145. FromUserName string `xml:"FromUserName"`
  146. CreateTime int64 `xml:"CreateTime"`
  147. MsgType MsgType `xml:"MsgType"`
  148. }
  149. //SetToUserName set ToUserName
  150. func (msg *CommonToken) SetToUserName(toUserName string) {
  151. msg.ToUserName = toUserName
  152. }
  153. //SetFromUserName set FromUserName
  154. func (msg *CommonToken) SetFromUserName(fromUserName string) {
  155. msg.FromUserName = fromUserName
  156. }
  157. //SetCreateTime set createTime
  158. func (msg *CommonToken) SetCreateTime(createTime int64) {
  159. msg.CreateTime = createTime
  160. }
  161. //SetMsgType set MsgType
  162. func (msg *CommonToken) SetMsgType(msgType MsgType) {
  163. msg.MsgType = msgType
  164. }