| @@ -75,6 +75,7 @@ public class WxCpMessageGsonAdapter implements JsonSerializer<WxCpMessage> { | |||||
| } | } | ||||
| if (WxConsts.CUSTOM_MSG_NEWS.equals(message.getMsgType())) { | if (WxConsts.CUSTOM_MSG_NEWS.equals(message.getMsgType())) { | ||||
| JsonObject newsJsonObject = new JsonObject(); | |||||
| JsonArray articleJsonArray = new JsonArray(); | JsonArray articleJsonArray = new JsonArray(); | ||||
| for (WxCpMessage.WxArticle article : message.getArticles()) { | for (WxCpMessage.WxArticle article : message.getArticles()) { | ||||
| JsonObject articleJson = new JsonObject(); | JsonObject articleJson = new JsonObject(); | ||||
| @@ -84,7 +85,8 @@ public class WxCpMessageGsonAdapter implements JsonSerializer<WxCpMessage> { | |||||
| articleJson.addProperty("picurl", article.getPicUrl()); | articleJson.addProperty("picurl", article.getPicUrl()); | ||||
| articleJsonArray.add(articleJson); | articleJsonArray.add(articleJson); | ||||
| } | } | ||||
| messageJson.add("articles", articleJsonArray); | |||||
| newsJsonObject.add("articles", articleJsonArray); | |||||
| messageJson.add("news", newsJsonObject); | |||||
| } | } | ||||
| return messageJson; | return messageJson; | ||||
| @@ -83,8 +83,8 @@ public class WxCpMessageTest { | |||||
| article2.setTitle("Happy Day"); | article2.setTitle("Happy Day"); | ||||
| reply.getArticles().add(article2); | reply.getArticles().add(article2); | ||||
| Assert.assertEquals(reply.toJson(), "{\"touser\":\"OPENID\",\"msgtype\":\"news\",\"articles\":[{\"title\":\"Happy Day\",\"description\":\"Is Really A Happy Day\",\"url\":\"URL\",\"picurl\":\"PIC_URL\"},{\"title\":\"Happy Day\",\"description\":\"Is Really A Happy Day\",\"url\":\"URL\",\"picurl\":\"PIC_URL\"}]}"); | |||||
| Assert.assertEquals(reply.toJson(), "{\"touser\":\"OPENID\",\"msgtype\":\"news\",\"news\":{\"articles\":[{\"title\":\"Happy Day\",\"description\":\"Is Really A Happy Day\",\"url\":\"URL\",\"picurl\":\"PIC_URL\"},{\"title\":\"Happy Day\",\"description\":\"Is Really A Happy Day\",\"url\":\"URL\",\"picurl\":\"PIC_URL\"}]}}"); | |||||
| } | } | ||||
| public void testNewsBuild() { | public void testNewsBuild() { | ||||
| @@ -101,8 +101,8 @@ public class WxCpMessageTest { | |||||
| article2.setTitle("Happy Day"); | article2.setTitle("Happy Day"); | ||||
| WxCpMessage reply = WxCpMessage.NEWS().toUser("OPENID").addArticle(article1).addArticle(article2).build(); | WxCpMessage reply = WxCpMessage.NEWS().toUser("OPENID").addArticle(article1).addArticle(article2).build(); | ||||
| Assert.assertEquals(reply.toJson(), "{\"touser\":\"OPENID\",\"msgtype\":\"news\",\"articles\":[{\"title\":\"Happy Day\",\"description\":\"Is Really A Happy Day\",\"url\":\"URL\",\"picurl\":\"PIC_URL\"},{\"title\":\"Happy Day\",\"description\":\"Is Really A Happy Day\",\"url\":\"URL\",\"picurl\":\"PIC_URL\"}]}"); | |||||
| Assert.assertEquals(reply.toJson(), "{\"touser\":\"OPENID\",\"msgtype\":\"news\",\"news\":{\"articles\":[{\"title\":\"Happy Day\",\"description\":\"Is Really A Happy Day\",\"url\":\"URL\",\"picurl\":\"PIC_URL\"},{\"title\":\"Happy Day\",\"description\":\"Is Really A Happy Day\",\"url\":\"URL\",\"picurl\":\"PIC_URL\"}]}}"); | |||||
| } | } | ||||
| } | } | ||||
| @@ -64,6 +64,7 @@ public class WxMpCustomMessageGsonAdapter implements JsonSerializer<WxMpCustomMe | |||||
| } | } | ||||
| if (WxConsts.CUSTOM_MSG_NEWS.equals(message.getMsgType())) { | if (WxConsts.CUSTOM_MSG_NEWS.equals(message.getMsgType())) { | ||||
| JsonObject newsJsonObject = new JsonObject(); | |||||
| JsonArray articleJsonArray = new JsonArray(); | JsonArray articleJsonArray = new JsonArray(); | ||||
| for (WxMpCustomMessage.WxArticle article : message.getArticles()) { | for (WxMpCustomMessage.WxArticle article : message.getArticles()) { | ||||
| JsonObject articleJson = new JsonObject(); | JsonObject articleJson = new JsonObject(); | ||||
| @@ -73,7 +74,8 @@ public class WxMpCustomMessageGsonAdapter implements JsonSerializer<WxMpCustomMe | |||||
| articleJson.addProperty("picurl", article.getPicUrl()); | articleJson.addProperty("picurl", article.getPicUrl()); | ||||
| articleJsonArray.add(articleJson); | articleJsonArray.add(articleJson); | ||||
| } | } | ||||
| messageJson.add("articles", articleJsonArray); | |||||
| newsJsonObject.add("articles", articleJsonArray); | |||||
| messageJson.add("news", newsJsonObject); | |||||
| } | } | ||||
| return messageJson; | return messageJson; | ||||
| @@ -108,7 +108,7 @@ public class WxMpCustomMessageTest { | |||||
| reply.getArticles().add(article2); | reply.getArticles().add(article2); | ||||
| Assert.assertEquals(reply.toJson(), "{\"touser\":\"OPENID\",\"msgtype\":\"news\",\"articles\":[{\"title\":\"Happy Day\",\"description\":\"Is Really A Happy Day\",\"url\":\"URL\",\"picurl\":\"PIC_URL\"},{\"title\":\"Happy Day\",\"description\":\"Is Really A Happy Day\",\"url\":\"URL\",\"picurl\":\"PIC_URL\"}]}"); | |||||
| Assert.assertEquals(reply.toJson(), "{\"touser\":\"OPENID\",\"msgtype\":\"news\",\"news\":{\"articles\":[{\"title\":\"Happy Day\",\"description\":\"Is Really A Happy Day\",\"url\":\"URL\",\"picurl\":\"PIC_URL\"},{\"title\":\"Happy Day\",\"description\":\"Is Really A Happy Day\",\"url\":\"URL\",\"picurl\":\"PIC_URL\"}]}}"); | |||||
| } | } | ||||
| public void testNewsBuild() { | public void testNewsBuild() { | ||||
| @@ -125,8 +125,8 @@ public class WxMpCustomMessageTest { | |||||
| article2.setTitle("Happy Day"); | article2.setTitle("Happy Day"); | ||||
| WxMpCustomMessage reply = WxMpCustomMessage.NEWS().toUser("OPENID").addArticle(article1).addArticle(article2).build(); | WxMpCustomMessage reply = WxMpCustomMessage.NEWS().toUser("OPENID").addArticle(article1).addArticle(article2).build(); | ||||
| Assert.assertEquals(reply.toJson(), "{\"touser\":\"OPENID\",\"msgtype\":\"news\",\"articles\":[{\"title\":\"Happy Day\",\"description\":\"Is Really A Happy Day\",\"url\":\"URL\",\"picurl\":\"PIC_URL\"},{\"title\":\"Happy Day\",\"description\":\"Is Really A Happy Day\",\"url\":\"URL\",\"picurl\":\"PIC_URL\"}]}"); | |||||
| Assert.assertEquals(reply.toJson(), "{\"touser\":\"OPENID\",\"msgtype\":\"news\",\"news\":{\"articles\":[{\"title\":\"Happy Day\",\"description\":\"Is Really A Happy Day\",\"url\":\"URL\",\"picurl\":\"PIC_URL\"},{\"title\":\"Happy Day\",\"description\":\"Is Really A Happy Day\",\"url\":\"URL\",\"picurl\":\"PIC_URL\"}]}}"); | |||||
| } | } | ||||
| } | } | ||||