Browse Source

更新

master
huangjiajun 1 year ago
parent
commit
50e0f493cb
2 changed files with 20 additions and 9 deletions
  1. +16
    -7
      app/hdl/hdl_wx.go
  2. +4
    -2
      app/svc/svc_wechat_reply.go

+ 16
- 7
app/hdl/hdl_wx.go View File

@@ -11,7 +11,6 @@ import (
"encoding/xml" "encoding/xml"
"errors" "errors"
"fmt" "fmt"
"github.com/tidwall/gjson"
"log" "log"
"net/http" "net/http"
"strings" "strings"
@@ -113,19 +112,29 @@ func WXMsgReceive(c *gin.Context) {
WXMsgReply(c, eventMsg.ToUserName, eventMsg.FromUserName, err.Error()) 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") { if strings.Contains(strings.ToLower(eventMsg.EventKey), "official_account_custom_reply") {
id := strings.ReplaceAll(strings.ToLower(eventMsg.EventKey), "official_account_custom_reply_", "") id := strings.ReplaceAll(strings.ToLower(eventMsg.EventKey), "official_account_custom_reply_", "")
var mod model.SysModule var mod model.SysModule
db.Db.Where("mod_id=?", id).Get(&mod) db.Db.Where("mod_id=?", id).Get(&mod)
fmt.Println(mod)
if mod.Data == "" { if mod.Data == "" {
fmt.Println(333)

return 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)
}
} }
} }
} }


+ 4
- 2
app/svc/svc_wechat_reply.go View File

@@ -1,7 +1,9 @@
package svc package svc


import ( import (
"applet/app/utils"
"encoding/xml" "encoding/xml"
"fmt"
"github.com/gin-gonic/gin" "github.com/gin-gonic/gin"
"log" "log"
"time" "time"
@@ -40,7 +42,7 @@ func WXMsgTextReply(c *gin.Context, fromUser, toUser, content string) {
MsgType: "text", MsgType: "text",
Content: content, Content: content,
} }
fmt.Println(utils.SerializeStr(repTextMsg))
msg, err := xml.Marshal(&repTextMsg) msg, err := xml.Marshal(&repTextMsg)
if err != nil { if err != nil {
log.Printf("[消息回复] - 将对象进行XML编码出错: %v\n", err) log.Printf("[消息回复] - 将对象进行XML编码出错: %v\n", err)
@@ -56,7 +58,7 @@ func WXMsgImageReply(c *gin.Context, fromUser, toUser, content string) {
MsgType: "image", MsgType: "image",
Image: struct{ MediaId string }{MediaId: content}, Image: struct{ MediaId string }{MediaId: content},
} }
fmt.Println(utils.SerializeStr(repTextMsg))
msg, err := xml.Marshal(&repTextMsg) msg, err := xml.Marshal(&repTextMsg)
if err != nil { if err != nil {
log.Printf("[消息回复] - 将对象进行XML编码出错: %v\n", err) log.Printf("[消息回复] - 将对象进行XML编码出错: %v\n", err)


Loading…
Cancel
Save