@@ -6,7 +6,6 @@ import java.util.List; | |||||
import chanjarster.weixin.api.WxConsts; | import chanjarster.weixin.api.WxConsts; | ||||
import chanjarster.weixin.bean.custombuilder.ImageBuilder; | import chanjarster.weixin.bean.custombuilder.ImageBuilder; | ||||
import chanjarster.weixin.bean.custombuilder.MusicBuilder; | import chanjarster.weixin.bean.custombuilder.MusicBuilder; | ||||
import chanjarster.weixin.bean.custombuilder.NewsArticleBuilder; | |||||
import chanjarster.weixin.bean.custombuilder.NewsBuilder; | import chanjarster.weixin.bean.custombuilder.NewsBuilder; | ||||
import chanjarster.weixin.bean.custombuilder.TextBuilder; | import chanjarster.weixin.bean.custombuilder.TextBuilder; | ||||
import chanjarster.weixin.bean.custombuilder.VideoBuilder; | import chanjarster.weixin.bean.custombuilder.VideoBuilder; | ||||
@@ -191,12 +190,4 @@ public class WxCustomMessage { | |||||
return new NewsBuilder(); | return new NewsBuilder(); | ||||
} | } | ||||
/** | |||||
* 获得图文消息文章builder | |||||
* @return | |||||
*/ | |||||
public static NewsArticleBuilder NEWS_ARTICLE() { | |||||
return new NewsArticleBuilder(); | |||||
} | |||||
} | } |
@@ -386,127 +386,5 @@ public class WxXmlMessage { | |||||
public void setErrorCount(Integer errorCount) { | public void setErrorCount(Integer errorCount) { | ||||
ErrorCount = errorCount; | ErrorCount = errorCount; | ||||
} | } | ||||
@Override | |||||
public int hashCode() { | |||||
final int prime = 31; | |||||
int result = 1; | |||||
result = prime * result + ((Content == null) ? 0 : Content.hashCode()); | |||||
result = prime * result + ((CreateTime == null) ? 0 : CreateTime.hashCode()); | |||||
result = prime * result + ((Description == null) ? 0 : Description.hashCode()); | |||||
result = prime * result + ErrorCount; | |||||
result = prime * result + ((Event == null) ? 0 : Event.hashCode()); | |||||
result = prime * result + ((EventKey == null) ? 0 : EventKey.hashCode()); | |||||
result = prime * result + FilterCount; | |||||
result = prime * result + ((Format == null) ? 0 : Format.hashCode()); | |||||
result = prime * result + ((FromUserName == null) ? 0 : FromUserName.hashCode()); | |||||
result = prime * result + ((Label == null) ? 0 : Label.hashCode()); | |||||
result = prime * result + ((Latitude == null) ? 0 : Latitude.hashCode()); | |||||
result = prime * result + ((Location_X == null) ? 0 : Location_X.hashCode()); | |||||
result = prime * result + ((Location_Y == null) ? 0 : Location_Y.hashCode()); | |||||
result = prime * result + ((Longitude == null) ? 0 : Longitude.hashCode()); | |||||
result = prime * result + ((MediaId == null) ? 0 : MediaId.hashCode()); | |||||
result = prime * result + ((MsgId == null) ? 0 : MsgId.hashCode()); | |||||
result = prime * result + ((MsgType == null) ? 0 : MsgType.hashCode()); | |||||
result = prime * result + ((PicUrl == null) ? 0 : PicUrl.hashCode()); | |||||
result = prime * result + ((Precision == null) ? 0 : Precision.hashCode()); | |||||
result = prime * result + ((Recognition == null) ? 0 : Recognition.hashCode()); | |||||
result = prime * result + ((Scale == null) ? 0 : Scale.hashCode()); | |||||
result = prime * result + SentCount; | |||||
result = prime * result + ((Status == null) ? 0 : Status.hashCode()); | |||||
result = prime * result + ((ThumbMediaId == null) ? 0 : ThumbMediaId.hashCode()); | |||||
result = prime * result + ((Ticket == null) ? 0 : Ticket.hashCode()); | |||||
result = prime * result + ((Title == null) ? 0 : Title.hashCode()); | |||||
result = prime * result + ((ToUserName == null) ? 0 : ToUserName.hashCode()); | |||||
result = prime * result + TotalCount; | |||||
result = prime * result + ((Url == null) ? 0 : Url.hashCode()); | |||||
return result; | |||||
} | |||||
@Override | |||||
public boolean equals(Object obj) { | |||||
if (this == obj) return true; | |||||
if (obj == null) return false; | |||||
if (getClass() != obj.getClass()) return false; | |||||
WxXmlMessage other = (WxXmlMessage) obj; | |||||
if (Content == null) { | |||||
if (other.Content != null) return false; | |||||
} else if (!Content.equals(other.Content)) return false; | |||||
if (CreateTime == null) { | |||||
if (other.CreateTime != null) return false; | |||||
} else if (!CreateTime.equals(other.CreateTime)) return false; | |||||
if (Description == null) { | |||||
if (other.Description != null) return false; | |||||
} else if (!Description.equals(other.Description)) return false; | |||||
if (ErrorCount != other.ErrorCount) return false; | |||||
if (Event == null) { | |||||
if (other.Event != null) return false; | |||||
} else if (!Event.equals(other.Event)) return false; | |||||
if (EventKey == null) { | |||||
if (other.EventKey != null) return false; | |||||
} else if (!EventKey.equals(other.EventKey)) return false; | |||||
if (FilterCount != other.FilterCount) return false; | |||||
if (Format == null) { | |||||
if (other.Format != null) return false; | |||||
} else if (!Format.equals(other.Format)) return false; | |||||
if (FromUserName == null) { | |||||
if (other.FromUserName != null) return false; | |||||
} else if (!FromUserName.equals(other.FromUserName)) return false; | |||||
if (Label == null) { | |||||
if (other.Label != null) return false; | |||||
} else if (!Label.equals(other.Label)) return false; | |||||
if (Latitude == null) { | |||||
if (other.Latitude != null) return false; | |||||
} else if (!Latitude.equals(other.Latitude)) return false; | |||||
if (Location_X == null) { | |||||
if (other.Location_X != null) return false; | |||||
} else if (!Location_X.equals(other.Location_X)) return false; | |||||
if (Location_Y == null) { | |||||
if (other.Location_Y != null) return false; | |||||
} else if (!Location_Y.equals(other.Location_Y)) return false; | |||||
if (Longitude == null) { | |||||
if (other.Longitude != null) return false; | |||||
} else if (!Longitude.equals(other.Longitude)) return false; | |||||
if (MediaId == null) { | |||||
if (other.MediaId != null) return false; | |||||
} else if (!MediaId.equals(other.MediaId)) return false; | |||||
if (MsgId == null) { | |||||
if (other.MsgId != null) return false; | |||||
} else if (!MsgId.equals(other.MsgId)) return false; | |||||
if (MsgType == null) { | |||||
if (other.MsgType != null) return false; | |||||
} else if (!MsgType.equals(other.MsgType)) return false; | |||||
if (PicUrl == null) { | |||||
if (other.PicUrl != null) return false; | |||||
} else if (!PicUrl.equals(other.PicUrl)) return false; | |||||
if (Precision == null) { | |||||
if (other.Precision != null) return false; | |||||
} else if (!Precision.equals(other.Precision)) return false; | |||||
if (Recognition == null) { | |||||
if (other.Recognition != null) return false; | |||||
} else if (!Recognition.equals(other.Recognition)) return false; | |||||
if (Scale == null) { | |||||
if (other.Scale != null) return false; | |||||
} else if (!Scale.equals(other.Scale)) return false; | |||||
if (SentCount != other.SentCount) return false; | |||||
if (Status == null) { | |||||
if (other.Status != null) return false; | |||||
} else if (!Status.equals(other.Status)) return false; | |||||
if (ThumbMediaId == null) { | |||||
if (other.ThumbMediaId != null) return false; | |||||
} else if (!ThumbMediaId.equals(other.ThumbMediaId)) return false; | |||||
if (Ticket == null) { | |||||
if (other.Ticket != null) return false; | |||||
} else if (!Ticket.equals(other.Ticket)) return false; | |||||
if (Title == null) { | |||||
if (other.Title != null) return false; | |||||
} else if (!Title.equals(other.Title)) return false; | |||||
if (ToUserName == null) { | |||||
if (other.ToUserName != null) return false; | |||||
} else if (!ToUserName.equals(other.ToUserName)) return false; | |||||
if (TotalCount != other.TotalCount) return false; | |||||
if (Url == null) { | |||||
if (other.Url != null) return false; | |||||
} else if (!Url.equals(other.Url)) return false; | |||||
return true; | |||||
} | |||||
} | } |
@@ -7,6 +7,12 @@ import javax.xml.bind.annotation.XmlElement; | |||||
import javax.xml.bind.annotation.XmlRootElement; | import javax.xml.bind.annotation.XmlRootElement; | ||||
import javax.xml.bind.annotation.adapters.XmlJavaTypeAdapter; | import javax.xml.bind.annotation.adapters.XmlJavaTypeAdapter; | ||||
import chanjarster.weixin.bean.outxmlbuilder.ImageBuilder; | |||||
import chanjarster.weixin.bean.outxmlbuilder.MusicBuilder; | |||||
import chanjarster.weixin.bean.outxmlbuilder.NewsBuilder; | |||||
import chanjarster.weixin.bean.outxmlbuilder.TextBuilder; | |||||
import chanjarster.weixin.bean.outxmlbuilder.VideoBuilder; | |||||
import chanjarster.weixin.bean.outxmlbuilder.VoiceBuilder; | |||||
import chanjarster.weixin.util.xml.AdapterCDATA; | import chanjarster.weixin.util.xml.AdapterCDATA; | ||||
import chanjarster.weixin.util.xml.XmlTransformer; | import chanjarster.weixin.util.xml.XmlTransformer; | ||||
@@ -69,4 +75,51 @@ public class WxXmlOutMessage { | |||||
return null; | return null; | ||||
} | } | ||||
/** | |||||
* 获得文本消息builder | |||||
* @return | |||||
*/ | |||||
public static TextBuilder TEXT() { | |||||
return new TextBuilder(); | |||||
} | |||||
/** | |||||
* 获得图片消息builder | |||||
* @return | |||||
*/ | |||||
public static ImageBuilder IMAGE() { | |||||
return new ImageBuilder(); | |||||
} | |||||
/** | |||||
* 获得语音消息builder | |||||
* @return | |||||
*/ | |||||
public static VoiceBuilder VOICE() { | |||||
return new VoiceBuilder(); | |||||
} | |||||
/** | |||||
* 获得视频消息builder | |||||
* @return | |||||
*/ | |||||
public static VideoBuilder VIDEO() { | |||||
return new VideoBuilder(); | |||||
} | |||||
/** | |||||
* 获得音乐消息builder | |||||
* @return | |||||
*/ | |||||
public static MusicBuilder MUSIC() { | |||||
return new MusicBuilder(); | |||||
} | |||||
/** | |||||
* 获得图文消息builder | |||||
* @return | |||||
*/ | |||||
public static NewsBuilder NEWS() { | |||||
return new NewsBuilder(); | |||||
} | |||||
} | } |
@@ -1,52 +0,0 @@ | |||||
package chanjarster.weixin.bean.custombuilder; | |||||
import chanjarster.weixin.bean.WxCustomMessage; | |||||
/** | |||||
* 图文消息文章builder | |||||
* <pre> | |||||
* 用法: WxCustomMessage.WxArticle m = WxCustomMessage.NEWS_ARTICLE() | |||||
* .url(...) | |||||
* .title(...) | |||||
* .picurl(...) | |||||
* .description(...) | |||||
* .build(); | |||||
* </pre> | |||||
* @author chanjarster | |||||
* | |||||
*/ | |||||
public final class NewsArticleBuilder { | |||||
private String title; | |||||
private String description; | |||||
private String url; | |||||
private String picurl; | |||||
public NewsArticleBuilder url(String url) { | |||||
this.url = url; | |||||
return this; | |||||
} | |||||
public NewsArticleBuilder title(String title) { | |||||
this.title = title; | |||||
return this; | |||||
} | |||||
public NewsArticleBuilder description(String description) { | |||||
this.description = description; | |||||
return this; | |||||
} | |||||
public NewsArticleBuilder picurl(String picurl) { | |||||
this.picurl = picurl; | |||||
return this; | |||||
} | |||||
public WxCustomMessage.WxArticle build() { | |||||
WxCustomMessage.WxArticle m = new WxCustomMessage.WxArticle(); | |||||
m.setPicurl(this.picurl); | |||||
m.setTitle(title); | |||||
m.setDescription(description); | |||||
m.setUrl(this.url); | |||||
return m; | |||||
} | |||||
} |
@@ -11,12 +11,6 @@ import chanjarster.weixin.bean.WxCustomMessage.WxArticle; | |||||
* 图文消息builder | * 图文消息builder | ||||
* <pre> | * <pre> | ||||
* 用法: | * 用法: | ||||
* WxCustomMessage.WxArticle article = WxCustomMessage.NEWS_ARTICLE() | |||||
* .url(...) | |||||
* .title(...) | |||||
* .picurl(...) | |||||
* .description(...) | |||||
* .build(); | |||||
* WxCustomMessage m = WxCustomMessage.NEWS().addArticle(article).touser(...).build(); | * WxCustomMessage m = WxCustomMessage.NEWS().addArticle(article).touser(...).build(); | ||||
* </pre> | * </pre> | ||||
* @author chanjarster | * @author chanjarster | ||||
@@ -9,8 +9,6 @@ public abstract class BaseBuilder<BuilderType, ValueType> { | |||||
protected String fromUserName; | protected String fromUserName; | ||||
protected String msgtype; | |||||
public BuilderType touser(String touser) { | public BuilderType touser(String touser) { | ||||
this.toUserName = touser; | this.toUserName = touser; | ||||
return (BuilderType) this; | return (BuilderType) this; | ||||
@@ -26,7 +24,6 @@ public abstract class BaseBuilder<BuilderType, ValueType> { | |||||
public void setCommon(WxXmlOutMessage m) { | public void setCommon(WxXmlOutMessage m) { | ||||
m.setToUserName(this.toUserName); | m.setToUserName(this.toUserName); | ||||
m.setFromUserName(this.fromUserName); | m.setFromUserName(this.fromUserName); | ||||
m.setMsgType(this.msgtype); | |||||
m.setCreateTime(System.currentTimeMillis() / 1000l); | m.setCreateTime(System.currentTimeMillis() / 1000l); | ||||
} | } | ||||
@@ -1,32 +1,24 @@ | |||||
package chanjarster.weixin.bean.outxmlbuilder; | package chanjarster.weixin.bean.outxmlbuilder; | ||||
import chanjarster.weixin.api.WxConsts; | |||||
import chanjarster.weixin.bean.WxXmlOutImageMessage; | import chanjarster.weixin.bean.WxXmlOutImageMessage; | ||||
/** | /** | ||||
* 获得消息builder | |||||
* <pre> | |||||
* 用法: WxXmlMessage m = WxXmlMessage.IMAGE().media_id(...).touser(...).build(); | |||||
* </pre> | |||||
* 图片消息builder | |||||
* @author chanjarster | * @author chanjarster | ||||
* | |||||
*/ | */ | ||||
public final class ImageBuilder extends BaseBuilder<ImageBuilder, WxXmlOutImageMessage> { | public final class ImageBuilder extends BaseBuilder<ImageBuilder, WxXmlOutImageMessage> { | ||||
private String media_id; | |||||
public ImageBuilder() { | |||||
this.msgtype = WxConsts.XML_MSG_IMAGE; | |||||
} | |||||
private String mediaId; | |||||
public ImageBuilder media_id(String media_id) { | |||||
this.media_id = media_id; | |||||
public ImageBuilder mediaId(String media_id) { | |||||
this.mediaId = media_id; | |||||
return this; | return this; | ||||
} | } | ||||
public WxXmlOutImageMessage build() { | public WxXmlOutImageMessage build() { | ||||
WxXmlOutImageMessage m = new WxXmlOutImageMessage(); | WxXmlOutImageMessage m = new WxXmlOutImageMessage(); | ||||
setCommon(m); | setCommon(m); | ||||
m.setMediaId(this.media_id); | |||||
m.setMediaId(this.mediaId); | |||||
return m; | return m; | ||||
} | } | ||||
@@ -0,0 +1,54 @@ | |||||
package chanjarster.weixin.bean.outxmlbuilder; | |||||
import chanjarster.weixin.bean.WxXmlOutMusicMessage; | |||||
/** | |||||
* 音乐消息builder | |||||
* | |||||
* @author chanjarster | |||||
*/ | |||||
public final class MusicBuilder extends BaseBuilder<MusicBuilder, WxXmlOutMusicMessage> { | |||||
private String title; | |||||
private String description; | |||||
private String hQMusicUrl; | |||||
private String musicUrl; | |||||
private String thumbMediaId; | |||||
public MusicBuilder title(String title) { | |||||
this.title = title; | |||||
return this; | |||||
} | |||||
public MusicBuilder description(String description) { | |||||
this.description = description; | |||||
return this; | |||||
} | |||||
public MusicBuilder hQMusicUrl(String hQMusicUrl) { | |||||
this.hQMusicUrl = hQMusicUrl; | |||||
return this; | |||||
} | |||||
public MusicBuilder musicUrl(String musicUrl) { | |||||
this.musicUrl = musicUrl; | |||||
return this; | |||||
} | |||||
public MusicBuilder thumbMediaId(String thumbMediaId) { | |||||
this.thumbMediaId = thumbMediaId; | |||||
return this; | |||||
} | |||||
public WxXmlOutMusicMessage build() { | |||||
WxXmlOutMusicMessage m = new WxXmlOutMusicMessage(); | |||||
setCommon(m); | |||||
m.setTitle(title); | |||||
m.setDescription(description); | |||||
m.setHQMusicUrl(hQMusicUrl); | |||||
m.setMusicUrl(musicUrl); | |||||
m.setThumbMediaId(thumbMediaId); | |||||
return m; | |||||
} | |||||
} |
@@ -0,0 +1,31 @@ | |||||
package chanjarster.weixin.bean.outxmlbuilder; | |||||
import java.util.ArrayList; | |||||
import java.util.List; | |||||
import chanjarster.weixin.bean.WxXmlOutMewsMessage; | |||||
import chanjarster.weixin.bean.WxXmlOutMewsMessage.Item; | |||||
/** | |||||
* 图文消息builder | |||||
* @author chanjarster | |||||
*/ | |||||
public final class NewsBuilder extends BaseBuilder<NewsBuilder, WxXmlOutMewsMessage> { | |||||
protected final List<Item> articles = new ArrayList<Item>(); | |||||
public NewsBuilder addArticle(Item item) { | |||||
this.articles.add(item); | |||||
return this; | |||||
} | |||||
public WxXmlOutMewsMessage build() { | |||||
WxXmlOutMewsMessage m = new WxXmlOutMewsMessage(); | |||||
for(Item item : articles) { | |||||
m.addArticle(item); | |||||
} | |||||
setCommon(m); | |||||
return m; | |||||
} | |||||
} |
@@ -1,23 +1,15 @@ | |||||
package chanjarster.weixin.bean.outxmlbuilder; | package chanjarster.weixin.bean.outxmlbuilder; | ||||
import chanjarster.weixin.api.WxConsts; | |||||
import chanjarster.weixin.bean.WxXmlOutTextMessage; | import chanjarster.weixin.bean.WxXmlOutTextMessage; | ||||
/** | /** | ||||
* 文本消息builder | * 文本消息builder | ||||
* <pre> | |||||
* 用法: WxXmlMessage m = WxXmlMessage.TEXT().touser(...).fromUser(...).content(...).build(); | |||||
* </pre> | |||||
* @author chanjarster | * @author chanjarster | ||||
* | * | ||||
*/ | */ | ||||
public final class TextBuilder extends BaseBuilder<TextBuilder, WxXmlOutTextMessage> { | public final class TextBuilder extends BaseBuilder<TextBuilder, WxXmlOutTextMessage> { | ||||
private String content; | private String content; | ||||
public TextBuilder() { | |||||
this.msgtype = WxConsts.XML_MSG_TEXT; | |||||
} | |||||
public TextBuilder content(String content) { | public TextBuilder content(String content) { | ||||
this.content = content; | this.content = content; | ||||
return this; | return this; | ||||
@@ -0,0 +1,38 @@ | |||||
package chanjarster.weixin.bean.outxmlbuilder; | |||||
import chanjarster.weixin.bean.WxXmlOutVideoMessage; | |||||
/** | |||||
* 视频消息builder | |||||
* @author chanjarster | |||||
* | |||||
*/ | |||||
public final class VideoBuilder extends BaseBuilder<VideoBuilder, WxXmlOutVideoMessage> { | |||||
private String mediaId; | |||||
private String title; | |||||
private String description; | |||||
public VideoBuilder title(String title) { | |||||
this.title = title; | |||||
return this; | |||||
} | |||||
public VideoBuilder description(String description) { | |||||
this.description = description; | |||||
return this; | |||||
} | |||||
public VideoBuilder mediaId(String mediaId) { | |||||
this.mediaId = mediaId; | |||||
return this; | |||||
} | |||||
public WxXmlOutVideoMessage build() { | |||||
WxXmlOutVideoMessage m = new WxXmlOutVideoMessage(); | |||||
setCommon(m); | |||||
m.setTitle(title); | |||||
m.setDescription(description); | |||||
m.setMediaId(mediaId); | |||||
return m; | |||||
} | |||||
} |
@@ -0,0 +1,25 @@ | |||||
package chanjarster.weixin.bean.outxmlbuilder; | |||||
import chanjarster.weixin.bean.WxXmlOutVoiceMessage; | |||||
/** | |||||
* 语音消息builder | |||||
* @author chanjarster | |||||
*/ | |||||
public final class VoiceBuilder extends BaseBuilder<VoiceBuilder, WxXmlOutVoiceMessage> { | |||||
private String mediaId; | |||||
public VoiceBuilder mediaId(String mediaId) { | |||||
this.mediaId = mediaId; | |||||
return this; | |||||
} | |||||
public WxXmlOutVoiceMessage build() { | |||||
WxXmlOutVoiceMessage m = new WxXmlOutVoiceMessage(); | |||||
setCommon(m); | |||||
m.setMediaId(mediaId); | |||||
return m; | |||||
} | |||||
} |
@@ -10,12 +10,12 @@ public class WxXmlOutIMusicMessageTest { | |||||
WxXmlOutMusicMessage m = new WxXmlOutMusicMessage(); | WxXmlOutMusicMessage m = new WxXmlOutMusicMessage(); | ||||
m.setTitle("title"); | m.setTitle("title"); | ||||
m.setDescription("ddfff"); | m.setDescription("ddfff"); | ||||
m.setCreateTime(1122l); | |||||
m.setFromUserName("fromUser"); | |||||
m.setToUserName("toUser"); | |||||
m.setHQMusicUrl("hQMusicUrl"); | m.setHQMusicUrl("hQMusicUrl"); | ||||
m.setMusicUrl("musicUrl"); | m.setMusicUrl("musicUrl"); | ||||
m.setThumbMediaId("thumbMediaId"); | m.setThumbMediaId("thumbMediaId"); | ||||
m.setCreateTime(1122l); | |||||
m.setFromUserName("fromUser"); | |||||
m.setToUserName("toUser"); | |||||
String expected = "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?>" | String expected = "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?>" | ||||
+ "<xml>" | + "<xml>" | ||||
@@ -35,4 +35,40 @@ public class WxXmlOutIMusicMessageTest { | |||||
Assert.assertEquals(m.toXml().replaceAll("\\s", ""), expected.replaceAll("\\s", "")); | Assert.assertEquals(m.toXml().replaceAll("\\s", ""), expected.replaceAll("\\s", "")); | ||||
} | } | ||||
public void testBuild() { | |||||
WxXmlOutMusicMessage m = WxXmlOutMessage.MUSIC() | |||||
.fromUser("fromUser") | |||||
.touser("toUser") | |||||
.title("title") | |||||
.description("ddfff") | |||||
.hQMusicUrl("hQMusicUrl") | |||||
.musicUrl("musicUrl") | |||||
.thumbMediaId("thumbMediaId") | |||||
.build(); | |||||
String expected = "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?>" | |||||
+ "<xml>" | |||||
+ "<ToUserName><![CDATA[toUser]]></ToUserName>" | |||||
+ "<FromUserName><![CDATA[fromUser]]></FromUserName>" | |||||
+ "<CreateTime>1122</CreateTime>" | |||||
+ "<MsgType><![CDATA[music]]></MsgType>" | |||||
+ "<Music>" | |||||
+ " <Title><![CDATA[title]]></Title>" | |||||
+ " <Description><![CDATA[ddfff]]></Description>" | |||||
+ " <ThumbMediaId><![CDATA[thumbMediaId]]></ThumbMediaId>" | |||||
+ " <MusicUrl><![CDATA[musicUrl]]></MusicUrl>" | |||||
+ " <HQMusicUrl><![CDATA[hQMusicUrl]]></HQMusicUrl>" | |||||
+ " </Music>" | |||||
+ "</xml>"; | |||||
System.out.println(m.toXml()); | |||||
Assert.assertEquals( | |||||
m | |||||
.toXml() | |||||
.replaceAll("\\s", "") | |||||
.replaceAll("<CreateTime>.*?</CreateTime>", ""), | |||||
expected | |||||
.replaceAll("\\s", "") | |||||
.replaceAll("<CreateTime>.*?</CreateTime>", "") | |||||
); | |||||
} | |||||
} | } |
@@ -45,4 +45,51 @@ public class WxXmlOutINewsMessageTest { | |||||
Assert.assertEquals(m.toXml().replaceAll("\\s", ""), expected.replaceAll("\\s", "")); | Assert.assertEquals(m.toXml().replaceAll("\\s", ""), expected.replaceAll("\\s", "")); | ||||
} | } | ||||
public void testBuild() { | |||||
WxXmlOutMewsMessage.Item item = new WxXmlOutMewsMessage.Item(); | |||||
item.setDescription("description"); | |||||
item.setPicUrl("picUrl"); | |||||
item.setTitle("title"); | |||||
item.setUrl("url"); | |||||
WxXmlOutMewsMessage m = WxXmlOutMessage.NEWS() | |||||
.fromUser("fromUser") | |||||
.touser("toUser") | |||||
.addArticle(item) | |||||
.addArticle(item) | |||||
.build(); | |||||
String expected = "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?>" | |||||
+ "<xml>" | |||||
+ "<ToUserName><![CDATA[toUser]]></ToUserName>" | |||||
+ "<FromUserName><![CDATA[fromUser]]></FromUserName>" | |||||
+ "<CreateTime>1122</CreateTime>" | |||||
+ "<MsgType><![CDATA[news]]></MsgType>" | |||||
+ " <ArticleCount>2</ArticleCount>" | |||||
+ " <Articles>" | |||||
+ " <Item>" | |||||
+ " <Title><![CDATA[title]]></Title>" | |||||
+ " <Description><![CDATA[description]]></Description>" | |||||
+ " <PicUrl><![CDATA[picUrl]]></PicUrl>" | |||||
+ " <Url><![CDATA[url]]></Url>" | |||||
+ " </Item>" | |||||
+ " <Item>" | |||||
+ " <Title><![CDATA[title]]></Title>" | |||||
+ " <Description><![CDATA[description]]></Description>" | |||||
+ " <PicUrl><![CDATA[picUrl]]></PicUrl>" | |||||
+ " <Url><![CDATA[url]]></Url>" | |||||
+ " </Item>" | |||||
+ " </Articles>" | |||||
+ "</xml>"; | |||||
System.out.println(m.toXml()); | |||||
Assert.assertEquals( | |||||
m | |||||
.toXml() | |||||
.replaceAll("\\s", "") | |||||
.replaceAll("<CreateTime>.*?</CreateTime>", ""), | |||||
expected | |||||
.replaceAll("\\s", "") | |||||
.replaceAll("<CreateTime>.*?</CreateTime>", "") | |||||
); | |||||
} | |||||
} | } |
@@ -31,4 +31,36 @@ public class WxXmlOutIVideoMessageTest { | |||||
Assert.assertEquals(m.toXml().replaceAll("\\s", ""), expected.replaceAll("\\s", "")); | Assert.assertEquals(m.toXml().replaceAll("\\s", ""), expected.replaceAll("\\s", "")); | ||||
} | } | ||||
public void testBuild() { | |||||
WxXmlOutVideoMessage m = WxXmlOutMessage.VIDEO() | |||||
.mediaId("media_id") | |||||
.fromUser("fromUser") | |||||
.touser("toUser") | |||||
.title("title") | |||||
.description("ddfff") | |||||
.build(); | |||||
String expected = "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?>" | |||||
+ "<xml>" | |||||
+ "<ToUserName><![CDATA[toUser]]></ToUserName>" | |||||
+ "<FromUserName><![CDATA[fromUser]]></FromUserName>" | |||||
+ "<CreateTime>1122</CreateTime>" | |||||
+ "<MsgType><![CDATA[video]]></MsgType>" | |||||
+ "<Video>" | |||||
+ "<MediaId><![CDATA[media_id]]></MediaId>" | |||||
+ "<Title><![CDATA[title]]></Title>" | |||||
+ "<Description><![CDATA[ddfff]]></Description>" | |||||
+ "</Video> " | |||||
+ "</xml>"; | |||||
System.out.println(m.toXml()); | |||||
Assert.assertEquals( | |||||
m | |||||
.toXml() | |||||
.replaceAll("\\s", "") | |||||
.replaceAll("<CreateTime>.*?</CreateTime>", ""), | |||||
expected | |||||
.replaceAll("\\s", "") | |||||
.replaceAll("<CreateTime>.*?</CreateTime>", "") | |||||
); | |||||
} | |||||
} | } |
@@ -25,4 +25,26 @@ public class WxXmlOutIVoiceMessageTest { | |||||
Assert.assertEquals(m.toXml().replaceAll("\\s", ""), expected.replaceAll("\\s", "")); | Assert.assertEquals(m.toXml().replaceAll("\\s", ""), expected.replaceAll("\\s", "")); | ||||
} | } | ||||
public void testBuild() { | |||||
WxXmlOutVoiceMessage m = WxXmlOutMessage.VOICE().mediaId("ddfefesfsdfef").fromUser("from").touser("to").build(); | |||||
String expected = "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?>" | |||||
+ "<xml>" | |||||
+ "<ToUserName><![CDATA[to]]></ToUserName>" | |||||
+ "<FromUserName><![CDATA[from]]></FromUserName>" | |||||
+ "<CreateTime>1122</CreateTime>" | |||||
+ "<MsgType><![CDATA[voice]]></MsgType>" | |||||
+ "<Voice><MediaId><![CDATA[ddfefesfsdfef]]></MediaId></Voice>" | |||||
+ "</xml>"; | |||||
System.out.println(m.toXml()); | |||||
Assert.assertEquals( | |||||
m | |||||
.toXml() | |||||
.replaceAll("\\s", "") | |||||
.replaceAll("<CreateTime>.*?</CreateTime>", ""), | |||||
expected | |||||
.replaceAll("\\s", "") | |||||
.replaceAll("<CreateTime>.*?</CreateTime>", "") | |||||
); | |||||
} | |||||
} | } |
@@ -25,4 +25,26 @@ public class WxXmlOutImageMessageTest { | |||||
Assert.assertEquals(m.toXml().replaceAll("\\s", ""), expected.replaceAll("\\s", "")); | Assert.assertEquals(m.toXml().replaceAll("\\s", ""), expected.replaceAll("\\s", "")); | ||||
} | } | ||||
public void testBuild() { | |||||
WxXmlOutImageMessage m = WxXmlOutMessage.IMAGE().mediaId("ddfefesfsdfef").fromUser("from").touser("to").build(); | |||||
String expected = "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?>" | |||||
+ "<xml>" | |||||
+ "<ToUserName><![CDATA[to]]></ToUserName>" | |||||
+ "<FromUserName><![CDATA[from]]></FromUserName>" | |||||
+ "<CreateTime>1122</CreateTime>" | |||||
+ "<MsgType><![CDATA[image]]></MsgType>" | |||||
+ "<Image><MediaId><![CDATA[ddfefesfsdfef]]></MediaId></Image>" | |||||
+ "</xml>"; | |||||
System.out.println(m.toXml()); | |||||
Assert.assertEquals( | |||||
m | |||||
.toXml() | |||||
.replaceAll("\\s", "") | |||||
.replaceAll("<CreateTime>.*?</CreateTime>", ""), | |||||
expected | |||||
.replaceAll("\\s", "") | |||||
.replaceAll("<CreateTime>.*?</CreateTime>", "") | |||||
); | |||||
} | |||||
} | } |
@@ -25,4 +25,28 @@ public class WxXmlOutTextMessageTest { | |||||
Assert.assertEquals(m.toXml().replaceAll("\\s", ""), expected.replaceAll("\\s", "")); | Assert.assertEquals(m.toXml().replaceAll("\\s", ""), expected.replaceAll("\\s", "")); | ||||
} | } | ||||
public void testBuild() { | |||||
WxXmlOutTextMessage m = WxXmlOutMessage.TEXT().content("content").fromUser("from").touser("to").build(); | |||||
String expected = "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?>" | |||||
+ "<xml>" | |||||
+ "<ToUserName><![CDATA[to]]></ToUserName>" | |||||
+ "<FromUserName><![CDATA[from]]></FromUserName>" | |||||
+ "<CreateTime>1122</CreateTime>" | |||||
+ "<MsgType><![CDATA[text]]></MsgType>" | |||||
+ "<Content><![CDATA[content]]></Content>" | |||||
+ "</xml>"; | |||||
System.out.println(m.toXml()); | |||||
Assert.assertEquals( | |||||
m | |||||
.toXml() | |||||
.replaceAll("\\s", "") | |||||
.replaceAll("<CreateTime>.*?</CreateTime>", ""), | |||||
expected | |||||
.replaceAll("\\s", "") | |||||
.replaceAll("<CreateTime>.*?</CreateTime>", "") | |||||
); | |||||
} | |||||
} | } |