issue #10 提供客服消息Builder
This commit is contained in:
@@ -4,17 +4,17 @@ import chanjarster.weixin.bean.WxCustomMessage;
|
|||||||
|
|
||||||
public class BaseBuilder<T> {
|
public class BaseBuilder<T> {
|
||||||
protected String msgtype;
|
protected String msgtype;
|
||||||
protected String touser;
|
protected String toUser;
|
||||||
|
|
||||||
public T touser(String touser) {
|
public T toUser(String toUser) {
|
||||||
this.touser = touser;
|
this.toUser = toUser;
|
||||||
return (T) this;
|
return (T) this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public WxCustomMessage build() {
|
public WxCustomMessage build() {
|
||||||
WxCustomMessage m = new WxCustomMessage();
|
WxCustomMessage m = new WxCustomMessage();
|
||||||
m.setMsgtype(this.msgtype);
|
m.setMsgtype(this.msgtype);
|
||||||
m.setTouser(this.touser);
|
m.setTouser(this.toUser);
|
||||||
return m;
|
return m;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -18,7 +18,7 @@ public final class ImageBuilder extends BaseBuilder<ImageBuilder> {
|
|||||||
this.msgtype = WxConsts.CUSTOM_MSG_IMAGE;
|
this.msgtype = WxConsts.CUSTOM_MSG_IMAGE;
|
||||||
}
|
}
|
||||||
|
|
||||||
public ImageBuilder media_id(String media_id) {
|
public ImageBuilder mediaId(String media_id) {
|
||||||
this.media_id = media_id;
|
this.media_id = media_id;
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -27,12 +27,12 @@ public final class MusicBuilder extends BaseBuilder<MusicBuilder> {
|
|||||||
this.msgtype = WxConsts.CUSTOM_MSG_MUSIC;
|
this.msgtype = WxConsts.CUSTOM_MSG_MUSIC;
|
||||||
}
|
}
|
||||||
|
|
||||||
public MusicBuilder musicurl(String musicurl) {
|
public MusicBuilder musicUrl(String musicurl) {
|
||||||
this.musicurl = musicurl;
|
this.musicurl = musicurl;
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public MusicBuilder hqmusicurl(String hqmusicurl) {
|
public MusicBuilder hqmusicUrl(String hqmusicurl) {
|
||||||
this.hqmusicurl = hqmusicurl;
|
this.hqmusicurl = hqmusicurl;
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
@@ -47,7 +47,7 @@ public final class MusicBuilder extends BaseBuilder<MusicBuilder> {
|
|||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public MusicBuilder thumb_media_id(String thumb_media_id) {
|
public MusicBuilder thumbMediaId(String thumb_media_id) {
|
||||||
this.thumb_media_id = thumb_media_id;
|
this.thumb_media_id = thumb_media_id;
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -27,7 +27,7 @@ public final class VideoBuilder extends BaseBuilder<VideoBuilder> {
|
|||||||
this.msgtype = WxConsts.CUSTOM_MSG_VIDEO;
|
this.msgtype = WxConsts.CUSTOM_MSG_VIDEO;
|
||||||
}
|
}
|
||||||
|
|
||||||
public VideoBuilder media_id(String media_id) {
|
public VideoBuilder mediaId(String media_id) {
|
||||||
this.media_id = media_id;
|
this.media_id = media_id;
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
@@ -42,7 +42,7 @@ public final class VideoBuilder extends BaseBuilder<VideoBuilder> {
|
|||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public VideoBuilder thumb_media_id(String thumb_media_id) {
|
public VideoBuilder thumbMediaId(String thumb_media_id) {
|
||||||
this.thumb_media_id = thumb_media_id;
|
this.thumb_media_id = thumb_media_id;
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -18,7 +18,7 @@ public final class VoiceBuilder extends BaseBuilder<VoiceBuilder> {
|
|||||||
this.msgtype = WxConsts.CUSTOM_MSG_VOICE;
|
this.msgtype = WxConsts.CUSTOM_MSG_VOICE;
|
||||||
}
|
}
|
||||||
|
|
||||||
public VoiceBuilder media_id(String media_id) {
|
public VoiceBuilder mediaId(String media_id) {
|
||||||
this.media_id = media_id;
|
this.media_id = media_id;
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -25,7 +25,7 @@ public final class MusicBuilder extends BaseBuilder<MusicBuilder, WxXmlOutMusicM
|
|||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public MusicBuilder hQMusicUrl(String hQMusicUrl) {
|
public MusicBuilder hqmusicUrl(String hQMusicUrl) {
|
||||||
this.hQMusicUrl = hQMusicUrl;
|
this.hQMusicUrl = hQMusicUrl;
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -17,6 +17,11 @@ public class WxCustomMessageTest {
|
|||||||
Assert.assertEquals(reply.toJson(), "{\"touser\":\"OPENID\",\"msgtype\":\"text\",\"text\":{\"content\":\"sfsfdsdf\"}}");
|
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() {
|
public void testImageReply() {
|
||||||
WxCustomMessage reply = new WxCustomMessage();
|
WxCustomMessage reply = new WxCustomMessage();
|
||||||
reply.setTouser("OPENID");
|
reply.setTouser("OPENID");
|
||||||
@@ -25,6 +30,11 @@ public class WxCustomMessageTest {
|
|||||||
Assert.assertEquals(reply.toJson(), "{\"touser\":\"OPENID\",\"msgtype\":\"image\",\"image\":{\"media_id\":\"MEDIA_ID\"}}");
|
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() {
|
public void testVoiceReply() {
|
||||||
WxCustomMessage reply = new WxCustomMessage();
|
WxCustomMessage reply = new WxCustomMessage();
|
||||||
reply.setTouser("OPENID");
|
reply.setTouser("OPENID");
|
||||||
@@ -33,6 +43,11 @@ public class WxCustomMessageTest {
|
|||||||
Assert.assertEquals(reply.toJson(), "{\"touser\":\"OPENID\",\"msgtype\":\"voice\",\"voice\":{\"media_id\":\"MEDIA_ID\"}}");
|
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() {
|
public void testVideoReply() {
|
||||||
WxCustomMessage reply = new WxCustomMessage();
|
WxCustomMessage reply = new WxCustomMessage();
|
||||||
reply.setTouser("OPENID");
|
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\"}}");
|
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() {
|
public void testMusicReply() {
|
||||||
WxCustomMessage reply = new WxCustomMessage();
|
WxCustomMessage reply = new WxCustomMessage();
|
||||||
reply.setTouser("OPENID");
|
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\"}}");
|
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() {
|
public void testNewsReply() {
|
||||||
WxCustomMessage reply = new WxCustomMessage();
|
WxCustomMessage reply = new WxCustomMessage();
|
||||||
reply.setTouser("OPENID");
|
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\"}]}");
|
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\"}]}");
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -41,7 +41,7 @@ public class WxXmlOutIMusicMessageTest {
|
|||||||
.touser("toUser")
|
.touser("toUser")
|
||||||
.title("title")
|
.title("title")
|
||||||
.description("ddfff")
|
.description("ddfff")
|
||||||
.hQMusicUrl("hQMusicUrl")
|
.hqmusicUrl("hQMusicUrl")
|
||||||
.musicUrl("musicUrl")
|
.musicUrl("musicUrl")
|
||||||
.thumbMediaId("thumbMediaId")
|
.thumbMediaId("thumbMediaId")
|
||||||
.build();
|
.build();
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd" >
|
<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd" >
|
||||||
|
|
||||||
<suite name="Weixin-java-tool-suite" verbose="1">
|
<suite name="Weixin-java-tool-suite" verbose="1">
|
||||||
<test name="API_Test">
|
<test name="API_Test" enabled="false">
|
||||||
<classes>
|
<classes>
|
||||||
<class name="chanjarster.weixin.api.WxBaseAPITest" />
|
<class name="chanjarster.weixin.api.WxBaseAPITest" />
|
||||||
<class name="chanjarster.weixin.api.WxCustomMessageAPITest" />
|
<class name="chanjarster.weixin.api.WxCustomMessageAPITest" />
|
||||||
@@ -9,9 +9,9 @@
|
|||||||
<class name="chanjarster.weixin.api.WxGroupAPITest" />
|
<class name="chanjarster.weixin.api.WxGroupAPITest" />
|
||||||
<class name="chanjarster.weixin.api.WxMassMessageAPITest" />
|
<class name="chanjarster.weixin.api.WxMassMessageAPITest" />
|
||||||
<class name="chanjarster.weixin.api.WxMediaAPITest" />
|
<class name="chanjarster.weixin.api.WxMediaAPITest" />
|
||||||
<class name="chanjarster.weixin.api.WxUserAPITest" />
|
<class name="chanjarster.weixin.api.WxUserAPITest" />
|
||||||
<class name="chanjarster.weixin.api.WxQrCodeAPITest" />
|
<class name="chanjarster.weixin.api.WxQrCodeAPITest" />
|
||||||
<class name="chanjarster.weixin.api.WxShortUrlAPITest" />
|
<class name="chanjarster.weixin.api.WxShortUrlAPITest" />
|
||||||
<class name="chanjarster.weixin.api.WxMessageRouterTest" />
|
<class name="chanjarster.weixin.api.WxMessageRouterTest" />
|
||||||
</classes>
|
</classes>
|
||||||
</test>
|
</test>
|
||||||
@@ -23,6 +23,12 @@
|
|||||||
<class name="chanjarster.weixin.bean.WxErrorTest" />
|
<class name="chanjarster.weixin.bean.WxErrorTest" />
|
||||||
<class name="chanjarster.weixin.bean.WxMenuTest" />
|
<class name="chanjarster.weixin.bean.WxMenuTest" />
|
||||||
<class name="chanjarster.weixin.bean.WxXmlMessageTest" />
|
<class name="chanjarster.weixin.bean.WxXmlMessageTest" />
|
||||||
|
<class name="chanjarster.weixin.bean.WxXmlOutImageMessageTest" />
|
||||||
|
<class name="chanjarster.weixin.bean.WxXmlOutIMusicMessageTest" />
|
||||||
|
<class name="chanjarster.weixin.bean.WxXmlOutINewsMessageTest" />
|
||||||
|
<class name="chanjarster.weixin.bean.WxXmlOutIVideoMessageTest" />
|
||||||
|
<class name="chanjarster.weixin.bean.WxXmlOutIVoiceMessageTest" />
|
||||||
|
<class name="chanjarster.weixin.bean.WxXmlOutTextMessageTest" />
|
||||||
</classes>
|
</classes>
|
||||||
</test>
|
</test>
|
||||||
</suite>
|
</suite>
|
||||||
Reference in New Issue
Block a user