response.go 866 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. package wechat
  2. import (
  3. "sync"
  4. "time"
  5. "encoding/xml"
  6. )
  7. var (
  8. memcache 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. return
  35. }