package com.fh.util.weixin; import net.sf.json.JSONObject; import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; import java.net.HttpURLConnection; import java.net.MalformedURLException; import java.net.URL; import java.util.ArrayList; import java.util.List; import com.fh.entity.weixin.Button; import com.fh.entity.weixin.CommonButton; import com.fh.entity.weixin.ComplexButton; import com.fh.entity.weixin.Menu; import com.fh.entity.weixin.ViewButton; import com.fh.util.PageData; public class MenuUtil { /** * 创建自定义菜单(每天限制1000次) * */ public static int createMenu(Menu menu,String appid, String appsecret){ String jsonMenu=JSONObject.fromObject(menu).toString(); int status=0; //System.out.println("菜单:"+jsonMenu); Weixin wx = new Weixin(); String path="https://api.weixin.qq.com/cgi-bin/menu/create?access_token="+wx.getAccess_token(appid, appsecret); try { URL url=new URL(path); HttpURLConnection http = (HttpURLConnection)url.openConnection(); http.setDoOutput(true); http.setDoInput(true); http.setRequestMethod("POST"); http.setRequestProperty("Content-Type","application/x-www-form-urlencoded"); http.connect(); OutputStream os = http.getOutputStream(); os.write(jsonMenu.getBytes("UTF-8")); os.close(); InputStream is = http.getInputStream(); int size = is.available(); byte[] bt = new byte[size]; is.read(bt); String message=new String(bt,"UTF-8"); JSONObject jsonMsg = JSONObject.fromObject(message); status = Integer.parseInt(jsonMsg.getString("errcode")); } catch (MalformedURLException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } return status; } /**封装菜单数据 * @return */ public static Menu getMenu(List varList){ PageData M1 = new PageData(); PageData M2 = new PageData(); PageData M3 = new PageData(); List listm1 = new ArrayList(); List listm2 = new ArrayList(); List listm3 = new ArrayList(); String[] arraym1 = {"M11","M12","M13","M14","M15"}; String[] arraym2 = {"M21","M22","M23","M24","M25"}; String[] arraym3 = {"M31","M32","M33","M34","M35"}; for(int i=0;i