response.go 893 B

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