Get the ACCESS_TOKEN value based on the developer's AppID (application ID) and AppSecret (application key). The request address is: https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=wx69e10a281a17e81f&secret= cff1fa9d984a3d122cadfbb901ecfa32, where "wx69e10a281a17e81f" is the appid of WeChat Circle, and "cff1fa9d984a3d122cadfbb901ecfa32" is the AppSecret of WeChat Circle. After obtaining ACCESS_TOKEN, the menu request address is: https://api.weixin.qq.com/ cgi-bin/menu/ create?access_token=value, substitute the obtained ACCESS_TOKEN value into the link address to create a set of menus.
Menu creation format:
{ "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" } ] } ] }
If it is not the first time to create a menu, you need to delete the existing menu before creating the menu. The request address for deleting the menu is: https://api. weixin.qq.com/cgi-bin/menu/delete?access_token=value, substitute the obtained ACCESS_TOKEN value into the link address to delete the existing menu.
Example:
Menu creation fragment:
string postString = "{\"button\":[{\"name\":\"Message Express\", \"sub_button\":[{\"type\":\"click\",\"name\":\"Revision Notice\",\"key\":\"RevisionNotice\"},{\"type \":\"view\",\"name\":\"Reading good books in spring\",\"url\":\"http://ah.10086.cn/new/s/ydty/ctdhsxscd \ "}]},{\"name\":\"I want to share\",\"sub_button\":[{\"type\":\"click\",\"name\":\"Read· Good books\",\"key\":\"bookRanking\"},{\"type\":\"click\",\"name\":\"Listen to cool sounds\",\"key\ ":\"musicRanking\"},{\"type\":\"click\",\"name\":\"play·quyou\",\"key\":\"gameRanking\"}] },{\"name\":\"Personal Center\",\"sub_button\":[{\"type\":\"click\",\"name\":\"Authentication\",\ "key\":\"BDClick\"},{\"type\":\"click\",\"name\":\"Points Exchange\",\"key\":\"OnExchange\"} ,{\"type\":\"click\",\"name\":\"Points Rule Description\",\"key\":\"IntegralRule\"}]}]}"; //WeChat Circle Circle menu
byte[] postData = Encoding.UTF8.GetBytes(postString);//Encoding, especially Chinese characters, you need to check the encoding method of crawling the web page in advance
string url = " https://api.weixin.qq.com/cgi-bin/menu/create?access_token=LZTCC_eaEHVsEh9pEczSYqGzrphoCsSiTtkbMwDj5yqkQVlP3rObDxxIm6J7cG39mLljSw9H18efkwEK0dHrCTlbKBXOJf2BHFuNZ4MZRBM"; //Create a menu based on the obtained ACCESS_TOKEN value and substitute it into the link
WebClient webClient = new WebClient() ;
webClient.Headers.Add("Content-Type", "application/x-www-form-urlencoded");//Headers that must be added when using POST method, remove them if changing to GET method This sentence can be
byte[] responseData = webClient.UploadData(url, "POST", postData);//Get the return character stream
string srcString = Encoding.UTF8.GetString( responseData);//Decoding
Response.Write(srcString);
The above is the detailed content of Detailed introduction to C# WeChat public platform menu development. For more information, please follow other related articles on the PHP Chinese website!