12345678910111213141516171819202122232425262728293031323334353637383940414243444546 |
- package wechat
- import (
- "fmt"
- "sync"
- "time"
- "encoding/xml"
- )
- var (
- cache sync.Map
- )
- // ToXML reply message to xml
- func (m ReplyMessage) ToXML() (data []byte, err error) {
- return xml.Marshal(m)
- }
- // ReplyText 回复文本信息
- func ReplyText(msg Message, text string) (reply ReplyMessage) {
- reply.ToUserName = msg.FromUserName
- reply.FromUserName = msg.ToUserName
- reply.CreateTime = time.Now().Unix()
- reply.MsgType = MsgText
- reply.Content = text
- return
- }
- // ReplyNews 回复图文信息
- func ReplyNews(msg Message, items []ArticleItem) (reply ReplyMessage) {
- reply.ToUserName = msg.FromUserName
- reply.FromUserName = msg.ToUserName
- reply.CreateTime = time.Now().Unix()
- reply.MsgType = MsgNews
- reply.ArticleCount = len(items)
- articles := &articleItems{}
- articles.Items = items
- reply.Articles = articles
- bs, _ := xml.Marshal(reply)
- fmt.Println(string(bs))
- return
- }
|