response.go 888 B

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. package wechat
  2. import (
  3. "sync"
  4. "time"
  5. "encoding/xml"
  6. )
  7. var (
  8. cache sync.Map
  9. )
  10. // ToXML reply message to xml
  11. func (m ReplyMessage) ToXML() (data []byte, err error) {
  12. return xml.Marshal(m)
  13. }
  14. // ReplyText 回复文本信息
  15. func ReplyText(msg Message, text string) (reply ReplyMessage) {
  16. reply.ToUserName = msg.FromUserName
  17. reply.FromUserName = msg.ToUserName
  18. reply.CreateTime = time.Now().Unix()
  19. reply.MsgType = MsgText
  20. reply.Content = text
  21. return
  22. }
  23. // ReplyNews 回复图文信息
  24. func ReplyNews(msg Message, items []ArticleItem) (reply ReplyMessage) {
  25. reply.ToUserName = msg.FromUserName
  26. reply.FromUserName = msg.ToUserName
  27. reply.CreateTime = time.Now().Unix()
  28. reply.MsgType = MsgNews
  29. reply.ArticleCount = len(items)
  30. articles := &articleItems{}
  31. articles.Items = items
  32. reply.Articles = articles
  33. bs, _ := xml.Marshal(reply)
  34. //fmt.Println(string(bs))
  35. return
  36. }