微信公众号开发创建菜单栏(二)
2015-11-12 15:43
525 查看
创建菜单栏
需要用到http的get和post:http://www.cnblogs.com/lswbk/p/4940449.html
官方自定义菜单创建接口API:http://mp.weixin.qq.com/wiki/2/88b2bf1265a707c031e51f26ca5e6512.html
接口调用请求说明
第一步获取access_token,获取access_token官方API:http://mp.weixin.qq.com/wiki/2/88b2bf1265a707c031e51f26ca5e6512.html
http请求方式: GET https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=APPID&secret=APPSECRET
APPID, APPSECRET在微信公众平台可以找到
第二步设置自定义菜单
http请求方式:POST(请使用https协议) https://api.weixin.qq.com/cgi-bin/menu/create?access_token=ACCESS_TOKEN
参数有access_token,和一个json格式的数据(可以参考官方api,这里只列出click方式,点击菜单事件)
需要用到http的get和post:http://www.cnblogs.com/lswbk/p/4940449.html
官方自定义菜单创建接口API:http://mp.weixin.qq.com/wiki/2/88b2bf1265a707c031e51f26ca5e6512.html
接口调用请求说明
第一步获取access_token,获取access_token官方API:http://mp.weixin.qq.com/wiki/2/88b2bf1265a707c031e51f26ca5e6512.html
http请求方式: GET https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=APPID&secret=APPSECRET
APPID, APPSECRET在微信公众平台可以找到
string access_token_json = HttpGet("https://api.weixin.qq.com/cgi-bin/token", "grant_type=client_credential&appid=" +APPID + "&secret=" + APPSECRET); string access_token = string.Empty; DataTable dt1 = JsonConvert.DeserializeObject<DataTable>("[" + access_token_json + "]"); for (int i = 0; i < dt1.Rows.Count; i++) { DataRow dr = dt1.Rows[i]; access_token = dr[0].ToString(); }
第二步设置自定义菜单
http请求方式:POST(请使用https协议) https://api.weixin.qq.com/cgi-bin/menu/create?access_token=ACCESS_TOKEN
参数有access_token,和一个json格式的数据(可以参考官方api,这里只列出click方式,点击菜单事件)
string content="{\"button\": [{\"name\": \"账号服务\", \"sub_button\": [{\"type\": \"click\", \"name\": \"查询用户名\", \"key\": \"Select_username\"}, {\"type\":\"click\", \"name\": \"找回密码\", \"key\": \"Retrieve_password\"}]}]}" string json = HttpPost("https://api.weixin.qq.com/cgi-bin/menu/create?access_token=" + access_token,content);
string errmsg= string.Empty; DataTable dt2 = JsonConvert.DeserializeObject<DataTable>("[" + json + "]");
for (int i = 0; i < dt2.Rows.Count; i++) { DataRow dr = dt2.Rows[i];
errmsg= dr[1].ToString(); } //if(errmsg=="ok")添加成功
相关文章推荐
- 腾讯优测自动化测试场景丨iBeacon走进微信“豪门”
- 微信绑定后台是验证token失败
- android微信登录,分享
- android微信登录,分享
- android微信登录,分享
- 微信支付iOS
- 高仿微信6.0Tab bar
- 微信企业号开发相关问题
- 微信JS分享实战代码
- C#开发微信门户及应用(1)--开始使用微信接口
- Testlink自动执行用例小程序
- overflow: hidden;在安卓微信页面失效问题
- 微信获取用户地理位置信息的原理与步骤
- 微信服务号开发-获取用户位置信息
- 微信获取用户地理位置信息的原理与步骤
- 分享 Java微信开发SDK
- Zabbix 实现微信短信告警
- 024.ArrayList中方法详解
- php 在web端来播放amr语音(如微信语音)
- 微信公众平台开发者模式(2)JAVA自动回复文本消息及多图文消息