来源:自学PHP网 时间:2015-04-14 12:58 作者: 阅读:次
[导读] 微信自定义菜单这个就比较简单,直接贴代码。微信说的注意:目前自定义菜单最多包括3个一级菜单,每个一级菜单最多包含5个二级菜单。一级菜单最多4个汉字,二级菜单最多7个汉字...
微信自定义菜单这个就比较简单,直接贴代码。 微信说的注意:
#region 菜单管理 public ActionResult CreateMenu() { string access_token = weixin.AccessToken(); string url = "https://api.weixin.qq.com/cgi-bin/menu/create?access_token=" + access_token; string data = ""; using (StreamReader sr = new StreamReader(Server.MapPath("/Config/menu.txt"))) { data = sr.ReadToEnd(); } var json = HttpHelper.Post(url, data); return Content(json); } public ActionResult DeleteMenu() { string access_token = weixin.AccessToken(); string url = "https://api.weixin.qq.com/cgi-bin/menu/delete?access_token=" + access_token; var json = HttpHelper.Get(url); return Content(json); } #endregion #region 菜单管理 public ActionResult CreateMenu() { string access_token = weixin.AccessToken(); string url = "https://api.weixin.qq.com/cgi-bin/menu/create?access_token=" + access_token; string data = ""; using (StreamReader sr = new StreamReader(Server.MapPath("/Config/menu.txt"))) { data = sr.ReadToEnd(); } var json = HttpHelper.Post(url, data); return Content(json); } public ActionResult DeleteMenu() { string access_token = weixin.AccessToken(); string url = "https://api.weixin.qq.com/cgi-bin/menu/delete?access_token=" + access_token; var json = HttpHelper.Get(url); return Content(json); } #endregion
menu.txt { "button":[ { "name":"一级标题1", "sub_button":[ { "type":"view", "name":"二级标题1", "url":"http://xx.xx.com/1.html" }, { "type":"view", "name":"二级标题2", "url":"" }, { "type":"view", "name":"二级标题3", "url":"" }, { "type":"view", "name":"二级标题4", "url":"" }, { "type":"view", "name":"二级标题5", "url":"" }] }, { "type":"view", "name":"一级标题2", "url":"http://xx.xx.com/2.html" }, { "name":"一级标题3", "sub_button":[ { "type":"view", "name":"二级标题1", "url":"" }, { "type":"view", "name":"二级标题2", "url":"http://xx.xx.com/3-1.html" }] }] } |
自学PHP网专注网站建设学习,PHP程序学习,平面设计学习,以及操作系统学习
京ICP备14009008号-1@版权所有www.zixuephp.com
网站声明:本站所有视频,教程都由网友上传,站长收集和分享给大家学习使用,如由牵扯版权问题请联系站长邮箱904561283@qq.com