根据开发者appid(应用id)和appsecret(应用密钥)获取access_token值,请求地址是:https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=wx69e10a281a17e81f&secret=cff1fa9d984a3d122cadfbb901ecfa32,其中“wx69e10a281a17e81f”是微信圈圈的appid,“cff1fa9d984a3d122cadfbb901ecfa32”是微信圈圈的appsecret,获取access_token后,菜单请求地址是:https://api.weixin.qq.com/cgi-bin/menu/create?access_token=值,将获取到的access_token值代入链接地址中,即可创建一组菜单。
菜单创建格式:
{
"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);
以上就是c#微信公众平台菜单开发的详细介绍的详细内容。