response.go 958 B

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