概述
根据开发者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#微信公众平台菜单开发的详细介绍的详细内容,更多请关注靠谱客其它相关文章!
最后
以上就是舒服帆布鞋为你收集整理的C#微信公众平台菜单开发的详细介绍的全部内容,希望文章能够帮你解决C#微信公众平台菜单开发的详细介绍所遇到的程序开发问题。
如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。
发表评论 取消回复