微信开发-自定义菜单

public static void createMenu(String token,String menuStr)throws ClientProtocolException, IOException
	{
		token = "你获取的access_token";
		menuStr = "{"+
                "\"button\":["+
                "{\"name\":\"xxx\","+
                "\"type\":\"view\"," +
                "\"url\":\"http://www.baidu.com\"" +
                "},"+
                "{\"name\":\"xxx\","+
                "\"type\":\"view\"," +
                "\"url\":\"http://www.qq.com\"" +
                "},"+
                "{\"name\":\"xxxx\","+
                "\"type\":\"view\"," +
                "\"url\":\"http://www.163.com\"" +
                "}"+
            "]"+
        "}";
		
		String url = "https://api.weixin.qq.com/cgi-bin/menu/create?access_token="+ token;

		DefaultHttpClient httpClient = new DefaultHttpClient();
		HttpPost post = new HttpPost(url);

		post.setEntity(new StringEntity(menuStr, WxData.CharSet));
		HttpResponse response = httpClient.execute(post);
		String jsonStr = EntityUtils.toString(response.getEntity(),WxData.CharSet);
		
		System.out.println(jsonStr);
	}
菜单格式为json而后你Post给微信;它会帮你完成,通常修改以后会有3-10分钟延迟,或者取消关注以后再次关注等待刷新;
相关文章
相关标签/搜索