微信開發-自定義菜單

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分鐘延遲,或者取消關注以後再次關注等待刷新;
相關文章
相關標籤/搜索