ls 4 years ago
parent
commit
720ca52e88
2 changed files with 82 additions and 26 deletions
  1. 23 0
      wechat/client.go
  2. 59 26
      wechat/structure.go

+ 23 - 0
wechat/client.go

@@ -194,6 +194,29 @@ func (wc Client) GetMaterial(mtype string, offset, count int) (material Material
 	return
 }
 
+// GetMenu 查询自定义菜单
+func (wc Client) GetMenu() (menu Menu, err error) {
+	uri := BaseURL + "/cgi-bin/get_current_selfmenu_info?"
+
+	if wc.AccessToken, err = wc.getToken(); err != nil {
+		return
+	}
+
+	args := url.Values{}
+	data := make(map[string]interface{})
+
+	args.Add("access_token", wc.AccessToken)
+	uri += args.Encode()
+
+	var msg myth.HTTPMessage
+	msg, err = postJSON(uri, data)
+	if err == nil {
+		err = msg.JSON(&menu)
+	}
+
+	return
+}
+
 // GetSignPackage JS 签名
 //   uri      当前 URL
 //   nonceStr 随机字符串

+ 59 - 26
wechat/structure.go

@@ -4,6 +4,31 @@ import (
 	"encoding/xml"
 )
 
+// Client wechat
+type Client struct {
+	AppID          string `json:"appid"`
+	AppSecret      string `json:"appsecret"`
+	Token          string `json:"token"`
+	EncodingAESKey string `json:"encodingaeskey"`
+
+	//ReadLock *sync.Mutex
+
+	AccessToken   string
+	LastTokenTime int64
+
+	Ticket         string
+	LastTicketTime int64
+}
+
+// MiniClient wechat mini
+type MiniClient struct {
+	AppID     string `json:"appid"`
+	AppSecret string `json:"appsecret"`
+
+	AccessToken   string
+	LastTokenTime int64
+}
+
 // FormSignature signature
 type FormSignature struct {
 	TimeStamp string `form:"timestamp" json:"timestamp"`
@@ -124,10 +149,38 @@ type Message struct {
 	Longitude string `xml:"Longitude,omitempty" json:"Longitude,omitempty"` // 经度
 	Precision string `xml:"Precision,omitempty" json:"Precision,omitempty"` // 地理位置精度
 
-	MsgID  int64  `xml:"MsgId,omitempty" json:"MsgId,omitempty"`   // 消息id
+	MsgID  int64  `xml:"MsgID,omitempty" json:"MsgID,omitempty"`   // 消息id
 	Status string `xml:"Status,omitempty" json:"Status,omitempty"` // 消息发送状态
 }
 
+type menuSubButtonList struct {
+	Type string `json:"type"`
+	Name string `json:"name"`
+	Key  string `json:"key"`
+	URL  string `json:"url"`
+}
+
+type menuSubButton struct {
+	List []menuSubButtonList `json:"list"`
+}
+
+type menuButton struct {
+	Type      string        `json:"type"`
+	Name      string        `json:"name"`
+	Key       string        `json:"key"`
+	SubButton menuSubButton `json:"sub_button"`
+}
+
+type menuInfo struct {
+	Button []menuButton `json:"button"`
+}
+
+// Menu menu
+type Menu struct {
+	IsOpen int64    `json:"is_menu_open"`
+	Info   menuInfo `json:"selfmenu_info"`
+}
+
 // ArticleItem article item
 type ArticleItem struct {
 	Title       string `xml:"Title" json:"Title"`
@@ -196,31 +249,6 @@ type SignPackage struct {
 	URL       string `json:"url"`
 }
 
-// Client wechat
-type Client struct {
-	AppID          string `json:"appid"`
-	AppSecret      string `json:"appsecret"`
-	Token          string `json:"token"`
-	EncodingAESKey string `json:"encodingaeskey"`
-
-	//ReadLock *sync.Mutex
-
-	AccessToken   string
-	LastTokenTime int64
-
-	Ticket         string
-	LastTicketTime int64
-}
-
-// MiniClient wechat mini
-type MiniClient struct {
-	AppID     string `json:"appid"`
-	AppSecret string `json:"appsecret"`
-
-	AccessToken   string
-	LastTokenTime int64
-}
-
 // FormMaterial Material
 type FormMaterial struct {
 	Type   string `form:"type"`
@@ -249,6 +277,11 @@ type UserInfo struct {
 	QrSceneStr     string `json:"qr_scene_str"`
 }
 
+// FormNextOpenID next openid
+type FormNextOpenID struct {
+	Next string `form:"next_openid"`
+}
+
 // List openid list
 type List struct {
 	OpenID []string `json:"openid"`