1
0
mirror of synced 2025-12-22 00:48:00 +08:00

issue #10 提供客服消息Builder

This commit is contained in:
Daniel Qian
2014-08-28 15:06:39 +08:00
parent 23bf42dbba
commit bb6c789bc3
9 changed files with 73 additions and 17 deletions

View File

@@ -17,6 +17,11 @@ public class WxCustomMessageTest {
Assert.assertEquals(reply.toJson(), "{\"touser\":\"OPENID\",\"msgtype\":\"text\",\"text\":{\"content\":\"sfsfdsdf\"}}");
}
public void testTextBuild() {
WxCustomMessage reply = WxCustomMessage.TEXT().toUser("OPENID").content("sfsfdsdf").build();
Assert.assertEquals(reply.toJson(), "{\"touser\":\"OPENID\",\"msgtype\":\"text\",\"text\":{\"content\":\"sfsfdsdf\"}}");
}
public void testImageReply() {
WxCustomMessage reply = new WxCustomMessage();
reply.setTouser("OPENID");
@@ -25,6 +30,11 @@ public class WxCustomMessageTest {
Assert.assertEquals(reply.toJson(), "{\"touser\":\"OPENID\",\"msgtype\":\"image\",\"image\":{\"media_id\":\"MEDIA_ID\"}}");
}
public void testImageBuild() {
WxCustomMessage reply = WxCustomMessage.IMAGE().toUser("OPENID").mediaId("MEDIA_ID").build();
Assert.assertEquals(reply.toJson(), "{\"touser\":\"OPENID\",\"msgtype\":\"image\",\"image\":{\"media_id\":\"MEDIA_ID\"}}");
}
public void testVoiceReply() {
WxCustomMessage reply = new WxCustomMessage();
reply.setTouser("OPENID");
@@ -33,6 +43,11 @@ public class WxCustomMessageTest {
Assert.assertEquals(reply.toJson(), "{\"touser\":\"OPENID\",\"msgtype\":\"voice\",\"voice\":{\"media_id\":\"MEDIA_ID\"}}");
}
public void testVoiceBuild() {
WxCustomMessage reply = WxCustomMessage.VOICE().toUser("OPENID").mediaId("MEDIA_ID").build();
Assert.assertEquals(reply.toJson(), "{\"touser\":\"OPENID\",\"msgtype\":\"voice\",\"voice\":{\"media_id\":\"MEDIA_ID\"}}");
}
public void testVideoReply() {
WxCustomMessage reply = new WxCustomMessage();
reply.setTouser("OPENID");
@@ -44,6 +59,11 @@ public class WxCustomMessageTest {
Assert.assertEquals(reply.toJson(), "{\"touser\":\"OPENID\",\"msgtype\":\"video\",\"video\":{\"media_id\":\"MEDIA_ID\",\"thumb_media_id\":\"MEDIA_ID\",\"title\":\"TITLE\",\"description\":\"DESCRIPTION\"}}");
}
public void testVideoBuild() {
WxCustomMessage reply = WxCustomMessage.VIDEO().toUser("OPENID").title("TITLE").mediaId("MEDIA_ID").thumbMediaId("MEDIA_ID").description("DESCRIPTION").build();
Assert.assertEquals(reply.toJson(), "{\"touser\":\"OPENID\",\"msgtype\":\"video\",\"video\":{\"media_id\":\"MEDIA_ID\",\"thumb_media_id\":\"MEDIA_ID\",\"title\":\"TITLE\",\"description\":\"DESCRIPTION\"}}");
}
public void testMusicReply() {
WxCustomMessage reply = new WxCustomMessage();
reply.setTouser("OPENID");
@@ -56,6 +76,18 @@ public class WxCustomMessageTest {
Assert.assertEquals(reply.toJson(), "{\"touser\":\"OPENID\",\"msgtype\":\"music\",\"music\":{\"title\":\"TITLE\",\"description\":\"DESCRIPTION\",\"thumb_media_id\":\"MEDIA_ID\",\"musicurl\":\"MUSIC_URL\",\"hqmusicurl\":\"HQ_MUSIC_URL\"}}");
}
public void testMusicBuild() {
WxCustomMessage reply = WxCustomMessage.MUSIC()
.toUser("OPENID")
.title("TITLE")
.thumbMediaId("MEDIA_ID")
.description("DESCRIPTION")
.musicUrl("MUSIC_URL")
.hqmusicUrl("HQ_MUSIC_URL")
.build();
Assert.assertEquals(reply.toJson(), "{\"touser\":\"OPENID\",\"msgtype\":\"music\",\"music\":{\"title\":\"TITLE\",\"description\":\"DESCRIPTION\",\"thumb_media_id\":\"MEDIA_ID\",\"musicurl\":\"MUSIC_URL\",\"hqmusicurl\":\"HQ_MUSIC_URL\"}}");
}
public void testNewsReply() {
WxCustomMessage reply = new WxCustomMessage();
reply.setTouser("OPENID");
@@ -79,4 +111,22 @@ public class WxCustomMessageTest {
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\"}]}");
}
public void testNewsBuild() {
WxArticle article1 = new WxArticle();
article1.setUrl("URL");
article1.setPicurl("PIC_URL");
article1.setDescription("Is Really A Happy Day");
article1.setTitle("Happy Day");
WxArticle article2 = new WxArticle();
article2.setUrl("URL");
article2.setPicurl("PIC_URL");
article2.setDescription("Is Really A Happy Day");
article2.setTitle("Happy Day");
WxCustomMessage reply = WxCustomMessage.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\"}]}");
}
}