@@ -13,7 +13,7 @@ public class WxConsts { | |||||
public static final String XML_MSG_VOICE = "voice"; | public static final String XML_MSG_VOICE = "voice"; | ||||
public static final String XML_MSG_VIDEO = "video"; | public static final String XML_MSG_VIDEO = "video"; | ||||
public static final String XML_MSG_NEWS = "news"; | public static final String XML_MSG_NEWS = "news"; | ||||
public static final String XML_MSG_MUSIC = "news"; | |||||
public static final String XML_MSG_MUSIC = "music"; | |||||
public static final String XML_MSG_LOCATION = "location"; | public static final String XML_MSG_LOCATION = "location"; | ||||
public static final String XML_MSG_LINK = "link"; | public static final String XML_MSG_LINK = "link"; | ||||
public static final String XML_MSG_EVENT = "event"; | public static final String XML_MSG_EVENT = "event"; | ||||
@@ -0,0 +1,100 @@ | |||||
package chanjarster.weixin.bean; | |||||
import java.util.ArrayList; | |||||
import java.util.List; | |||||
import javax.xml.bind.annotation.XmlAccessType; | |||||
import javax.xml.bind.annotation.XmlAccessorType; | |||||
import javax.xml.bind.annotation.XmlElement; | |||||
import javax.xml.bind.annotation.XmlElementWrapper; | |||||
import javax.xml.bind.annotation.XmlRootElement; | |||||
import javax.xml.bind.annotation.adapters.XmlJavaTypeAdapter; | |||||
import chanjarster.weixin.api.WxConsts; | |||||
import chanjarster.weixin.util.xml.AdapterCDATA; | |||||
@XmlRootElement(name = "xml") | |||||
@XmlAccessorType(XmlAccessType.FIELD) | |||||
public class WxXmlOutMewsMessage extends WxXmlOutMessage { | |||||
@XmlElement(name = "ArticleCount") | |||||
protected int ArticleCount; | |||||
@XmlElementWrapper(name="Articles") | |||||
@XmlElement(name = "Item") | |||||
protected final List<Item> Articles = new ArrayList<Item>(); | |||||
public WxXmlOutMewsMessage() { | |||||
this.MsgType = WxConsts.XML_MSG_NEWS; | |||||
} | |||||
public int getArticleCount() { | |||||
return ArticleCount; | |||||
} | |||||
public void addArticle(Item item) { | |||||
this.Articles.add(item); | |||||
this.ArticleCount = this.Articles.size(); | |||||
} | |||||
public List<Item> getArticles() { | |||||
return Articles; | |||||
} | |||||
@XmlRootElement(name = "Item") | |||||
@XmlAccessorType(XmlAccessType.FIELD) | |||||
public static class Item { | |||||
@XmlElement(name = "Title") | |||||
@XmlJavaTypeAdapter(AdapterCDATA.class) | |||||
private String Title; | |||||
@XmlElement(name = "Description") | |||||
@XmlJavaTypeAdapter(AdapterCDATA.class) | |||||
private String Description; | |||||
@XmlElement(name="PicUrl") | |||||
@XmlJavaTypeAdapter(AdapterCDATA.class) | |||||
private String PicUrl; | |||||
@XmlElement(name="Url") | |||||
@XmlJavaTypeAdapter(AdapterCDATA.class) | |||||
private String Url; | |||||
public String getTitle() { | |||||
return Title; | |||||
} | |||||
public void setTitle(String title) { | |||||
Title = title; | |||||
} | |||||
public String getDescription() { | |||||
return Description; | |||||
} | |||||
public void setDescription(String description) { | |||||
Description = description; | |||||
} | |||||
public String getPicUrl() { | |||||
return PicUrl; | |||||
} | |||||
public void setPicUrl(String picUrl) { | |||||
PicUrl = picUrl; | |||||
} | |||||
public String getUrl() { | |||||
return Url; | |||||
} | |||||
public void setUrl(String url) { | |||||
Url = url; | |||||
} | |||||
} | |||||
} |
@@ -0,0 +1,129 @@ | |||||
package chanjarster.weixin.bean; | |||||
import javax.xml.bind.annotation.XmlAccessType; | |||||
import javax.xml.bind.annotation.XmlAccessorType; | |||||
import javax.xml.bind.annotation.XmlElement; | |||||
import javax.xml.bind.annotation.XmlRootElement; | |||||
import javax.xml.bind.annotation.adapters.XmlJavaTypeAdapter; | |||||
import chanjarster.weixin.api.WxConsts; | |||||
import chanjarster.weixin.util.xml.AdapterCDATA; | |||||
@XmlRootElement(name = "xml") | |||||
@XmlAccessorType(XmlAccessType.FIELD) | |||||
public class WxXmlOutMusicMessage extends WxXmlOutMessage { | |||||
@XmlElement(name = "Music") | |||||
protected final Music music = new Music(); | |||||
public WxXmlOutMusicMessage() { | |||||
this.MsgType = WxConsts.XML_MSG_MUSIC; | |||||
} | |||||
public String getTitle() { | |||||
return music.getTitle(); | |||||
} | |||||
public void setTitle(String title) { | |||||
music.setTitle(title); | |||||
} | |||||
public String getDescription() { | |||||
return music.getDescription(); | |||||
} | |||||
public void setDescription(String description) { | |||||
music.setDescription(description); | |||||
} | |||||
public String getThumbMediaId() { | |||||
return music.getThumbMediaId(); | |||||
} | |||||
public void setThumbMediaId(String thumbMediaId) { | |||||
music.setThumbMediaId(thumbMediaId); | |||||
} | |||||
public String getMusicUrl() { | |||||
return music.getMusicUrl(); | |||||
} | |||||
public void setMusicUrl(String musicUrl) { | |||||
music.setMusicUrl(musicUrl); | |||||
} | |||||
public String getHQMusicUrl() { | |||||
return music.getHQMusicUrl(); | |||||
} | |||||
public void setHQMusicUrl(String hQMusicUrl) { | |||||
music.setHQMusicUrl(hQMusicUrl); | |||||
} | |||||
@XmlRootElement(name = "Music") | |||||
@XmlAccessorType(XmlAccessType.FIELD) | |||||
private static class Music { | |||||
@XmlElement(name = "Title") | |||||
@XmlJavaTypeAdapter(AdapterCDATA.class) | |||||
private String Title; | |||||
@XmlElement(name = "Description") | |||||
@XmlJavaTypeAdapter(AdapterCDATA.class) | |||||
private String Description; | |||||
@XmlElement(name="ThumbMediaId") | |||||
@XmlJavaTypeAdapter(AdapterCDATA.class) | |||||
private String ThumbMediaId; | |||||
@XmlElement(name="MusicUrl") | |||||
@XmlJavaTypeAdapter(AdapterCDATA.class) | |||||
private String MusicUrl; | |||||
@XmlElement(name="HQMusicUrl") | |||||
@XmlJavaTypeAdapter(AdapterCDATA.class) | |||||
private String HQMusicUrl; | |||||
public String getTitle() { | |||||
return Title; | |||||
} | |||||
public void setTitle(String title) { | |||||
Title = title; | |||||
} | |||||
public String getDescription() { | |||||
return Description; | |||||
} | |||||
public void setDescription(String description) { | |||||
Description = description; | |||||
} | |||||
public String getThumbMediaId() { | |||||
return ThumbMediaId; | |||||
} | |||||
public void setThumbMediaId(String thumbMediaId) { | |||||
ThumbMediaId = thumbMediaId; | |||||
} | |||||
public String getMusicUrl() { | |||||
return MusicUrl; | |||||
} | |||||
public void setMusicUrl(String musicUrl) { | |||||
MusicUrl = musicUrl; | |||||
} | |||||
public String getHQMusicUrl() { | |||||
return HQMusicUrl; | |||||
} | |||||
public void setHQMusicUrl(String hQMusicUrl) { | |||||
HQMusicUrl = hQMusicUrl; | |||||
} | |||||
} | |||||
} |
@@ -0,0 +1,90 @@ | |||||
package chanjarster.weixin.bean; | |||||
import javax.xml.bind.annotation.XmlAccessType; | |||||
import javax.xml.bind.annotation.XmlAccessorType; | |||||
import javax.xml.bind.annotation.XmlElement; | |||||
import javax.xml.bind.annotation.XmlRootElement; | |||||
import javax.xml.bind.annotation.adapters.XmlJavaTypeAdapter; | |||||
import chanjarster.weixin.api.WxConsts; | |||||
import chanjarster.weixin.util.xml.AdapterCDATA; | |||||
@XmlRootElement(name = "xml") | |||||
@XmlAccessorType(XmlAccessType.FIELD) | |||||
public class WxXmlOutVideoMessage extends WxXmlOutMessage { | |||||
@XmlElement(name = "Video") | |||||
protected final Video video = new Video(); | |||||
public WxXmlOutVideoMessage() { | |||||
this.MsgType = WxConsts.XML_MSG_VIDEO; | |||||
} | |||||
public String getMediaId() { | |||||
return video.getMediaId(); | |||||
} | |||||
public void setMediaId(String mediaId) { | |||||
video.setMediaId(mediaId); | |||||
} | |||||
public String getTitle() { | |||||
return video.getTitle(); | |||||
} | |||||
public void setTitle(String title) { | |||||
video.setTitle(title); | |||||
} | |||||
public String getDescription() { | |||||
return video.getDescription(); | |||||
} | |||||
public void setDescription(String description) { | |||||
video.setDescription(description); | |||||
} | |||||
@XmlRootElement(name = "Video") | |||||
@XmlAccessorType(XmlAccessType.FIELD) | |||||
private static class Video { | |||||
@XmlElement(name = "MediaId") | |||||
@XmlJavaTypeAdapter(AdapterCDATA.class) | |||||
private String MediaId; | |||||
@XmlElement(name = "Title") | |||||
@XmlJavaTypeAdapter(AdapterCDATA.class) | |||||
private String Title; | |||||
@XmlElement(name = "Description") | |||||
@XmlJavaTypeAdapter(AdapterCDATA.class) | |||||
private String Description; | |||||
public String getMediaId() { | |||||
return MediaId; | |||||
} | |||||
public void setMediaId(String mediaId) { | |||||
MediaId = mediaId; | |||||
} | |||||
public String getTitle() { | |||||
return Title; | |||||
} | |||||
public void setTitle(String title) { | |||||
Title = title; | |||||
} | |||||
public String getDescription() { | |||||
return Description; | |||||
} | |||||
public void setDescription(String description) { | |||||
Description = description; | |||||
} | |||||
} | |||||
} |
@@ -6,6 +6,7 @@ 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.api.WxConsts; | |||||
import chanjarster.weixin.util.xml.MediaIdMarshaller; | import chanjarster.weixin.util.xml.MediaIdMarshaller; | ||||
@XmlRootElement(name = "xml") | @XmlRootElement(name = "xml") | ||||
@@ -16,6 +17,10 @@ public class WxXmlOutVoiceMessage extends WxXmlOutMessage { | |||||
@XmlJavaTypeAdapter(MediaIdMarshaller.class) | @XmlJavaTypeAdapter(MediaIdMarshaller.class) | ||||
private String MediaId; | private String MediaId; | ||||
public WxXmlOutVoiceMessage() { | |||||
this.MsgType = WxConsts.XML_MSG_VOICE; | |||||
} | |||||
public String getMediaId() { | public String getMediaId() { | ||||
return MediaId; | return MediaId; | ||||
} | } | ||||
@@ -0,0 +1,38 @@ | |||||
package chanjarster.weixin.bean; | |||||
import org.testng.Assert; | |||||
import org.testng.annotations.Test; | |||||
@Test | |||||
public class WxXmlOutIMusicMessageTest { | |||||
public void test() { | |||||
WxXmlOutMusicMessage m = new WxXmlOutMusicMessage(); | |||||
m.setTitle("title"); | |||||
m.setDescription("ddfff"); | |||||
m.setCreateTime(1122l); | |||||
m.setFromUserName("fromUser"); | |||||
m.setToUserName("toUser"); | |||||
m.setHQMusicUrl("hQMusicUrl"); | |||||
m.setMusicUrl("musicUrl"); | |||||
m.setThumbMediaId("thumbMediaId"); | |||||
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", ""), expected.replaceAll("\\s", "")); | |||||
} | |||||
} |
@@ -0,0 +1,48 @@ | |||||
package chanjarster.weixin.bean; | |||||
import org.testng.Assert; | |||||
import org.testng.annotations.Test; | |||||
@Test | |||||
public class WxXmlOutINewsMessageTest { | |||||
public void test() { | |||||
WxXmlOutMewsMessage m = new WxXmlOutMewsMessage(); | |||||
m.setCreateTime(1122l); | |||||
m.setFromUserName("fromUser"); | |||||
m.setToUserName("toUser"); | |||||
WxXmlOutMewsMessage.Item item = new WxXmlOutMewsMessage.Item(); | |||||
item.setDescription("description"); | |||||
item.setPicUrl("picUrl"); | |||||
item.setTitle("title"); | |||||
item.setUrl("url"); | |||||
m.addArticle(item); | |||||
m.addArticle(item); | |||||
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", ""), expected.replaceAll("\\s", "")); | |||||
} | |||||
} |
@@ -0,0 +1,34 @@ | |||||
package chanjarster.weixin.bean; | |||||
import org.testng.Assert; | |||||
import org.testng.annotations.Test; | |||||
@Test | |||||
public class WxXmlOutIVideoMessageTest { | |||||
public void test() { | |||||
WxXmlOutVideoMessage m = new WxXmlOutVideoMessage(); | |||||
m.setMediaId("media_id"); | |||||
m.setTitle("title"); | |||||
m.setDescription("ddfff"); | |||||
m.setCreateTime(1122l); | |||||
m.setFromUserName("fromUser"); | |||||
m.setToUserName("toUser"); | |||||
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", ""), expected.replaceAll("\\s", "")); | |||||
} | |||||
} |
@@ -0,0 +1,28 @@ | |||||
package chanjarster.weixin.bean; | |||||
import org.testng.Assert; | |||||
import org.testng.annotations.Test; | |||||
@Test | |||||
public class WxXmlOutIVoiceMessageTest { | |||||
public void test() { | |||||
WxXmlOutVoiceMessage m = new WxXmlOutVoiceMessage(); | |||||
m.setMediaId("ddfefesfsdfef"); | |||||
m.setCreateTime(1122l); | |||||
m.setFromUserName("from"); | |||||
m.setToUserName("to"); | |||||
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", ""), expected.replaceAll("\\s", "")); | |||||
} | |||||
} |