From 50e0f493cb37a5eb547f5c044fa68544d517d53a Mon Sep 17 00:00:00 2001 From: huangjiajun <582604932@qq.com> Date: Tue, 15 Aug 2023 16:11:56 +0800 Subject: [PATCH] =?UTF-8?q?=E6=9B=B4=E6=96=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/hdl/hdl_wx.go | 23 ++++++++++++++++------- app/svc/svc_wechat_reply.go | 6 ++++-- 2 files changed, 20 insertions(+), 9 deletions(-) diff --git a/app/hdl/hdl_wx.go b/app/hdl/hdl_wx.go index baaf749..313e64f 100644 --- a/app/hdl/hdl_wx.go +++ b/app/hdl/hdl_wx.go @@ -11,7 +11,6 @@ import ( "encoding/xml" "errors" "fmt" - "github.com/tidwall/gjson" "log" "net/http" "strings" @@ -113,19 +112,29 @@ func WXMsgReceive(c *gin.Context) { WXMsgReply(c, eventMsg.ToUserName, eventMsg.FromUserName, err.Error()) } } - if eventMsg.Event == "click" { //公众号点击 + 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 } - if gjson.Get(mod.Data, "msgType").String() == "text" { - svc.WXMsgTextReply(c, msg.ToUserName, msg.FromUserName, gjson.Get(mod.Data, "text.content").String()) - } - if gjson.Get(mod.Data, "msgType").String() == "image" { - svc.WXMsgImageReply(c, msg.ToUserName, msg.FromUserName, gjson.Get(mod.Data, "image.mediaId").String()) + 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) + } } } } diff --git a/app/svc/svc_wechat_reply.go b/app/svc/svc_wechat_reply.go index a9c5c02..d82ea3e 100644 --- a/app/svc/svc_wechat_reply.go +++ b/app/svc/svc_wechat_reply.go @@ -1,7 +1,9 @@ package svc import ( + "applet/app/utils" "encoding/xml" + "fmt" "github.com/gin-gonic/gin" "log" "time" @@ -40,7 +42,7 @@ func WXMsgTextReply(c *gin.Context, fromUser, toUser, content string) { MsgType: "text", Content: content, } - + fmt.Println(utils.SerializeStr(repTextMsg)) msg, err := xml.Marshal(&repTextMsg) if err != nil { log.Printf("[消息回复] - 将对象进行XML编码出错: %v\n", err) @@ -56,7 +58,7 @@ func WXMsgImageReply(c *gin.Context, fromUser, toUser, content string) { MsgType: "image", Image: struct{ MediaId string }{MediaId: content}, } - + fmt.Println(utils.SerializeStr(repTextMsg)) msg, err := xml.Marshal(&repTextMsg) if err != nil { log.Printf("[消息回复] - 将对象进行XML编码出错: %v\n", err)