Pārlūkot izejas kodu

自定义菜单加入对小程序的支持 #170

master
Binary Wang pirms 7 gadiem
vecāks
revīzija
89870bbb92
2 mainītis faili ar 40 papildinājumiem un 39 dzēšanām
  1. +4
    -0
      weixin-java-common/src/main/java/me/chanjar/weixin/common/util/json/WxMenuGsonAdapter.java
  2. +36
    -39
      weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/impl/WxMpMenuServiceImplTest.java

+ 4
- 0
weixin-java-common/src/main/java/me/chanjar/weixin/common/util/json/WxMenuGsonAdapter.java Parādīt failu

@@ -46,6 +46,8 @@ public class WxMenuGsonAdapter implements JsonSerializer<WxMenu>, 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<WxMenu>, 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;
}



+ 36
- 39
weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/impl/WxMpMenuServiceImplTest.java Parādīt failu

@@ -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("菜单");


Notiek ielāde…
Atcelt
Saglabāt