{ "button": [ { "type": "click", "name": "今日歌曲", "key": "V1001_TODAY_MUSIC" }, { "name": "菜單", "sub_button": [ { "type": "view", "name": "搜索", "url": "http://www.soso.com/" }, { "type": "view", "name": "視頻", "url": "http://v.qq.com/" }, { "type": "click", "name": "贊一下我們", "key": "V1001_GOOD" } ] } ] }
若不是第一次創建菜單,則需在創建菜單前,刪除已存在的菜單,刪除菜單請求地址是:https://api.weixin.qq.com/cgi-bin/menu/delete?access_token=值,將獲取到的ACCESS_TOKEN值代入鏈接地址中,即可刪除已存在的菜單。 示例: 菜單創建片段: string postString = "{\"button\":[{\"name\":\"訊息速遞\",\"sub_button\":[{\"type\":\"click\",\"name\":\"改版公告\",\"key\":\"RevisionNotice\"},{\"type\":\"view\",\"name\":\"春天讀好書\",\"url\":\"http://ah.10086.cn/new/s/ydty/ctdhsxscd \"}]},{\"name\":\"我要分享\",\"sub_button\":[{\"type\":\"click\",\"name\":\"讀 · 好書\",\"key\":\"bookRanking\"},{\"type\":\"click\",\"name\":\"聽 · 酷音\",\"key\":\"musicRanking\"},{\"type\":\"click\",\"name\":\"玩 · 趣游\",\"key\":\"gameRanking\"}]},{\"name\":\"個人中心\",\"sub_button\":[{\"type\":\"click\",\"name\":\"身份驗證\",\"key\":\"BDClick\"},{\"type\":\"click\",\"name\":\"積分兌換\",\"key\":\"OnExchange\"},{\"type\":\"click\",\"name\":\"積分規則說明\",\"key\":\"IntegralRule\"}]}]}"; //微信圈圈菜單 byte[] postData = Encoding.UTF8.GetBytes(postString);//編碼,尤其是漢字,事先要看下抓取網頁的編碼方式 string url = "https://api.weixin.qq.com/cgi-bin/menu/create?access_token=LZTCC_eaEHVsEh9pEczSYqGzrphoCsSiTtkbMwDj5yqkQVlP3rObDxxIm6J7cG39mLljSw9H18efkwEK0dHrCTlbKBXOJf2BHFuNZ4MZRBM";//根據獲取的ACCESS_TOKEN值代入鏈接中創建菜單 WebClient webClient = new WebClient(); webClient.Headers.Add("Content-Type", "application/x-www-form-urlencoded");//采取POST方式必須加的header,如果改為GET方式的話就去掉這句話即可 byte[] responseData = webClient.UploadData(url, "POST", postData);//得到返回字符流 string srcString = Encoding.UTF8.GetString(responseData);//解碼 Response.Write(srcString);