message.go 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205
  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. //EventWxaMediaCheck 异步校验图片/音频是否含有违法违规内容推送事件
  61. EventWxaMediaCheck = "wxa_media_check"
  62. )
  63. const (
  64. // InfoTypeVerifyTicket 返回ticket
  65. InfoTypeVerifyTicket InfoType = "component_verify_ticket"
  66. // InfoTypeAuthorized 授权
  67. InfoTypeAuthorized = "authorized"
  68. // InfoTypeUnauthorized 取消授权
  69. InfoTypeUnauthorized = "unauthorized"
  70. // InfoTypeUpdateAuthorized 更新授权
  71. InfoTypeUpdateAuthorized = "updateauthorized"
  72. )
  73. //MixMessage 存放所有微信发送过来的消息和事件
  74. type MixMessage struct {
  75. CommonToken
  76. //基本消息
  77. MsgID int64 `xml:"MsgId"`
  78. Content string `xml:"Content"`
  79. Recognition string `xml:"Recognition"`
  80. PicURL string `xml:"PicUrl"`
  81. MediaID string `xml:"MediaId"`
  82. Format string `xml:"Format"`
  83. ThumbMediaID string `xml:"ThumbMediaId"`
  84. LocationX float64 `xml:"Location_X"`
  85. LocationY float64 `xml:"Location_Y"`
  86. Scale float64 `xml:"Scale"`
  87. Label string `xml:"Label"`
  88. Title string `xml:"Title"`
  89. Description string `xml:"Description"`
  90. URL string `xml:"Url"`
  91. //事件相关
  92. Event EventType `xml:"Event"`
  93. EventKey string `xml:"EventKey"`
  94. Ticket string `xml:"Ticket"`
  95. Latitude string `xml:"Latitude"`
  96. Longitude string `xml:"Longitude"`
  97. Precision string `xml:"Precision"`
  98. MenuID string `xml:"MenuId"`
  99. Status string `xml:"Status"`
  100. SessionFrom string `xml:"SessionFrom"`
  101. ScanCodeInfo struct {
  102. ScanType string `xml:"ScanType"`
  103. ScanResult string `xml:"ScanResult"`
  104. } `xml:"ScanCodeInfo"`
  105. SendPicsInfo struct {
  106. Count int32 `xml:"Count"`
  107. PicList []EventPic `xml:"PicList>item"`
  108. } `xml:"SendPicsInfo"`
  109. SendLocationInfo struct {
  110. LocationX float64 `xml:"Location_X"`
  111. LocationY float64 `xml:"Location_Y"`
  112. Scale float64 `xml:"Scale"`
  113. Label string `xml:"Label"`
  114. Poiname string `xml:"Poiname"`
  115. }
  116. // 第三方平台相关
  117. InfoType InfoType `xml:"InfoType"`
  118. AppID string `xml:"AppId"`
  119. ComponentVerifyTicket string `xml:"ComponentVerifyTicket"`
  120. AuthorizerAppid string `xml:"AuthorizerAppid"`
  121. AuthorizationCode string `xml:"AuthorizationCode"`
  122. AuthorizationCodeExpiredTime int64 `xml:"AuthorizationCodeExpiredTime"`
  123. PreAuthCode string `xml:"PreAuthCode"`
  124. // 卡券相关
  125. CardID string `xml:"CardId"`
  126. RefuseReason string `xml:"RefuseReason"`
  127. IsGiveByFriend int32 `xml:"IsGiveByFriend"`
  128. FriendUserName string `xml:"FriendUserName"`
  129. UserCardCode string `xml:"UserCardCode"`
  130. OldUserCardCode string `xml:"OldUserCardCode"`
  131. OuterStr string `xml:"OuterStr"`
  132. IsRestoreMemberCard int32 `xml:"IsRestoreMemberCard"`
  133. UnionID string `xml:"UnionId"`
  134. // 内容审核相关
  135. IsRisky bool `xml:"isrisky"`
  136. ExtraInfoJSON string `xml:"extra_info_json"`
  137. TraceID string `xml:"trace_id"`
  138. StatusCode int `xml:"status_code"`
  139. }
  140. //EventPic 发图事件推送
  141. type EventPic struct {
  142. PicMd5Sum string `xml:"PicMd5Sum"`
  143. }
  144. //EncryptedXMLMsg 安全模式下的消息体
  145. type EncryptedXMLMsg struct {
  146. XMLName struct{} `xml:"xml" json:"-"`
  147. ToUserName string `xml:"ToUserName" json:"ToUserName"`
  148. EncryptedMsg string `xml:"Encrypt" json:"Encrypt"`
  149. }
  150. //ResponseEncryptedXMLMsg 需要返回的消息体
  151. type ResponseEncryptedXMLMsg struct {
  152. XMLName struct{} `xml:"xml" json:"-"`
  153. EncryptedMsg string `xml:"Encrypt" json:"Encrypt"`
  154. MsgSignature string `xml:"MsgSignature" json:"MsgSignature"`
  155. Timestamp int64 `xml:"TimeStamp" json:"TimeStamp"`
  156. Nonce string `xml:"Nonce" json:"Nonce"`
  157. }
  158. // CommonToken 消息中通用的结构
  159. type CommonToken struct {
  160. XMLName xml.Name `xml:"xml"`
  161. ToUserName string `xml:"ToUserName"`
  162. FromUserName string `xml:"FromUserName"`
  163. CreateTime int64 `xml:"CreateTime"`
  164. MsgType MsgType `xml:"MsgType"`
  165. }
  166. //SetToUserName set ToUserName
  167. func (msg *CommonToken) SetToUserName(toUserName string) {
  168. msg.ToUserName = toUserName
  169. }
  170. //SetFromUserName set FromUserName
  171. func (msg *CommonToken) SetFromUserName(fromUserName string) {
  172. msg.FromUserName = fromUserName
  173. }
  174. //SetCreateTime set createTime
  175. func (msg *CommonToken) SetCreateTime(createTime int64) {
  176. msg.CreateTime = createTime
  177. }
  178. //SetMsgType set MsgType
  179. func (msg *CommonToken) SetMsgType(msgType MsgType) {
  180. msg.MsgType = msgType
  181. }