@@ -80,7 +80,6 @@ public class XmlTransformer { | |||
WxCpXmlOutMessage.class, | |||
WxCpXmlOutImageMessage.class, | |||
WxCpXmlOutMewsMessage.class, | |||
WxCpXmlOutMusicMessage.class, | |||
WxCpXmlOutTextMessage.class, | |||
WxCpXmlOutVideoMessage.class, | |||
WxCpXmlOutVoiceMessage.class, | |||
@@ -3,7 +3,7 @@ package me.chanjar.weixin.enterprise.api; | |||
import java.util.HashMap; | |||
import java.util.Map; | |||
public class WxConsts { | |||
public class WxCpConsts { | |||
/////////////////////// | |||
// 微信推送过来的消息的类型,和发送给微信xml格式消息的消息类型 | |||
@@ -13,7 +13,6 @@ public class WxConsts { | |||
public static final String XML_MSG_VOICE = "voice"; | |||
public static final String XML_MSG_VIDEO = "video"; | |||
public static final String XML_MSG_NEWS = "news"; | |||
public static final String XML_MSG_MUSIC = "music"; | |||
public static final String XML_MSG_LOCATION = "location"; | |||
public static final String XML_MSG_LINK = "link"; | |||
public static final String XML_MSG_EVENT = "event"; | |||
@@ -25,7 +24,6 @@ public class WxConsts { | |||
public static final String CUSTOM_MSG_IMAGE = "image"; | |||
public static final String CUSTOM_MSG_VOICE = "voice"; | |||
public static final String CUSTOM_MSG_VIDEO = "video"; | |||
public static final String CUSTOM_MSG_MUSIC = "music"; | |||
public static final String CUSTOM_MSG_NEWS = "news"; | |||
public static final String CUSTOM_MSG_FILE = "file"; | |||
@@ -65,8 +65,8 @@ public interface WxCpService { | |||
* | |||
* 详情请见: http://mp.weixin.qq.com/wiki/index.php?title=上传下载多媒体文件 | |||
* </pre> | |||
* @param mediaType 媒体类型, 请看{@link WxConsts} | |||
* @param fileType 文件类型,请看{@link WxConsts} | |||
* @param mediaType 媒体类型, 请看{@link WxCpConsts} | |||
* @param fileType 文件类型,请看{@link WxCpConsts} | |||
* @param inputStream 输入流 | |||
* @throws WxErrorException | |||
*/ | |||
@@ -3,7 +3,6 @@ package me.chanjar.weixin.enterprise.bean; | |||
import java.util.ArrayList; | |||
import java.util.List; | |||
import me.chanjar.weixin.enterprise.api.WxConsts; | |||
import me.chanjar.weixin.enterprise.bean.messagebuilder.*; | |||
import me.chanjar.weixin.enterprise.util.json.WxCpGsonBuilder; | |||
@@ -66,12 +65,12 @@ public class WxCpMessage { | |||
/** | |||
* <pre> | |||
* 请使用 | |||
* {@link WxConsts#CUSTOM_MSG_TEXT} | |||
* {@link WxConsts#CUSTOM_MSG_IMAGE} | |||
* {@link WxConsts#CUSTOM_MSG_VOICE} | |||
* {@link WxConsts#CUSTOM_MSG_MUSIC} | |||
* {@link WxConsts#CUSTOM_MSG_VIDEO} | |||
* {@link WxConsts#CUSTOM_MSG_NEWS} | |||
* {@link me.chanjar.weixin.enterprise.api.WxCpConsts#CUSTOM_MSG_TEXT} | |||
* {@link me.chanjar.weixin.enterprise.api.WxCpConsts#CUSTOM_MSG_IMAGE} | |||
* {@link me.chanjar.weixin.enterprise.api.WxCpConsts#CUSTOM_MSG_VOICE} | |||
* {@link me.chanjar.weixin.enterprise.api.WxCpConsts#CUSTOM_MSG_MUSIC} | |||
* {@link me.chanjar.weixin.enterprise.api.WxCpConsts#CUSTOM_MSG_VIDEO} | |||
* {@link me.chanjar.weixin.enterprise.api.WxCpConsts#CUSTOM_MSG_NEWS} | |||
* </pre> | |||
* @param msgType | |||
*/ | |||
@@ -197,14 +196,6 @@ public class WxCpMessage { | |||
return new VideoBuilder(); | |||
} | |||
/** | |||
* 获得音乐消息builder | |||
* @return | |||
*/ | |||
public static MusicBuilder MUSIC() { | |||
return new MusicBuilder(); | |||
} | |||
/** | |||
* 获得图文消息builder | |||
* @return | |||
@@ -1,7 +1,6 @@ | |||
package me.chanjar.weixin.enterprise.bean; | |||
import me.chanjar.weixin.enterprise.api.WxCpConfigStorage; | |||
import me.chanjar.weixin.enterprise.api.WxConsts; | |||
import me.chanjar.weixin.common.AdapterCDATA; | |||
import me.chanjar.weixin.common.XmlTransformer; | |||
import me.chanjar.weixin.enterprise.util.crypto.WxCryptUtil; | |||
@@ -191,13 +190,13 @@ public class WxCpXmlMessage { | |||
/** | |||
* <pre> | |||
* 当接受用户消息时,可能会获得以下值: | |||
* {@link WxConsts#XML_MSG_TEXT} | |||
* {@link WxConsts#XML_MSG_IMAGE} | |||
* {@link WxConsts#XML_MSG_VOICE} | |||
* {@link WxConsts#XML_MSG_VIDEO} | |||
* {@link WxConsts#XML_MSG_LOCATION} | |||
* {@link WxConsts#XML_MSG_LINK} | |||
* {@link WxConsts#XML_MSG_EVENT} | |||
* {@link me.chanjar.weixin.enterprise.api.WxCpConsts#XML_MSG_TEXT} | |||
* {@link me.chanjar.weixin.enterprise.api.WxCpConsts#XML_MSG_IMAGE} | |||
* {@link me.chanjar.weixin.enterprise.api.WxCpConsts#XML_MSG_VOICE} | |||
* {@link me.chanjar.weixin.enterprise.api.WxCpConsts#XML_MSG_VIDEO} | |||
* {@link me.chanjar.weixin.enterprise.api.WxCpConsts#XML_MSG_LOCATION} | |||
* {@link me.chanjar.weixin.enterprise.api.WxCpConsts#XML_MSG_LINK} | |||
* {@link me.chanjar.weixin.enterprise.api.WxCpConsts#XML_MSG_EVENT} | |||
* </pre> | |||
* | |||
* @return | |||
@@ -209,12 +208,12 @@ public class WxCpXmlMessage { | |||
/** | |||
* <pre> | |||
* 当发送消息的时候使用: | |||
* {@link WxConsts#XML_MSG_TEXT} | |||
* {@link WxConsts#XML_MSG_IMAGE} | |||
* {@link WxConsts#XML_MSG_VOICE} | |||
* {@link WxConsts#XML_MSG_VIDEO} | |||
* {@link WxConsts#XML_MSG_NEWS} | |||
* {@link WxConsts#XML_MSG_MUSIC} | |||
* {@link me.chanjar.weixin.enterprise.api.WxCpConsts#XML_MSG_TEXT} | |||
* {@link me.chanjar.weixin.enterprise.api.WxCpConsts#XML_MSG_IMAGE} | |||
* {@link me.chanjar.weixin.enterprise.api.WxCpConsts#XML_MSG_VOICE} | |||
* {@link me.chanjar.weixin.enterprise.api.WxCpConsts#XML_MSG_VIDEO} | |||
* {@link me.chanjar.weixin.enterprise.api.WxCpConsts#XML_MSG_NEWS} | |||
* {@link me.chanjar.weixin.enterprise.api.WxCpConsts#XML_MSG_MUSIC} | |||
* </pre> | |||
* | |||
* @param msgType | |||
@@ -6,7 +6,7 @@ import javax.xml.bind.annotation.XmlElement; | |||
import javax.xml.bind.annotation.XmlRootElement; | |||
import javax.xml.bind.annotation.adapters.XmlJavaTypeAdapter; | |||
import me.chanjar.weixin.enterprise.api.WxConsts; | |||
import me.chanjar.weixin.enterprise.api.WxCpConsts; | |||
import me.chanjar.weixin.common.MediaIdMarshaller; | |||
@XmlRootElement(name = "xml") | |||
@@ -18,7 +18,7 @@ public class WxCpXmlOutImageMessage extends WxCpXmlOutMessage { | |||
private String mediaId; | |||
public WxCpXmlOutImageMessage() { | |||
this.msgType = WxConsts.XML_MSG_IMAGE; | |||
this.msgType = WxCpConsts.XML_MSG_IMAGE; | |||
} | |||
public String getMediaId() { | |||
@@ -9,7 +9,6 @@ import javax.xml.bind.annotation.adapters.XmlJavaTypeAdapter; | |||
import me.chanjar.weixin.enterprise.api.WxCpConfigStorage; | |||
import me.chanjar.weixin.enterprise.bean.outxmlbuilder.ImageBuilder; | |||
import me.chanjar.weixin.enterprise.bean.outxmlbuilder.MusicBuilder; | |||
import me.chanjar.weixin.enterprise.bean.outxmlbuilder.NewsBuilder; | |||
import me.chanjar.weixin.enterprise.bean.outxmlbuilder.TextBuilder; | |||
import me.chanjar.weixin.enterprise.bean.outxmlbuilder.VideoBuilder; | |||
@@ -119,14 +118,6 @@ public class WxCpXmlOutMessage { | |||
return new VideoBuilder(); | |||
} | |||
/** | |||
* 获得音乐消息builder | |||
* @return | |||
*/ | |||
public static MusicBuilder MUSIC() { | |||
return new MusicBuilder(); | |||
} | |||
/** | |||
* 获得图文消息builder | |||
* @return | |||
@@ -10,7 +10,7 @@ import javax.xml.bind.annotation.XmlElementWrapper; | |||
import javax.xml.bind.annotation.XmlRootElement; | |||
import javax.xml.bind.annotation.adapters.XmlJavaTypeAdapter; | |||
import me.chanjar.weixin.enterprise.api.WxConsts; | |||
import me.chanjar.weixin.enterprise.api.WxCpConsts; | |||
import me.chanjar.weixin.common.AdapterCDATA; | |||
@XmlRootElement(name = "xml") | |||
@@ -25,7 +25,7 @@ public class WxCpXmlOutMewsMessage extends WxCpXmlOutMessage { | |||
protected final List<Item> articles = new ArrayList<Item>(); | |||
public WxCpXmlOutMewsMessage() { | |||
this.msgType = WxConsts.XML_MSG_NEWS; | |||
this.msgType = WxCpConsts.XML_MSG_NEWS; | |||
} | |||
public int getArticleCount() { | |||
@@ -1,129 +0,0 @@ | |||
package me.chanjar.weixin.enterprise.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 me.chanjar.weixin.enterprise.api.WxConsts; | |||
import me.chanjar.weixin.common.AdapterCDATA; | |||
@XmlRootElement(name = "xml") | |||
@XmlAccessorType(XmlAccessType.FIELD) | |||
public class WxCpXmlOutMusicMessage extends WxCpXmlOutMessage { | |||
@XmlElement(name = "Music") | |||
protected final Music music = new Music(); | |||
public WxCpXmlOutMusicMessage() { | |||
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) { | |||
this.title = title; | |||
} | |||
public String getDescription() { | |||
return description; | |||
} | |||
public void setDescription(String description) { | |||
this.description = description; | |||
} | |||
public String getThumbMediaId() { | |||
return thumbMediaId; | |||
} | |||
public void setThumbMediaId(String thumbMediaId) { | |||
this.thumbMediaId = thumbMediaId; | |||
} | |||
public String getMusicUrl() { | |||
return musicUrl; | |||
} | |||
public void setMusicUrl(String musicUrl) { | |||
this.musicUrl = musicUrl; | |||
} | |||
public String getHqMusicUrl() { | |||
return hqMusicUrl; | |||
} | |||
public void setHqMusicUrl(String hqMusicUrl) { | |||
this.hqMusicUrl = hqMusicUrl; | |||
} | |||
} | |||
} |
@@ -6,7 +6,7 @@ import javax.xml.bind.annotation.XmlElement; | |||
import javax.xml.bind.annotation.XmlRootElement; | |||
import javax.xml.bind.annotation.adapters.XmlJavaTypeAdapter; | |||
import me.chanjar.weixin.enterprise.api.WxConsts; | |||
import me.chanjar.weixin.enterprise.api.WxCpConsts; | |||
import me.chanjar.weixin.common.AdapterCDATA; | |||
@XmlRootElement(name = "xml") | |||
@@ -18,7 +18,7 @@ public class WxCpXmlOutTextMessage extends WxCpXmlOutMessage { | |||
private String content; | |||
public WxCpXmlOutTextMessage() { | |||
this.msgType = WxConsts.XML_MSG_TEXT; | |||
this.msgType = WxCpConsts.XML_MSG_TEXT; | |||
} | |||
public String getContent() { | |||
@@ -6,7 +6,7 @@ import javax.xml.bind.annotation.XmlElement; | |||
import javax.xml.bind.annotation.XmlRootElement; | |||
import javax.xml.bind.annotation.adapters.XmlJavaTypeAdapter; | |||
import me.chanjar.weixin.enterprise.api.WxConsts; | |||
import me.chanjar.weixin.enterprise.api.WxCpConsts; | |||
import me.chanjar.weixin.common.AdapterCDATA; | |||
@XmlRootElement(name = "xml") | |||
@@ -17,7 +17,7 @@ public class WxCpXmlOutVideoMessage extends WxCpXmlOutMessage { | |||
protected final Video video = new Video(); | |||
public WxCpXmlOutVideoMessage() { | |||
this.msgType = WxConsts.XML_MSG_VIDEO; | |||
this.msgType = WxCpConsts.XML_MSG_VIDEO; | |||
} | |||
public String getMediaId() { | |||
@@ -6,7 +6,7 @@ import javax.xml.bind.annotation.XmlElement; | |||
import javax.xml.bind.annotation.XmlRootElement; | |||
import javax.xml.bind.annotation.adapters.XmlJavaTypeAdapter; | |||
import me.chanjar.weixin.enterprise.api.WxConsts; | |||
import me.chanjar.weixin.enterprise.api.WxCpConsts; | |||
import me.chanjar.weixin.common.MediaIdMarshaller; | |||
@XmlRootElement(name = "xml") | |||
@@ -18,7 +18,7 @@ public class WxCpXmlOutVoiceMessage extends WxCpXmlOutMessage { | |||
private String mediaId; | |||
public WxCpXmlOutVoiceMessage() { | |||
this.msgType = WxConsts.XML_MSG_VOICE; | |||
this.msgType = WxCpConsts.XML_MSG_VOICE; | |||
} | |||
public String getMediaId() { | |||
@@ -1,6 +1,6 @@ | |||
package me.chanjar.weixin.enterprise.bean.messagebuilder; | |||
import me.chanjar.weixin.enterprise.api.WxConsts; | |||
import me.chanjar.weixin.enterprise.api.WxCpConsts; | |||
import me.chanjar.weixin.enterprise.bean.WxCpMessage; | |||
/** | |||
@@ -15,7 +15,7 @@ public final class FileBuilder extends BaseBuilder<FileBuilder> { | |||
private String mediaId; | |||
public FileBuilder() { | |||
this.msgType = WxConsts.CUSTOM_MSG_FILE; | |||
this.msgType = WxCpConsts.CUSTOM_MSG_FILE; | |||
} | |||
public FileBuilder mediaId(String media_id) { | |||
@@ -1,6 +1,6 @@ | |||
package me.chanjar.weixin.enterprise.bean.messagebuilder; | |||
import me.chanjar.weixin.enterprise.api.WxConsts; | |||
import me.chanjar.weixin.enterprise.api.WxCpConsts; | |||
import me.chanjar.weixin.enterprise.bean.WxCpMessage; | |||
/** | |||
@@ -15,7 +15,7 @@ public final class ImageBuilder extends BaseBuilder<ImageBuilder> { | |||
private String mediaId; | |||
public ImageBuilder() { | |||
this.msgType = WxConsts.CUSTOM_MSG_IMAGE; | |||
this.msgType = WxCpConsts.CUSTOM_MSG_IMAGE; | |||
} | |||
public ImageBuilder mediaId(String media_id) { | |||
@@ -1,64 +0,0 @@ | |||
package me.chanjar.weixin.enterprise.bean.messagebuilder; | |||
import me.chanjar.weixin.enterprise.api.WxConsts; | |||
import me.chanjar.weixin.enterprise.bean.WxCpMessage; | |||
/** | |||
* 音乐消息builder | |||
* <pre> | |||
* 用法: WxCustomMessage m = WxCustomMessage.MUSIC() | |||
* .musicUrl(...) | |||
* .hqMusicUrl(...) | |||
* .title(...) | |||
* .thumbMediaId(..) | |||
* .description(..) | |||
* .toUser(...) | |||
* .build(); | |||
* </pre> | |||
*/ | |||
public final class MusicBuilder extends BaseBuilder<MusicBuilder> { | |||
private String title; | |||
private String description; | |||
private String thumbMediaId; | |||
private String musicUrl; | |||
private String hqMusicUrl; | |||
public MusicBuilder() { | |||
this.msgType = WxConsts.CUSTOM_MSG_MUSIC; | |||
} | |||
public MusicBuilder musicUrl(String musicurl) { | |||
this.musicUrl = musicurl; | |||
return this; | |||
} | |||
public MusicBuilder hqMusicUrl(String hqMusicurl) { | |||
this.hqMusicUrl = hqMusicurl; | |||
return this; | |||
} | |||
public MusicBuilder title(String title) { | |||
this.title = title; | |||
return this; | |||
} | |||
public MusicBuilder description(String description) { | |||
this.description = description; | |||
return this; | |||
} | |||
public MusicBuilder thumbMediaId(String thumb_media_id) { | |||
this.thumbMediaId = thumb_media_id; | |||
return this; | |||
} | |||
public WxCpMessage build() { | |||
WxCpMessage m = super.build(); | |||
m.setMusicUrl(this.musicUrl); | |||
m.setHqMusicUrl(this.hqMusicUrl); | |||
m.setTitle(title); | |||
m.setDescription(description); | |||
m.setThumbMediaId(thumbMediaId); | |||
return m; | |||
} | |||
} |
@@ -3,7 +3,7 @@ package me.chanjar.weixin.enterprise.bean.messagebuilder; | |||
import java.util.ArrayList; | |||
import java.util.List; | |||
import me.chanjar.weixin.enterprise.api.WxConsts; | |||
import me.chanjar.weixin.enterprise.api.WxCpConsts; | |||
import me.chanjar.weixin.enterprise.bean.WxCpMessage; | |||
/** | |||
@@ -20,7 +20,7 @@ public final class NewsBuilder extends BaseBuilder<NewsBuilder> { | |||
private List<WxCpMessage.WxArticle> articles = new ArrayList<WxCpMessage.WxArticle>(); | |||
public NewsBuilder() { | |||
this.msgType = WxConsts.CUSTOM_MSG_NEWS; | |||
this.msgType = WxCpConsts.CUSTOM_MSG_NEWS; | |||
} | |||
public NewsBuilder addArticle(WxCpMessage.WxArticle article) { | |||
@@ -1,6 +1,6 @@ | |||
package me.chanjar.weixin.enterprise.bean.messagebuilder; | |||
import me.chanjar.weixin.enterprise.api.WxConsts; | |||
import me.chanjar.weixin.enterprise.api.WxCpConsts; | |||
import me.chanjar.weixin.enterprise.bean.WxCpMessage; | |||
/** | |||
@@ -15,7 +15,7 @@ public final class TextBuilder extends BaseBuilder<TextBuilder> { | |||
private String content; | |||
public TextBuilder() { | |||
this.msgType = WxConsts.CUSTOM_MSG_TEXT; | |||
this.msgType = WxCpConsts.CUSTOM_MSG_TEXT; | |||
} | |||
public TextBuilder content(String content) { | |||
@@ -1,6 +1,6 @@ | |||
package me.chanjar.weixin.enterprise.bean.messagebuilder; | |||
import me.chanjar.weixin.enterprise.api.WxConsts; | |||
import me.chanjar.weixin.enterprise.api.WxCpConsts; | |||
import me.chanjar.weixin.enterprise.bean.WxCpMessage; | |||
/** | |||
@@ -24,7 +24,7 @@ public final class VideoBuilder extends BaseBuilder<VideoBuilder> { | |||
private String thumbMediaId; | |||
public VideoBuilder() { | |||
this.msgType = WxConsts.CUSTOM_MSG_VIDEO; | |||
this.msgType = WxCpConsts.CUSTOM_MSG_VIDEO; | |||
} | |||
public VideoBuilder mediaId(String mediaId) { | |||
@@ -1,6 +1,6 @@ | |||
package me.chanjar.weixin.enterprise.bean.messagebuilder; | |||
import me.chanjar.weixin.enterprise.api.WxConsts; | |||
import me.chanjar.weixin.enterprise.api.WxCpConsts; | |||
import me.chanjar.weixin.enterprise.bean.WxCpMessage; | |||
/** | |||
@@ -15,7 +15,7 @@ public final class VoiceBuilder extends BaseBuilder<VoiceBuilder> { | |||
private String mediaId; | |||
public VoiceBuilder() { | |||
this.msgType = WxConsts.CUSTOM_MSG_VOICE; | |||
this.msgType = WxCpConsts.CUSTOM_MSG_VOICE; | |||
} | |||
public VoiceBuilder mediaId(String media_id) { | |||
@@ -1,54 +0,0 @@ | |||
package me.chanjar.weixin.enterprise.bean.outxmlbuilder; | |||
import me.chanjar.weixin.enterprise.bean.WxCpXmlOutMusicMessage; | |||
/** | |||
* 音乐消息builder | |||
* | |||
* @author Daniel Qian | |||
*/ | |||
public final class MusicBuilder extends BaseBuilder<MusicBuilder, WxCpXmlOutMusicMessage> { | |||
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 WxCpXmlOutMusicMessage build() { | |||
WxCpXmlOutMusicMessage m = new WxCpXmlOutMusicMessage(); | |||
setCommon(m); | |||
m.setTitle(title); | |||
m.setDescription(description); | |||
m.setHqMusicUrl(hqMusicUrl); | |||
m.setMusicUrl(musicUrl); | |||
m.setThumbMediaId(thumbMediaId); | |||
return m; | |||
} | |||
} |
@@ -10,7 +10,7 @@ package me.chanjar.weixin.enterprise.util.json; | |||
import java.lang.reflect.Type; | |||
import me.chanjar.weixin.enterprise.api.WxConsts; | |||
import me.chanjar.weixin.enterprise.api.WxCpConsts; | |||
import me.chanjar.weixin.enterprise.bean.WxCpMessage; | |||
import com.google.gson.JsonArray; | |||
@@ -41,31 +41,31 @@ public class WxCpMessageGsonAdapter implements JsonSerializer<WxCpMessage> { | |||
if (StringUtils.isNotBlank(message.getToTag())) { | |||
messageJson.addProperty("totag", message.getToUser()); | |||
} | |||
if (WxConsts.CUSTOM_MSG_TEXT.equals(message.getMsgType())) { | |||
if (WxCpConsts.CUSTOM_MSG_TEXT.equals(message.getMsgType())) { | |||
JsonObject text = new JsonObject(); | |||
text.addProperty("content", message.getContent()); | |||
messageJson.add("text", text); | |||
} | |||
if (WxConsts.CUSTOM_MSG_IMAGE.equals(message.getMsgType())) { | |||
if (WxCpConsts.CUSTOM_MSG_IMAGE.equals(message.getMsgType())) { | |||
JsonObject image = new JsonObject(); | |||
image.addProperty("media_id", message.getMediaId()); | |||
messageJson.add("image", image); | |||
} | |||
if (WxConsts.CUSTOM_MSG_FILE.equals(message.getMsgType())) { | |||
if (WxCpConsts.CUSTOM_MSG_FILE.equals(message.getMsgType())) { | |||
JsonObject image = new JsonObject(); | |||
image.addProperty("media_id", message.getMediaId()); | |||
messageJson.add("file", image); | |||
} | |||
if (WxConsts.CUSTOM_MSG_VOICE.equals(message.getMsgType())) { | |||
if (WxCpConsts.CUSTOM_MSG_VOICE.equals(message.getMsgType())) { | |||
JsonObject voice = new JsonObject(); | |||
voice.addProperty("media_id", message.getMediaId()); | |||
messageJson.add("voice", voice); | |||
} | |||
if (WxConsts.CUSTOM_MSG_VIDEO.equals(message.getMsgType())) { | |||
if (WxCpConsts.CUSTOM_MSG_VIDEO.equals(message.getMsgType())) { | |||
JsonObject video = new JsonObject(); | |||
video.addProperty("media_id", message.getMediaId()); | |||
video.addProperty("thumb_media_id", message.getThumbMediaId()); | |||
@@ -74,17 +74,7 @@ public class WxCpMessageGsonAdapter implements JsonSerializer<WxCpMessage> { | |||
messageJson.add("video", video); | |||
} | |||
if (WxConsts.CUSTOM_MSG_MUSIC.equals(message.getMsgType())) { | |||
JsonObject music = new JsonObject(); | |||
music.addProperty("title", message.getTitle()); | |||
music.addProperty("description", message.getDescription()); | |||
music.addProperty("thumb_media_id", message.getThumbMediaId()); | |||
music.addProperty("musicurl", message.getMusicUrl()); | |||
music.addProperty("hqmusicurl", message.getHqMusicUrl()); | |||
messageJson.add("music", music); | |||
} | |||
if (WxConsts.CUSTOM_MSG_NEWS.equals(message.getMsgType())) { | |||
if (WxCpConsts.CUSTOM_MSG_NEWS.equals(message.getMsgType())) { | |||
JsonArray articleJsonArray = new JsonArray(); | |||
for (WxCpMessage.WxArticle article : message.getArticles()) { | |||
JsonObject articleJson = new JsonObject(); | |||
@@ -24,7 +24,7 @@ public class WxCpMessageAPITest { | |||
ApiTestModule.WxXmlCpConfigStorage configStorage = (ApiTestModule.WxXmlCpConfigStorage) wxService.wxCpConfigStorage; | |||
WxCpMessage message1 = new WxCpMessage(); | |||
message1.setAgentId(configStorage.getAgentId()); | |||
message1.setMsgType(WxConsts.CUSTOM_MSG_TEXT); | |||
message1.setMsgType(WxCpConsts.CUSTOM_MSG_TEXT); | |||
message1.setToUser(configStorage.getUserId()); | |||
message1.setContent("欢迎欢迎,热烈欢迎\n换行测试\n超链接:<a href=\"http://www.baidu.com\">Hello World</a>"); | |||
wxService.messageSend(message1); | |||
@@ -21,21 +21,21 @@ public class WxCpMessageRouterTest { | |||
router | |||
.rule() | |||
.async(async) | |||
.msgType(WxConsts.XML_MSG_TEXT).event(WxConsts.EVT_CLICK).eventKey("KEY_1").content("CONTENT_1") | |||
.msgType(WxCpConsts.XML_MSG_TEXT).event(WxCpConsts.EVT_CLICK).eventKey("KEY_1").content("CONTENT_1") | |||
.handler(new WxEchoCpMessageHandler(sb, "COMBINE_4")) | |||
.end() | |||
.rule() | |||
.async(async) | |||
.msgType(WxConsts.XML_MSG_TEXT).event(WxConsts.EVT_CLICK).eventKey("KEY_1") | |||
.msgType(WxCpConsts.XML_MSG_TEXT).event(WxCpConsts.EVT_CLICK).eventKey("KEY_1") | |||
.handler(new WxEchoCpMessageHandler(sb, "COMBINE_3")) | |||
.end() | |||
.rule() | |||
.async(async) | |||
.msgType(WxConsts.XML_MSG_TEXT).event(WxConsts.EVT_CLICK) | |||
.msgType(WxCpConsts.XML_MSG_TEXT).event(WxCpConsts.EVT_CLICK) | |||
.handler(new WxEchoCpMessageHandler(sb, "COMBINE_2")) | |||
.end() | |||
.rule().async(async).msgType(WxConsts.XML_MSG_TEXT).handler(new WxEchoCpMessageHandler(sb, WxConsts.XML_MSG_TEXT)).end() | |||
.rule().async(async).event(WxConsts.EVT_CLICK).handler(new WxEchoCpMessageHandler(sb, WxConsts.EVT_CLICK)).end() | |||
.rule().async(async).msgType(WxCpConsts.XML_MSG_TEXT).handler(new WxEchoCpMessageHandler(sb, WxCpConsts.XML_MSG_TEXT)).end() | |||
.rule().async(async).event(WxCpConsts.EVT_CLICK).handler(new WxEchoCpMessageHandler(sb, WxCpConsts.EVT_CLICK)).end() | |||
.rule().async(async).eventKey("KEY_1").handler(new WxEchoCpMessageHandler(sb, "KEY_1")).end() | |||
.rule().async(async).content("CONTENT_1").handler(new WxEchoCpMessageHandler(sb, "CONTENT_1")).end() | |||
.rule().async(async).rContent(".*bc.*").handler(new WxEchoCpMessageHandler(sb, "abcd")).end() | |||
@@ -91,10 +91,10 @@ public class WxCpMessageRouterTest { | |||
@DataProvider(name="messages-1") | |||
public Object[][] messages2() { | |||
WxCpXmlMessage message1 = new WxCpXmlMessage(); | |||
message1.setMsgType(WxConsts.XML_MSG_TEXT); | |||
message1.setMsgType(WxCpConsts.XML_MSG_TEXT); | |||
WxCpXmlMessage message2 = new WxCpXmlMessage(); | |||
message2.setEvent(WxConsts.EVT_CLICK); | |||
message2.setEvent(WxCpConsts.EVT_CLICK); | |||
WxCpXmlMessage message3 = new WxCpXmlMessage(); | |||
message3.setEventKey("KEY_1"); | |||
@@ -109,23 +109,23 @@ public class WxCpMessageRouterTest { | |||
message6.setContent("abcd"); | |||
WxCpXmlMessage c2 = new WxCpXmlMessage(); | |||
c2.setMsgType(WxConsts.XML_MSG_TEXT); | |||
c2.setEvent(WxConsts.EVT_CLICK); | |||
c2.setMsgType(WxCpConsts.XML_MSG_TEXT); | |||
c2.setEvent(WxCpConsts.EVT_CLICK); | |||
WxCpXmlMessage c3 = new WxCpXmlMessage(); | |||
c3.setMsgType(WxConsts.XML_MSG_TEXT); | |||
c3.setEvent(WxConsts.EVT_CLICK); | |||
c3.setMsgType(WxCpConsts.XML_MSG_TEXT); | |||
c3.setEvent(WxCpConsts.EVT_CLICK); | |||
c3.setEventKey("KEY_1"); | |||
WxCpXmlMessage c4 = new WxCpXmlMessage(); | |||
c4.setMsgType(WxConsts.XML_MSG_TEXT); | |||
c4.setEvent(WxConsts.EVT_CLICK); | |||
c4.setMsgType(WxCpConsts.XML_MSG_TEXT); | |||
c4.setEvent(WxCpConsts.EVT_CLICK); | |||
c4.setEventKey("KEY_1"); | |||
c4.setContent("CONTENT_1"); | |||
return new Object[][] { | |||
new Object[] { message1, WxConsts.XML_MSG_TEXT + "," }, | |||
new Object[] { message2, WxConsts.EVT_CLICK + "," }, | |||
new Object[] { message1, WxCpConsts.XML_MSG_TEXT + "," }, | |||
new Object[] { message2, WxCpConsts.EVT_CLICK + "," }, | |||
new Object[] { message3, "KEY_1," }, | |||
new Object[] { message4, "CONTENT_1," }, | |||
new Object[] { message5, "ALL," }, | |||
@@ -48,10 +48,10 @@ public class WxMediaAPITest { | |||
@DataProvider | |||
public Object[][] uploadMedia() { | |||
return new Object[][] { | |||
new Object[] { WxConsts.MEDIA_IMAGE, WxConsts.FILE_JPG, "mm.jpeg" }, | |||
new Object[] { WxConsts.MEDIA_VOICE, WxConsts.FILE_MP3, "mm.mp3" }, | |||
new Object[] { WxConsts.MEDIA_VIDEO, WxConsts.FILE_MP4, "mm.mp4" }, | |||
new Object[] { WxConsts.MEDIA_THUMB, WxConsts.FILE_JPG, "mm.jpeg" } | |||
new Object[] { WxCpConsts.MEDIA_IMAGE, WxCpConsts.FILE_JPG, "mm.jpeg" }, | |||
new Object[] { WxCpConsts.MEDIA_VOICE, WxCpConsts.FILE_MP3, "mm.mp3" }, | |||
new Object[] { WxCpConsts.MEDIA_VIDEO, WxCpConsts.FILE_MP4, "mm.mp4" }, | |||
new Object[] { WxCpConsts.MEDIA_THUMB, WxCpConsts.FILE_JPG, "mm.jpeg" } | |||
}; | |||
} | |||
@@ -44,12 +44,12 @@ public class WxMenuAPITest { | |||
public Object[][] getMenu() throws JAXBException { | |||
WxMenu menu = new WxMenu(); | |||
WxMenuButton button1 = new WxMenuButton(); | |||
button1.setType(WxConsts.BUTTON_CLICK); | |||
button1.setType(WxCpConsts.BUTTON_CLICK); | |||
button1.setName("今日歌曲"); | |||
button1.setKey("V1001_TODAY_MUSIC"); | |||
WxMenuButton button2 = new WxMenuButton(); | |||
button2.setType(WxConsts.BUTTON_CLICK); | |||
button2.setType(WxCpConsts.BUTTON_CLICK); | |||
button2.setName("歌手简介"); | |||
button2.setKey("V1001_TODAY_SINGER"); | |||
@@ -61,17 +61,17 @@ public class WxMenuAPITest { | |||
menu.getButtons().add(button3); | |||
WxMenuButton button31 = new WxMenuButton(); | |||
button31.setType(WxConsts.BUTTON_VIEW); | |||
button31.setType(WxCpConsts.BUTTON_VIEW); | |||
button31.setName("搜索"); | |||
button31.setUrl("http://www.soso.com/"); | |||
WxMenuButton button32 = new WxMenuButton(); | |||
button32.setType(WxConsts.BUTTON_VIEW); | |||
button32.setType(WxCpConsts.BUTTON_VIEW); | |||
button32.setName("视频"); | |||
button32.setUrl("http://v.qq.com/"); | |||
WxMenuButton button33 = new WxMenuButton(); | |||
button33.setType(WxConsts.BUTTON_CLICK); | |||
button33.setType(WxCpConsts.BUTTON_CLICK); | |||
button33.setName("赞一下我们"); | |||
button33.setKey("V1001_GOOD"); | |||
@@ -1,9 +1,9 @@ | |||
package me.chanjar.weixin.enterprise.bean; | |||
import me.chanjar.weixin.enterprise.api.WxCpConsts; | |||
import org.testng.Assert; | |||
import org.testng.annotations.Test; | |||
import me.chanjar.weixin.enterprise.api.WxConsts; | |||
import me.chanjar.weixin.enterprise.bean.WxCpMessage.WxArticle; | |||
@Test | |||
@@ -12,7 +12,7 @@ public class WxCpMessageTest { | |||
public void testTextReply() { | |||
WxCpMessage reply = new WxCpMessage(); | |||
reply.setToUser("OPENID"); | |||
reply.setMsgType(WxConsts.CUSTOM_MSG_TEXT); | |||
reply.setMsgType(WxCpConsts.CUSTOM_MSG_TEXT); | |||
reply.setContent("sfsfdsdf"); | |||
Assert.assertEquals(reply.toJson(), "{\"touser\":\"OPENID\",\"msgtype\":\"text\",\"text\":{\"content\":\"sfsfdsdf\"}}"); | |||
} | |||
@@ -25,7 +25,7 @@ public class WxCpMessageTest { | |||
public void testImageReply() { | |||
WxCpMessage reply = new WxCpMessage(); | |||
reply.setToUser("OPENID"); | |||
reply.setMsgType(WxConsts.CUSTOM_MSG_IMAGE); | |||
reply.setMsgType(WxCpConsts.CUSTOM_MSG_IMAGE); | |||
reply.setMediaId("MEDIA_ID"); | |||
Assert.assertEquals(reply.toJson(), "{\"touser\":\"OPENID\",\"msgtype\":\"image\",\"image\":{\"media_id\":\"MEDIA_ID\"}}"); | |||
} | |||
@@ -38,7 +38,7 @@ public class WxCpMessageTest { | |||
public void testVoiceReply() { | |||
WxCpMessage reply = new WxCpMessage(); | |||
reply.setToUser("OPENID"); | |||
reply.setMsgType(WxConsts.CUSTOM_MSG_VOICE); | |||
reply.setMsgType(WxCpConsts.CUSTOM_MSG_VOICE); | |||
reply.setMediaId("MEDIA_ID"); | |||
Assert.assertEquals(reply.toJson(), "{\"touser\":\"OPENID\",\"msgtype\":\"voice\",\"voice\":{\"media_id\":\"MEDIA_ID\"}}"); | |||
} | |||
@@ -51,7 +51,7 @@ public class WxCpMessageTest { | |||
public void testVideoReply() { | |||
WxCpMessage reply = new WxCpMessage(); | |||
reply.setToUser("OPENID"); | |||
reply.setMsgType(WxConsts.CUSTOM_MSG_VIDEO); | |||
reply.setMsgType(WxCpConsts.CUSTOM_MSG_VIDEO); | |||
reply.setMediaId("MEDIA_ID"); | |||
reply.setThumbMediaId("MEDIA_ID"); | |||
reply.setTitle("TITLE"); | |||
@@ -64,34 +64,10 @@ public class WxCpMessageTest { | |||
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() { | |||
WxCpMessage reply = new WxCpMessage(); | |||
reply.setToUser("OPENID"); | |||
reply.setMsgType(WxConsts.CUSTOM_MSG_MUSIC); | |||
reply.setThumbMediaId("MEDIA_ID"); | |||
reply.setDescription("DESCRIPTION"); | |||
reply.setTitle("TITLE"); | |||
reply.setMusicUrl("MUSIC_URL"); | |||
reply.setHqMusicUrl("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() { | |||
WxCpMessage reply = WxCpMessage.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() { | |||
WxCpMessage reply = new WxCpMessage(); | |||
reply.setToUser("OPENID"); | |||
reply.setMsgType(WxConsts.CUSTOM_MSG_NEWS); | |||
reply.setMsgType(WxCpConsts.CUSTOM_MSG_NEWS); | |||
WxArticle article1 = new WxArticle(); | |||
article1.setUrl("URL"); | |||
@@ -1,6 +1,6 @@ | |||
package me.chanjar.weixin.enterprise.bean; | |||
import me.chanjar.weixin.enterprise.api.WxConsts; | |||
import me.chanjar.weixin.enterprise.api.WxCpConsts; | |||
import org.testng.Assert; | |||
import org.testng.annotations.Test; | |||
@@ -57,7 +57,7 @@ public class WxCpXmlMessageTest { | |||
Assert.assertEquals(wxMessage.getToUserName(), "toUser"); | |||
Assert.assertEquals(wxMessage.getFromUserName(), "fromUser"); | |||
Assert.assertEquals(wxMessage.getCreateTime(), new Long(1348831860l)); | |||
Assert.assertEquals(wxMessage.getMsgType(), WxConsts.XML_MSG_TEXT); | |||
Assert.assertEquals(wxMessage.getMsgType(), WxCpConsts.XML_MSG_TEXT); | |||
Assert.assertEquals(wxMessage.getContent(), "this is a test"); | |||
Assert.assertEquals(wxMessage.getMsgId(), new Long(1234567890123456l)); | |||
Assert.assertEquals(wxMessage.getPicUrl(), "this is a url"); | |||
@@ -1,74 +0,0 @@ | |||
package me.chanjar.weixin.enterprise.bean; | |||
import org.testng.Assert; | |||
import org.testng.annotations.Test; | |||
@Test | |||
public class WxCpXmlOutMusicMessageTest { | |||
public void test() { | |||
WxCpXmlOutMusicMessage m = new WxCpXmlOutMusicMessage(); | |||
m.setTitle("title"); | |||
m.setDescription("ddfff"); | |||
m.setHqMusicUrl("hQMusicUrl"); | |||
m.setMusicUrl("musicUrl"); | |||
m.setThumbMediaId("thumbMediaId"); | |||
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[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", "")); | |||
} | |||
public void testBuild() { | |||
WxCpXmlOutMusicMessage m = WxCpXmlOutMessage.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>", "") | |||
); | |||
} | |||
} |