From d1ae89b8ffc9d1c07efa4dd7000643dba1a896f3 Mon Sep 17 00:00:00 2001 From: DengBiao <2319963317@qq.com> Date: Sat, 2 Sep 2023 14:40:39 +0800 Subject: [PATCH] update --- app/hdl/hdl_wx.go | 92 ++++++++++++++++++++++++----------------------- 1 file changed, 47 insertions(+), 45 deletions(-) diff --git a/app/hdl/hdl_wx.go b/app/hdl/hdl_wx.go index 6b8aa81..3148b2b 100644 --- a/app/hdl/hdl_wx.go +++ b/app/hdl/hdl_wx.go @@ -5,12 +5,14 @@ import ( "applet/app/db/model" "applet/app/enum" "applet/app/md" + "applet/app/svc" "applet/app/utils" "encoding/json" "encoding/xml" "errors" "fmt" "log" + "strings" "time" "github.com/gin-gonic/gin" @@ -97,51 +99,51 @@ func WXMsgReceive(c *gin.Context) { } utils.FilePutContents("WXMsgReceive", utils.SerializeStr(msg)) log.Printf("[消息接收] - 收到消息, 消息类型为: %s", msg.MsgType) - //if msg.MsgType == "event" { - // //事件类型消息 - // eventMsg := msg - // log.Printf("[事件类型]-收到消息, 事件类型为: %s, 事件KEY值为: %s\n, 二维码的ticket值为: %s\n", eventMsg.Event, eventMsg.EventKey, eventMsg.Ticket) - // if eventMsg.Event == "subscribe" { - // //用户未关注时,进行关注后的事件推送 - // err := DealCallBack(eventMsg.FromUserName, eventMsg.EventKey) - // if err != nil { - // WXMsgReply(c, eventMsg.ToUserName, eventMsg.FromUserName, err.Error()) - // } - // } - // if eventMsg.Event == "SCAN" { - // //用户已关注时的事件推送 - // err := DealCallBack(eventMsg.FromUserName, eventMsg.EventKey) - // if err != nil { - // WXMsgReply(c, eventMsg.ToUserName, eventMsg.FromUserName, err.Error()) - // } - // } - // if eventMsg.Event == "CLICK" { //公众号点击 - // if strings.Contains(strings.ToLower(eventMsg.EventKey), "official_account_custom_reply") { - // id := strings.ReplaceAll(strings.ToLower(eventMsg.EventKey), "official_account_custom_reply_", "") - // var mod model.SysModule - // db.Db.Where("mod_id=?", id).Get(&mod) - // fmt.Println(mod) - // if mod.Data == "" { - // fmt.Println(333) - // - // return - // } - // var data []md.ReplyContent - // json.Unmarshal([]byte(mod.Data), &data) - // for _, v := range data { - // if v.MsgType == "text" { - // fmt.Println(1111) - // - // svc.WXMsgTextReply(c, msg.ToUserName, msg.FromUserName, v.Text.Content) - // } - // if v.MsgType == "image" { - // fmt.Println(22222) - // svc.WXMsgImageReply(c, msg.ToUserName, msg.FromUserName, v.Image.MediaId) - // } - // } - // } - // } - //} + if msg.MsgType == "event" { + //事件类型消息 + eventMsg := msg + log.Printf("[事件类型]-收到消息, 事件类型为: %s, 事件KEY值为: %s\n, 二维码的ticket值为: %s\n", eventMsg.Event, eventMsg.EventKey, eventMsg.Ticket) + if eventMsg.Event == "subscribe" { + //用户未关注时,进行关注后的事件推送 + err := DealCallBack(eventMsg.FromUserName, eventMsg.EventKey) + if err != nil { + WXMsgReply(c, eventMsg.ToUserName, eventMsg.FromUserName, err.Error()) + } + } + if eventMsg.Event == "SCAN" { + //用户已关注时的事件推送 + err := DealCallBack(eventMsg.FromUserName, eventMsg.EventKey) + if err != nil { + WXMsgReply(c, eventMsg.ToUserName, eventMsg.FromUserName, err.Error()) + } + } + if eventMsg.Event == "CLICK" { //公众号点击 + if strings.Contains(strings.ToLower(eventMsg.EventKey), "official_account_custom_reply") { + id := strings.ReplaceAll(strings.ToLower(eventMsg.EventKey), "official_account_custom_reply_", "") + var mod model.SysModule + db.Db.Where("mod_id=?", id).Get(&mod) + fmt.Println(mod) + if mod.Data == "" { + fmt.Println(333) + + return + } + var data []md.ReplyContent + json.Unmarshal([]byte(mod.Data), &data) + for _, v := range data { + if v.MsgType == "text" { + fmt.Println(1111) + + svc.WXMsgTextReply(c, msg.ToUserName, msg.FromUserName, v.Text.Content) + } + if v.MsgType == "image" { + fmt.Println(22222) + svc.WXMsgImageReply(c, msg.ToUserName, msg.FromUserName, v.Image.MediaId) + } + } + } + } + } if msg.MsgType == "text" { //文本类型消息 textMsg := msg