diff --git a/modules/auth/wechat/auto_reply.go b/modules/auth/wechat/auto_reply.go index c81efa558..d077aee95 100644 --- a/modules/auth/wechat/auto_reply.go +++ b/modules/auth/wechat/auto_reply.go @@ -40,6 +40,7 @@ type ReplyContent struct { MusicUrl string HQMusicUrl string ThumbMediaId string + Articles []ArticlesContent } func GetAutomaticReply(msg string) *AutomaticResponseContent { @@ -51,13 +52,13 @@ func GetAutomaticReply(msg string) *AutomaticResponseContent { return nil } for i := 0; i < len(r); i++ { - if r[i].IsFullMatch > 0 { + if r[i].IsFullMatch == 0 { for _, v := range r[i].KeyWords { if strings.Contains(msg, v) { return r[i] } } - } else if r[i].IsFullMatch == 0 { + } else if r[i].IsFullMatch > 0 { for _, v := range r[i].KeyWords { if msg == v { return r[i] diff --git a/modules/auth/wechat/event_handle.go b/modules/auth/wechat/event_handle.go index 3dd8508cb..7e46fac04 100644 --- a/modules/auth/wechat/event_handle.go +++ b/modules/auth/wechat/event_handle.go @@ -81,13 +81,18 @@ type MusicMsgReply struct { MsgType string Music MusicContent } -type ArticlesMsgReply struct { +type NewsMsgReply struct { XMLName xml.Name `xml:"xml"` ToUserName string FromUserName string CreateTime int64 MsgType string - Articles []ArticlesContent + ArticleCount int + Articles ArticleItem +} + +type ArticleItem struct { + Item []ArticlesContent } type ImageContent struct { @@ -109,6 +114,7 @@ type MusicContent struct { ThumbMediaId string } type ArticlesContent struct { + XMLName xml.Name `xml:"item"` Title string Description string PicUrl string diff --git a/routers/authentication/wechat_event.go b/routers/authentication/wechat_event.go index b8270faee..8ae1d8991 100644 --- a/routers/authentication/wechat_event.go +++ b/routers/authentication/wechat_event.go @@ -128,6 +128,17 @@ func buildReplyContent(msg wechat.WechatMsg, r *wechat.AutomaticResponseContent) ThumbMediaId: r.Reply.ThumbMediaId, }, } + case wechat.ReplyTypeNews: + return &wechat.NewsMsgReply{ + ToUserName: msg.FromUserName, + FromUserName: msg.ToUserName, + CreateTime: time.Now().Unix(), + MsgType: r.ReplyType, + ArticleCount: len(r.Reply.Articles), + Articles: wechat.ArticleItem{ + Item: r.Reply.Articles}, + } + } return reply }