1、在设置自定义菜单之前,我们需要获取一个access_token.这个可以通过微信公众号appid和secret向公众号服务器获取api.weixin.qq.com/cgi-bin/token?appid=公众号ID&secret=公众号secret&grant_type=client_credential

3、创建自定义菜单是通过POST协议发送一个json格式的结构体。WxAccessToken accessToken = WxAppManager.getCacheAccessToken(redis.client, app); // 获取存取的access_tokenString path = "https://api.weixin.qq.com/cgi-bin/menu/create?access_token=" + accessToken.access_token;URL url = new URL(path);HttpURLConnection httpURLConnection = (HttpURLConnection) url.openConnection();httpURLConnection.setDoOutput(true);httpURLConnection.setDoInput(true);httpURLConnection.setRequestMethod("POST");httpURLConnection.setRequestProperty("Content-Type","application/x-www-form-urlencoded");httpURLConnection.connect();OutputStream outputStream = httpURLConnection.getOutputStream();outputStream.write(jsonMenu.getBytes("UTF-8"));outputStream.close();InputStream inputStream = httpURLConnection.getInputStream();JsonNode jsonIn = JsonUtil.readTree(inputStream);String errcode = jsonIn.path("errcode").asText();String errmsg = jsonIn.path("errmsg").asText();

5、查询现有的菜单。这里使用GET请求api.weixin.qq.com/cgi-bin/menu/get?access_token=access_token
