diff --git a/weixin-java-common/src/main/java/me/chanjar/weixin/common/util/json/WxMenuGsonAdapter.java b/weixin-java-common/src/main/java/me/chanjar/weixin/common/util/json/WxMenuGsonAdapter.java index 578aa41c..526b5f29 100644 --- a/weixin-java-common/src/main/java/me/chanjar/weixin/common/util/json/WxMenuGsonAdapter.java +++ b/weixin-java-common/src/main/java/me/chanjar/weixin/common/util/json/WxMenuGsonAdapter.java @@ -46,6 +46,8 @@ public class WxMenuGsonAdapter implements JsonSerializer, JsonDeserializ buttonJson.addProperty("key", button.getKey()); buttonJson.addProperty("url", button.getUrl()); buttonJson.addProperty("media_id", button.getMediaId()); + buttonJson.addProperty("appid", button.getAppId()); + buttonJson.addProperty("pagepath", button.getPagePath()); if (button.getSubButtons() != null && button.getSubButtons().size() > 0) { JsonArray buttonArray = new JsonArray(); for (WxMenuButton sub_button : button.getSubButtons()) { @@ -114,6 +116,8 @@ public class WxMenuGsonAdapter implements JsonSerializer, JsonDeserializ button.setUrl(GsonHelper.getString(json, "url")); button.setType(GsonHelper.getString(json, "type")); button.setMediaId(GsonHelper.getString(json, "media_id")); + button.setAppId(GsonHelper.getString(json, "appid")); + button.setPagePath(GsonHelper.getString(json, "pagepath")); return button; } diff --git a/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/impl/WxMpMenuServiceImplTest.java b/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/impl/WxMpMenuServiceImplTest.java index 51b80e36..dac37f26 100644 --- a/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/impl/WxMpMenuServiceImplTest.java +++ b/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/impl/WxMpMenuServiceImplTest.java @@ -94,42 +94,37 @@ public class WxMpMenuServiceImplTest { @Test public void testCreateMenu_by_json() throws WxErrorException { - String a = "{\n" - + " \"menu\": {\n" - + " \"button\": [\n" - + " {\n" - + " \"type\": \"click\",\n" - + " \"name\": \"今日歌曲\",\n" - + " \"key\": \"V1001_TODAY_MUSIC\"\n" - + " },\n" - + " {\n" - + " \"type\": \"click\",\n" - + " \"name\": \"歌手简介\",\n" - + " \"key\": \"V1001_TODAY_SINGER\"\n" - + " },\n" - + " {\n" - + " \"name\": \"菜单\",\n" - + " \"sub_button\": [\n" - + " {\n" - + " \"type\": \"view\",\n" - + " \"name\": \"搜索\",\n" - + " \"url\": \"http://www.soso.com/\"\n" - + " },\n" - + " {\n" - + " \"type\": \"view\",\n" - + " \"name\": \"视频\",\n" - + " \"url\": \"http://v.qq.com/\"\n" - + " },\n" - + " {\n" - + " \"type\": \"click\",\n" - + " \"name\": \"赞一下我们\",\n" - + " \"key\": \"V1001_GOOD\"\n" - + " }\n" - + " ]\n" - + " }\n" - + " ]\n" - + " }\n" - + "}"; + String a = "{\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://www.soso.com/\"\n" + + " },\n" + + " {\n" + + " \"type\": \"miniprogram\",\n" + + " \"name\": \"wxa\",\n" + + " \"url\": \"http://mp.weixin.qq.com\",\n" + + " \"appid\": \"wx286b93c14bbf93aa\",\n" + + " \"pagepath\": \"pages/lunar/index.html\"\n" + + " },\n" + + " {\n" + + " \"type\": \"click\",\n" + + " \"name\": \"赞一下我们\",\n" + + " \"key\": \"V1001_GOOD\"\n" + + " }\n" + + " ]\n" + + " }\n" + + " ]\n" + + "}"; WxMenu menu = WxMenu.fromJson(a); System.out.println(menu.toJson()); @@ -157,9 +152,11 @@ public class WxMpMenuServiceImplTest { button1.setKey("V1001_TODAY_MUSIC"); WxMenuButton button2 = new WxMenuButton(); - button2.setType(WxConsts.BUTTON_CLICK); - button2.setName("歌手简介"); - button2.setKey("V1001_TODAY_SINGER"); + button2.setType(WxConsts.BUTTON_MINIPROGRAM); + button2.setName("小程序"); + button2.setAppId("wx286b93c14bbf93aa"); + button2.setPagePath("pages/lunar/index.html"); + button2.setUrl("http://mp.weixin.qq.com"); WxMenuButton button3 = new WxMenuButton(); button3.setName("菜单");