Nie możesz wybrać więcej, niż 25 tematów Tematy muszą się zaczynać od litery lub cyfry, mogą zawierać myślniki ('-') i mogą mieć do 35 znaków.

135 lines
2.3KB

  1. //analyze xml message
  2. package main
  3. import (
  4. "encoding/xml"
  5. )
  6. //EncryptedMsg encrypted message from Wechat
  7. type EncryptedMsg struct {
  8. ToUserName string
  9. Encrypt string
  10. }
  11. //all xml message has these headers
  12. type CommonHeader struct {
  13. ToUserName string
  14. FromUserName string
  15. CreateTime int64
  16. MsgType string
  17. }
  18. //text message
  19. type TextMsg struct {
  20. Content string
  21. MsgId int64
  22. }
  23. //picture
  24. type PicMsg struct {
  25. PicUrl string
  26. MediaId string
  27. MsgId int64
  28. }
  29. //voice
  30. type VoiceMsg struct {
  31. MediaId string
  32. Format string
  33. MsgId int64
  34. Recognition string
  35. }
  36. //video
  37. type VideoMsg struct {
  38. MediaId string
  39. ThumbMediaId string
  40. MsgId int64
  41. }
  42. //short video
  43. type ShortVideoMsg struct {
  44. MediaId string
  45. ThumbMediaId string
  46. MsgId int64
  47. }
  48. //Location Info
  49. type LocationMsg struct {
  50. Location_X float64
  51. Location_Y float64
  52. Scale int
  53. Label string
  54. MsgId int64
  55. }
  56. type LinkMsg struct {
  57. Title string
  58. Description string
  59. Url string
  60. MsgId int64
  61. }
  62. //ReadCommonHeader parse xml of common field of wechat post message
  63. func ReadCommonHeader(s string) CommonHeader {
  64. var r = CommonHeader{}
  65. xml.Unmarshal([]byte(s), &r)
  66. return r
  67. }
  68. //ReadTextMsg extract text message
  69. func ReadTextMsg(s string) TextMsg {
  70. var r = TextMsg{}
  71. xml.Unmarshal([]byte(s), &r)
  72. return r
  73. }
  74. //ReadPicMsg extract text message
  75. func ReadPicMsg(s string) PicMsg {
  76. var r = PicMsg{}
  77. xml.Unmarshal([]byte(s), &r)
  78. return r
  79. }
  80. //ReadVoiceMsg extract text message
  81. func ReadVoiceMsg(s string) VoiceMsg {
  82. var r = VoiceMsg{}
  83. xml.Unmarshal([]byte(s), &r)
  84. return r
  85. }
  86. //ReadVideoMsg extract text message
  87. func ReadVideoMsg(s string) VideoMsg {
  88. var r = VideoMsg{}
  89. xml.Unmarshal([]byte(s), &r)
  90. return r
  91. }
  92. //ReadShortVideoMsg extract text message
  93. func ReadShortVideoMsg(s string) ShortVideoMsg {
  94. var r = ShortVideoMsg{}
  95. xml.Unmarshal([]byte(s), &r)
  96. return r
  97. }
  98. //ReadLocationMsg extract text message
  99. func ReadLocationMsg(s string) LocationMsg {
  100. var r = LocationMsg{}
  101. xml.Unmarshal([]byte(s), &r)
  102. return r
  103. }
  104. //ReadLinkMsg extract text message
  105. func ReadLinkMsg(s string) LinkMsg {
  106. var r = LinkMsg{}
  107. xml.Unmarshal([]byte(s), &r)
  108. return r
  109. }
  110. //ReadEncryptedMsg get Encrypted Msg
  111. func ReadEncryptedMsg(s string) EncryptedMsg {
  112. var r = EncryptedMsg{}
  113. xml.Unmarshal([]byte(s), &r)
  114. return r
  115. }