From 649443d5bdfce77a6a4c2e5a92d84a9a0fc6d077 Mon Sep 17 00:00:00 2001 From: huangjiajun <582604932@qq.com> Date: Tue, 15 Aug 2023 16:00:40 +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/db/model/sys_module.go | 2 -- app/md/md_wechat_menu.go | 14 +++++++------- app/svc/svc_wechat.go | 13 +++++++++++-- app/utils/wx.go | 1 + 4 files changed, 19 insertions(+), 11 deletions(-) diff --git a/app/db/model/sys_module.go b/app/db/model/sys_module.go index 82b4e88..d0043b4 100644 --- a/app/db/model/sys_module.go +++ b/app/db/model/sys_module.go @@ -15,7 +15,6 @@ type SysModule struct { Subtitle string `json:"subtitle" xorm:"not null default '' comment('副标题') VARCHAR(255)"` Url string `json:"url" xorm:"not null default '' comment('跳转链接') VARCHAR(512)"` Margin string `json:"margin" xorm:"not null default '0,0,0,0' comment('边距,上右下左') VARCHAR(64)"` - AspectRatio string `json:"aspect_ratio" xorm:"not null default 0.00 comment('宽高比,宽/高保留两位小数') DECIMAL(4,2)"` Icon string `json:"icon" xorm:"not null default '' comment('图标') VARCHAR(512)"` Img string `json:"img" xorm:"not null default '' comment('图片') VARCHAR(512)"` FontColor string `json:"font_color" xorm:"not null default '' comment('文字颜色') VARCHAR(128)"` @@ -30,5 +29,4 @@ type SysModule struct { IsGlobal int `json:"is_global" xorm:"not null default 0 comment('是否全局显示') TINYINT(1)"` Platform int `json:"platform" xorm:"not null default 1 comment('平台;1:全平台;2:App应用(ios和android);3:H5(wap);4:微信小程序;5:抖音小程序;6:百度小程序') TINYINT(1)"` CreateAt time.Time `json:"create_at" xorm:"not null default CURRENT_TIMESTAMP comment('创建时间') TIMESTAMP"` - UpdateAt time.Time `json:"update_at" xorm:"not null default CURRENT_TIMESTAMP comment('更新时间') TIMESTAMP"` } diff --git a/app/md/md_wechat_menu.go b/app/md/md_wechat_menu.go index e89ccc5..7bf7023 100644 --- a/app/md/md_wechat_menu.go +++ b/app/md/md_wechat_menu.go @@ -54,18 +54,18 @@ type WechatParam struct { } type WechatButtonParam struct { Name string `json:"name"` - Type string `json:"type"` - Url string `json:"url"` + Type string `json:"type,omitempty"` + Url string `json:"url,omitempty"` Appid string `json:"appid,omitempty"` - Pagepath string `json:"pagepath"` + Pagepath string `json:"pagepath,omitempty"` Key string `json:"key,omitempty"` SubButton []WechatSubButtonParam `json:"sub_button,omitempty"` } type WechatSubButtonParam struct { - Type string `json:"type"` + Type string `json:"type,omitempty"` Name string `json:"name"` - Url string `json:"url"` + Url string `json:"url,omitempty"` Appid string `json:"appid,omitempty"` - Pagepath string `json:"pagepath"` - Key string `json:"key"` + Pagepath string `json:"pagepath,omitempty"` + Key string `json:"key,omitempty"` } diff --git a/app/svc/svc_wechat.go b/app/svc/svc_wechat.go index d267bd1..290650b 100644 --- a/app/svc/svc_wechat.go +++ b/app/svc/svc_wechat.go @@ -14,6 +14,7 @@ import ( "github.com/gin-gonic/gin" "github.com/jinzhu/copier" "github.com/tidwall/gjson" + "strings" "time" ) @@ -66,7 +67,12 @@ func GetMenu(c *gin.Context) { } sysCfgDb.SysCfgUpdate("wechat_menu", utils.SerializeStr(menuList)) } - + for k, v := range menuList { + menuList[k].Url = strings.ReplaceAll(v.Url, "\\u0026", "&") + for k1, v1 := range v.SubButton { + menuList[k].SubButton[k1].Url = strings.ReplaceAll(v1.Url, "\\u0026", "&") + } + } replyContentSet := []map[string]string{ {"msgType": "text", "name": "文本"}, {"msgType": "image", "name": "图片"}, @@ -104,6 +110,7 @@ func SetMenu(c *gin.Context) { } } } + fmt.Println(utils.SerializeStr(param)) menu, err := utils.SetWechatSelfMenu(token, param) if err != nil { e.OutErr(c, 400, err.Error()) @@ -124,7 +131,9 @@ func commSetModule(modData string) string { Data: modData, CreateAt: time.Now(), } - db.Db.Insert(mod) + insert, err := db.Db.Insert(mod) + fmt.Println(insert) + fmt.Println(err) return "official_account_custom_reply" + "_" + utils.IntToStr(mod.ModId) } diff --git a/app/utils/wx.go b/app/utils/wx.go index ec69548..762517e 100644 --- a/app/utils/wx.go +++ b/app/utils/wx.go @@ -51,6 +51,7 @@ func GetWechatSelfMenu(token string) (string, error) { func SetWechatSelfMenu(token string, args md.WechatParam) (string, error) { str := SerializeStr(args) str = strings.ReplaceAll(str, "\\u0026", "&") + str = strings.ReplaceAll(str, "\\&", "&") fmt.Println(str) get, err := CurlPost("https://api.weixin.qq.com/cgi-bin/menu/create?access_token="+token, str, nil) return string(get), err