message.go 3.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  1. package mp
  2. import "encoding/xml"
  3. // CDATA 解析 xml cdata 字段
  4. type CDATA struct {
  5. Value string `xml:",cdata"`
  6. }
  7. // Message 公众号消息
  8. type Message struct {
  9. XMLName xml.Name `xml:"xml"`
  10. ToUserName CDATA `xml:"ToUserName"`
  11. FromUserName CDATA `xml:"FromUserName"`
  12. CreateTime int64 `xml:"CreateTime"`
  13. MsgType CDATA `xml:"MsgType"`
  14. }
  15. // TextMessage 文本消息
  16. type TextMessage struct {
  17. Message
  18. Content CDATA `xml:"Content"`
  19. MsgID int64 `xml:"MsgId"`
  20. // BizMsgMenuID 发送客服文本消息的时候用户的响应
  21. BizMsgMenuID int `xml:"bizmsgmenuid"`
  22. }
  23. // ImageMessage 图片消息
  24. type ImageMessage struct {
  25. Message
  26. PicURL CDATA `xml:"PicUrl"`
  27. MediaID CDATA `xml:"MediaId"`
  28. MsgID int64 `xml:"MsgId"`
  29. }
  30. // VoiceMessage 语音消息
  31. type VoiceMessage struct {
  32. Message
  33. MediaID CDATA `xml:"MediaId"`
  34. Format CDATA `xml:"Format"`
  35. Recognition CDATA `xml:"Recognition"`
  36. MsgID int64 `xml:"MsgId"`
  37. }
  38. // VideoMessage 视频消息
  39. type VideoMessage struct {
  40. Message
  41. MediaID CDATA `xml:"MediaId"`
  42. ThumbMediaID CDATA `xml:"ThumbMediaId"`
  43. MsgID int64 `xml:"MsgId"`
  44. }
  45. // MusicReplyMessage 回复音乐消息
  46. type MusicReplyMessage struct {
  47. Message
  48. Title CDATA `xml:"Music>Title"`
  49. Description CDATA `xml:"Video>Description"`
  50. MusicURL CDATA `xml:"Video>MusicUrl"`
  51. HQMusicURL CDATA `xml:"Video>HQMusicUrl"`
  52. ThumbMediaID CDATA `xml:"Video>ThumbMediaId"`
  53. }
  54. // ShortVideoMessage 小视频消息
  55. type ShortVideoMessage struct {
  56. Message
  57. MediaID CDATA `xml:"MediaId"`
  58. ThumbMediaID CDATA `xml:"ThumbMediaId"`
  59. MsgID int64 `xml:"MsgId"`
  60. }
  61. // LocationMessage 地理位置消息
  62. type LocationMessage struct {
  63. Message
  64. LocationX float64 `xml:"Location_X"`
  65. LocationY float64 `xml:"Location_Y"`
  66. Scale int `xml:"Scale"`
  67. Label CDATA `xml:"Label"`
  68. MsgID int64 `xml:"MsgId"`
  69. }
  70. // LinkMessage 链接消息
  71. type LinkMessage struct {
  72. Message
  73. Title CDATA `xml:"Title"`
  74. Description CDATA `xml:"Description"`
  75. URL CDATA `xml:"Url"`
  76. MsgID int64 `xml:"MsgId"`
  77. }
  78. // ReplyTextMessage 回复文本消息
  79. type ReplyTextMessage struct {
  80. Message
  81. Content CDATA `xml:"Content"`
  82. }
  83. // ReplyImageMessage 回复图片消息
  84. type ReplyImageMessage struct {
  85. Message
  86. MediaID CDATA `xml:"Image>MediaId"`
  87. }
  88. // ReplyVoiceMessage 回复语音消息
  89. type ReplyVoiceMessage struct {
  90. Message
  91. MediaID CDATA `xml:"Voice>MediaId"`
  92. }
  93. // ReplyVideoMessage 回复视频消息
  94. type ReplyVideoMessage struct {
  95. Message
  96. MediaID CDATA `xml:"Video>MediaId"`
  97. Title CDATA `xml:"Video>Title"`
  98. Description CDATA `xml:"Video>Description"`
  99. }
  100. // ReplyItem 回复图文消息的单独一个item
  101. type ReplyItem struct {
  102. Title CDATA `xml:"Title"`
  103. Description CDATA `xml:"Description"`
  104. PicURL CDATA `xml:"PicUrl"`
  105. URL CDATA `xml:"Url"`
  106. }
  107. // ReplyNewsMessage 回复图文消息
  108. type ReplyNewsMessage struct {
  109. Message
  110. ArticleCount int `xml:"ArticleCount"`
  111. Articles []ReplyItem `xml:"Articles>item"`
  112. }