mirror of
https://github.com/xxjwxc/public.git
synced 2025-09-26 20:01:19 +08:00
1
This commit is contained in:
@@ -2,6 +2,7 @@ package weixin
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"net/http"
|
||||
"time"
|
||||
@@ -18,6 +19,7 @@ const (
|
||||
_getToken = "https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid="
|
||||
_getSubscribe = "https://api.weixin.qq.com/cgi-bin/message/subscribe/send?access_token="
|
||||
_getTempMsg = "https://api.weixin.qq.com/cgi-bin/message/template/send?access_token="
|
||||
_createMenu = "https://api.weixin.qq.com/cgi-bin/menu/create?access_token="
|
||||
_cacheToken = "wx_access_token"
|
||||
_cacheTicket = "weixin_card_ticket"
|
||||
)
|
||||
@@ -193,3 +195,22 @@ func (_wx *wxTools) SendWebTemplateMsg(msg TempWebMsg) bool {
|
||||
}
|
||||
return b
|
||||
}
|
||||
|
||||
// CreateMenu 创建自定义菜单
|
||||
func (_wx *wxTools) CreateMenu(menu WxMenu) error { // 创建自定义菜单
|
||||
accessToken, err := _wx.GetAccessToken()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
bo, _ := json.Marshal(menu)
|
||||
resb, _ := myhttp.OnPostJSON(_createMenu+accessToken, string(bo))
|
||||
|
||||
var res ResTempMsg
|
||||
json.Unmarshal(resb, &res)
|
||||
b := res.Errcode == 0
|
||||
if !b {
|
||||
return fmt.Errorf("SendWebTemplateMsg error: res:%v", res)
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
@@ -100,3 +100,22 @@ type WxUserinfo struct {
|
||||
Headimgurl string `json:"headimgurl"` // 头像地址
|
||||
// Privilege []string `json:"privilege"` // 户特权信息,json 数组,如微信沃卡用户为(chinaunicom)
|
||||
}
|
||||
|
||||
type WxMenu struct {
|
||||
Button []WxMenuButton `json:"button"`
|
||||
}
|
||||
|
||||
type WxMenuButton struct {
|
||||
Type string `json:"type,omitempty"`
|
||||
Name string `json:"name,omitempty"`
|
||||
Key string `json:"key,omitempty"`
|
||||
Url string `json:"url,omitempty"`
|
||||
SubButton []SubButton `json:"sub_button"`
|
||||
}
|
||||
|
||||
type SubButton struct {
|
||||
Type string `json:"type,omitempty"`
|
||||
Name string `json:"name,omitempty"`
|
||||
Key string `json:"key,omitempty"`
|
||||
Url string `json:"url,omitempty"`
|
||||
}
|
||||
|
@@ -38,6 +38,7 @@ type WxTools interface {
|
||||
GetWebOauth(code string) (*AccessToken, error) // 授权
|
||||
GetWebUserinfo(openid, accessToken string) (*WxUserinfo, error) // 获取用户信息
|
||||
SendWebTemplateMsg(msg TempWebMsg) bool // 发送公众号模板消息
|
||||
CreateMenu(menu WxMenu) error // 创建自定义菜单
|
||||
// ----------------------------------------------------
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user