Browse Source

#2225

add reply type : news
tags/v1.22.6.2^2
chenyifan01 3 years ago
parent
commit
7961cb65b0
3 changed files with 22 additions and 4 deletions
  1. +3
    -2
      modules/auth/wechat/auto_reply.go
  2. +8
    -2
      modules/auth/wechat/event_handle.go
  3. +11
    -0
      routers/authentication/wechat_event.go

+ 3
- 2
modules/auth/wechat/auto_reply.go View File

@@ -40,6 +40,7 @@ type ReplyContent struct {
MusicUrl string MusicUrl string
HQMusicUrl string HQMusicUrl string
ThumbMediaId string ThumbMediaId string
Articles []ArticlesContent
} }


func GetAutomaticReply(msg string) *AutomaticResponseContent { func GetAutomaticReply(msg string) *AutomaticResponseContent {
@@ -51,13 +52,13 @@ func GetAutomaticReply(msg string) *AutomaticResponseContent {
return nil return nil
} }
for i := 0; i < len(r); i++ { for i := 0; i < len(r); i++ {
if r[i].IsFullMatch > 0 {
if r[i].IsFullMatch == 0 {
for _, v := range r[i].KeyWords { for _, v := range r[i].KeyWords {
if strings.Contains(msg, v) { if strings.Contains(msg, v) {
return r[i] return r[i]
} }
} }
} else if r[i].IsFullMatch == 0 {
} else if r[i].IsFullMatch > 0 {
for _, v := range r[i].KeyWords { for _, v := range r[i].KeyWords {
if msg == v { if msg == v {
return r[i] return r[i]


+ 8
- 2
modules/auth/wechat/event_handle.go View File

@@ -81,13 +81,18 @@ type MusicMsgReply struct {
MsgType string MsgType string
Music MusicContent Music MusicContent
} }
type ArticlesMsgReply struct {
type NewsMsgReply struct {
XMLName xml.Name `xml:"xml"` XMLName xml.Name `xml:"xml"`
ToUserName string ToUserName string
FromUserName string FromUserName string
CreateTime int64 CreateTime int64
MsgType string MsgType string
Articles []ArticlesContent
ArticleCount int
Articles ArticleItem
}

type ArticleItem struct {
Item []ArticlesContent
} }


type ImageContent struct { type ImageContent struct {
@@ -109,6 +114,7 @@ type MusicContent struct {
ThumbMediaId string ThumbMediaId string
} }
type ArticlesContent struct { type ArticlesContent struct {
XMLName xml.Name `xml:"item"`
Title string Title string
Description string Description string
PicUrl string PicUrl string


+ 11
- 0
routers/authentication/wechat_event.go View File

@@ -128,6 +128,17 @@ func buildReplyContent(msg wechat.WechatMsg, r *wechat.AutomaticResponseContent)
ThumbMediaId: r.Reply.ThumbMediaId, 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 return reply
} }

Loading…
Cancel
Save