微信公众平台自定义菜单实现-java版

分类:应用接口| 发布:佚名| 查看: | 发表时间:2014/7/2

菜单创建
接口说明
通过POST一个特定结构体,实现在微信客户端创建自定义菜单。
请求说明
http请求方式:POST

https://api.weixin.qq.com/cgi-bin/menu/create?access_token=ACCESS_TOKEN

结构体其实就是一个json格式的字符串,相信很多朋友就卡在这里了,怎么往这个接口地址 post 一个结构体呢,实现代码如下:

public static void main(String[] args) throws Exception {
URL url = new URL("https://api.weixin.qq.com/cgi-bin /menu/create?access_token=TOKEN");
String responeJsonStr = "{"+
"\"button\":["+
"{\"name\":\"酒店预订\","+
"\"sub_button\":["+
"{"+
"\"type\":\"click\","+
"\"name\":\"附近酒店\","+
"\"key\":\"jintoneinn488878-1\""+
"},"+
"{"+
"\"type\":\"click\","+
"\"name\":\"查找酒店\","+
"\"key\":\"jintoneinn488878-2\""+
"}"+
"]"+
"}"
"]"+
"}";
HttpURLConnection conn = (HttpURLConnection) url.openConnection();
conn.setRequestMethod("POST");
conn.setDoOutput(true);
conn.connect();
conn.getOutputStream().write(responeJsonStr.getBytes("utf-8"));
InputStream is = conn.getInputStream();
BufferedReader in = new BufferedReader(new InputStreamReader(is,"utf-8"));

StringBuffer buffer = new StringBuffer();
String line = "";
while ((line = in.readLine()) != null) {
buffer.append(line);
}
System.out.println(buffer.toString());
}
365据说看到好文章不转的人,服务器容易宕机
原创文章如转载,请注明:转载自郑州网建-前端开发 http://camnpr.com/
本文链接:http://camnpr.com/api/1296.html