@Test public void testMultiCreateConditionalMenu() throws WxErrorException { String json = "{\n" + " \"button\":[\n" + " { \n" + " \"type\":\"click\",\n" + " \"name\":\"今日歌曲\",\n" + " \"key\":\"V1001_TODAY_MUSIC\" \n" + " },\n" + " { \n" + " \"name\":\"菜单\",\n" + " \"sub_button\":[\n" + " { \n" + " \"type\":\"view\",\n" + " \"name\":\"搜索\",\n" + " \"url\":\"http: " },\n" + " {\n" + " \"type\":\"view\",\n" + " \"name\":\"视频\",\n" + " \"url\":\"http: " },\n" + " {\n" + " \"type\":\"click\",\n" + " \"name\":\"赞一下我们\",\n" + " \"key\":\"V1001_GOOD\"\n" + " }]\n" + " }],\n" + "\"matchrule\":{\n" + " \"tag_id\":\"2\",\n" + " \"sex\":\"1\",\n" + " \"country\":\"中国\",\n" + " \"province\":\"广东\",\n" + " \"city\":\"广州\",\n" + " \"client_platform_type\":\"2\",\n" + " \"language\":\"zh_CN\"\n" + " }\n" + "}"; this.menuId = this.wxService.getMenuService().menuCreate(json); System.out.println(this.menuId); }
@Override public String menuCreate(WxMenu menu) throws WxErrorException { String menuJson = menu.toJson(); String url = API_URL_PREFIX + "/create"; if (menu.getMatchRule() != null) { url = API_URL_PREFIX + "/addconditional"; } log.debug("开始创建菜单：{}", menuJson); String result = this.wxMpService.post(url, menuJson); log.debug("创建菜单：{},结果：{}", menuJson, result); if (menu.getMatchRule() != null) { return new JsonParser().parse(result).getAsJsonObject().get("menuid").getAsString(); } return null; }
WxMpMenuServiceImpl implements WxMpMenuService { @Override public String menuCreate(WxMenu menu) throws WxErrorException { String menuJson = menu.toJson(); String url = API_URL_PREFIX + "/create"; if (menu.getMatchRule() != null) { url = API_URL_PREFIX + "/addconditional"; } log.debug("开始创建菜单：{}", menuJson); String result = this.wxMpService.post(url, menuJson); log.debug("创建菜单：{},结果：{}", menuJson, result); if (menu.getMatchRule() != null) { return new JsonParser().parse(result).getAsJsonObject().get("menuid").getAsString(); } return null; } }
WxMpMenuServiceImpl implements WxMpMenuService { @Override public String menuCreate(WxMenu menu) throws WxErrorException { String menuJson = menu.toJson(); String url = API_URL_PREFIX + "/create"; if (menu.getMatchRule() != null) { url = API_URL_PREFIX + "/addconditional"; } log.debug("开始创建菜单：{}", menuJson); String result = this.wxMpService.post(url, menuJson); log.debug("创建菜单：{},结果：{}", menuJson, result); if (menu.getMatchRule() != null) { return new JsonParser().parse(result).getAsJsonObject().get("menuid").getAsString(); } return null; } WxMpMenuServiceImpl(WxMpService wxMpService); }
WxMpMenuServiceImpl implements WxMpMenuService { @Override public String menuCreate(WxMenu menu) throws WxErrorException { String menuJson = menu.toJson(); String url = API_URL_PREFIX + "/create"; if (menu.getMatchRule() != null) { url = API_URL_PREFIX + "/addconditional"; } log.debug("开始创建菜单：{}", menuJson); String result = this.wxMpService.post(url, menuJson); log.debug("创建菜单：{},结果：{}", menuJson, result); if (menu.getMatchRule() != null) { return new JsonParser().parse(result).getAsJsonObject().get("menuid").getAsString(); } return null; } WxMpMenuServiceImpl(WxMpService wxMpService); @Override String menuCreate(WxMenu menu); @Override String menuCreate(String json); @Override void menuDelete(); @Override void menuDelete(String menuId); @Override WxMpMenu menuGet(); @Override WxMenu menuTryMatch(String userid); @Override WxMpGetSelfMenuInfoResult getSelfMenuInfo(); }
WxMpMenuServiceImpl implements WxMpMenuService { @Override public String menuCreate(WxMenu menu) throws WxErrorException { String menuJson = menu.toJson(); String url = API_URL_PREFIX + "/create"; if (menu.getMatchRule() != null) { url = API_URL_PREFIX + "/addconditional"; } log.debug("开始创建菜单：{}", menuJson); String result = this.wxMpService.post(url, menuJson); log.debug("创建菜单：{},结果：{}", menuJson, result); if (menu.getMatchRule() != null) { return new JsonParser().parse(result).getAsJsonObject().get("menuid").getAsString(); } return null; } WxMpMenuServiceImpl(WxMpService wxMpService); @Override String menuCreate(WxMenu menu); @Override String menuCreate(String json); @Override void menuDelete(); @Override void menuDelete(String menuId); @Override WxMpMenu menuGet(); @Override WxMenu menuTryMatch(String userid); @Override WxMpGetSelfMenuInfoResult getSelfMenuInfo();  }