Browse Source

公众号菜单栏

master
huangjiajun 1 year ago
parent
commit
6f4a517c76
2 changed files with 23 additions and 1 deletions
  1. +8
    -0
      app/md/md_wechat_menu.go
  2. +15
    -1
      app/svc/svc_wechat.go

+ 8
- 0
app/md/md_wechat_menu.go View File

@@ -2,6 +2,11 @@ package md

type WechatButton struct {
Name string `json:"name"`
Type string `json:"type"`
Url string `json:"url"`
Appid string `json:"appid,omitempty"`
Pagepath string `json:"pagepath"`
Key string `json:"key,omitempty"`
SubButton []WechatSubButton `json:"sub_button,omitempty"`
}
type WechatSubButton struct {
@@ -16,6 +21,9 @@ type OffcialWechatButton struct {
Type string `json:"type,omitempty"`
Name string `json:"name"`
Key string `json:"key,omitempty"`
Url string `json:"url"`
Appid string `json:"appid,omitempty"`
Pagepath string `json:"pagepath"`
SubButton SubButtonMap `json:"sub_button,omitempty"`
}
type SubButtonMap struct {


+ 15
- 1
app/svc/svc_wechat.go View File

@@ -9,6 +9,7 @@ import (
"applet/app/utils/cache"
"encoding/json"
"errors"
"fmt"
"github.com/gin-gonic/gin"
"github.com/tidwall/gjson"
)
@@ -28,11 +29,16 @@ func GetMenu(c *gin.Context) {
}
var offcialMenuList = make([]md.OffcialWechatButton, 0)
menu, err := utils.GetWechatSelfMenu(token)
fmt.Println(menu)
menuStr := gjson.Get(menu, "selfmenu_info.button").String()
json.Unmarshal([]byte(menuStr), &offcialMenuList)
for _, v := range offcialMenuList {
var tmp = md.WechatButton{
Name: v.Name,
Type: v.Type,
Url: v.Url,
Pagepath: v.Pagepath,
Appid: v.Appid,
SubButton: []md.WechatSubButton{},
}
for _, v1 := range v.SubButton.List {
@@ -57,8 +63,16 @@ func GetMenu(c *gin.Context) {
}
sysCfgDb.SysCfgUpdate("wechat_menu", utils.SerializeStr(menuList))
}
replyContentSet := []map[string]string{
{"msgType": "text", "name": "文本"},
{"msgType": "image", "name": "图片"},
{"msgType": "video", "name": "视频"},
{"msgType": "voice", "name": "语音"},
{"msgType": "article", "name": "文章"},
}
res := map[string]interface{}{
"button": menuList,
"button": menuList,
"replyContentSet": replyContentSet,
}
e.OutSuc(c, res, nil)
}


Loading…
Cancel
Save