mirror of
				https://gitee.com/binary/weixin-java-tools.git
				synced 2025-11-01 03:25:35 +08:00 
			
		
		
		
	issue #32 发送客服消息图文消息时,拼接对象错误
This commit is contained in:
		| @ -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; | ||||||
|  | |||||||
| @ -84,7 +84,7 @@ public class WxCpMessageTest { | |||||||
|     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() { | ||||||
| @ -102,7 +102,7 @@ public class WxCpMessageTest { | |||||||
|  |  | ||||||
|     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() { | ||||||
| @ -126,7 +126,7 @@ public class WxMpCustomMessageTest { | |||||||
|  |  | ||||||
|     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\"}]}}"); | ||||||
|   } |   } | ||||||
|    |    | ||||||
| } | } | ||||||
|  | |||||||
		Reference in New Issue
	
	Block a user
	 Daniel Qian
					Daniel Qian