You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

115 satır
1.8KB

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