mirror of
https://gitee.com/binary/weixin-java-tools.git
synced 2026-03-10 00:13:40 +08:00
重构bean和builder的包结构
This commit is contained in:
@@ -1,20 +0,0 @@
|
||||
package me.chanjar.weixin.mp.bean.custombuilder;
|
||||
|
||||
import me.chanjar.weixin.mp.bean.kefu.WxMpKefuMessage;
|
||||
|
||||
public class BaseBuilder<T> {
|
||||
protected String msgType;
|
||||
protected String toUser;
|
||||
|
||||
public T toUser(String toUser) {
|
||||
this.toUser = toUser;
|
||||
return (T) this;
|
||||
}
|
||||
|
||||
public WxMpKefuMessage build() {
|
||||
WxMpKefuMessage m = new WxMpKefuMessage();
|
||||
m.setMsgType(this.msgType);
|
||||
m.setToUser(this.toUser);
|
||||
return m;
|
||||
}
|
||||
}
|
||||
@@ -1,32 +0,0 @@
|
||||
package me.chanjar.weixin.mp.bean.custombuilder;
|
||||
|
||||
import me.chanjar.weixin.common.api.WxConsts;
|
||||
import me.chanjar.weixin.mp.bean.kefu.WxMpKefuMessage;
|
||||
|
||||
/**
|
||||
* 获得消息builder
|
||||
* <pre>
|
||||
* 用法: WxMpKefuMessage m = WxMpKefuMessage.IMAGE().mediaId(...).toUser(...).build();
|
||||
* </pre>
|
||||
* @author chanjarster
|
||||
*
|
||||
*/
|
||||
public final class ImageBuilder extends BaseBuilder<ImageBuilder> {
|
||||
private String mediaId;
|
||||
|
||||
public ImageBuilder() {
|
||||
this.msgType = WxConsts.CUSTOM_MSG_IMAGE;
|
||||
}
|
||||
|
||||
public ImageBuilder mediaId(String media_id) {
|
||||
this.mediaId = media_id;
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public WxMpKefuMessage build() {
|
||||
WxMpKefuMessage m = super.build();
|
||||
m.setMediaId(this.mediaId);
|
||||
return m;
|
||||
}
|
||||
}
|
||||
@@ -1,33 +0,0 @@
|
||||
package me.chanjar.weixin.mp.bean.custombuilder;
|
||||
|
||||
import me.chanjar.weixin.common.api.WxConsts;
|
||||
import me.chanjar.weixin.mp.bean.kefu.WxMpKefuMessage;
|
||||
|
||||
/**
|
||||
* 图文消息builder
|
||||
* <pre>
|
||||
* 用法:
|
||||
* WxMpKefuMessage m = WxMpKefuMessage.NEWS().mediaId("xxxxx").toUser(...).build();
|
||||
* </pre>
|
||||
* @author Binary Wang
|
||||
*
|
||||
*/
|
||||
public final class MpNewsBuilder extends BaseBuilder<MpNewsBuilder> {
|
||||
private String mediaId;
|
||||
|
||||
public MpNewsBuilder() {
|
||||
this.msgType = WxConsts.CUSTOM_MSG_MPNEWS;
|
||||
}
|
||||
|
||||
public MpNewsBuilder mediaId(String mediaId) {
|
||||
this.mediaId = mediaId;
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public WxMpKefuMessage build() {
|
||||
WxMpKefuMessage m = super.build();
|
||||
m.setMpNewsMediaId(this.mediaId);
|
||||
return m;
|
||||
}
|
||||
}
|
||||
@@ -1,65 +0,0 @@
|
||||
package me.chanjar.weixin.mp.bean.custombuilder;
|
||||
|
||||
import me.chanjar.weixin.common.api.WxConsts;
|
||||
import me.chanjar.weixin.mp.bean.kefu.WxMpKefuMessage;
|
||||
|
||||
/**
|
||||
* 音乐消息builder
|
||||
* <pre>
|
||||
* 用法: WxMpKefuMessage m = WxMpKefuMessage.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;
|
||||
}
|
||||
|
||||
@Override
|
||||
public WxMpKefuMessage build() {
|
||||
WxMpKefuMessage m = super.build();
|
||||
m.setMusicUrl(this.musicUrl);
|
||||
m.setHqMusicUrl(this.hqMusicUrl);
|
||||
m.setTitle(this.title);
|
||||
m.setDescription(this.description);
|
||||
m.setThumbMediaId(this.thumbMediaId);
|
||||
return m;
|
||||
}
|
||||
}
|
||||
@@ -1,37 +0,0 @@
|
||||
package me.chanjar.weixin.mp.bean.custombuilder;
|
||||
|
||||
import me.chanjar.weixin.common.api.WxConsts;
|
||||
import me.chanjar.weixin.mp.bean.kefu.WxMpKefuMessage;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 图文消息builder
|
||||
* <pre>
|
||||
* 用法:
|
||||
* WxMpKefuMessage m = WxMpKefuMessage.NEWS().addArticle(article).toUser(...).build();
|
||||
* </pre>
|
||||
* @author chanjarster
|
||||
*
|
||||
*/
|
||||
public final class NewsBuilder extends BaseBuilder<NewsBuilder> {
|
||||
|
||||
private List<WxMpKefuMessage.WxArticle> articles = new ArrayList<>();
|
||||
|
||||
public NewsBuilder() {
|
||||
this.msgType = WxConsts.CUSTOM_MSG_NEWS;
|
||||
}
|
||||
|
||||
public NewsBuilder addArticle(WxMpKefuMessage.WxArticle article) {
|
||||
this.articles.add(article);
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public WxMpKefuMessage build() {
|
||||
WxMpKefuMessage m = super.build();
|
||||
m.setArticles(this.articles);
|
||||
return m;
|
||||
}
|
||||
}
|
||||
@@ -1,32 +0,0 @@
|
||||
package me.chanjar.weixin.mp.bean.custombuilder;
|
||||
|
||||
import me.chanjar.weixin.common.api.WxConsts;
|
||||
import me.chanjar.weixin.mp.bean.kefu.WxMpKefuMessage;
|
||||
|
||||
/**
|
||||
* 文本消息builder
|
||||
* <pre>
|
||||
* 用法: WxMpKefuMessage m = WxMpKefuMessage.TEXT().content(...).toUser(...).build();
|
||||
* </pre>
|
||||
* @author chanjarster
|
||||
*
|
||||
*/
|
||||
public final class TextBuilder extends BaseBuilder<TextBuilder> {
|
||||
private String content;
|
||||
|
||||
public TextBuilder() {
|
||||
this.msgType = WxConsts.CUSTOM_MSG_TEXT;
|
||||
}
|
||||
|
||||
public TextBuilder content(String content) {
|
||||
this.content = content;
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public WxMpKefuMessage build() {
|
||||
WxMpKefuMessage m = super.build();
|
||||
m.setContent(this.content);
|
||||
return m;
|
||||
}
|
||||
}
|
||||
@@ -1,59 +0,0 @@
|
||||
package me.chanjar.weixin.mp.bean.custombuilder;
|
||||
|
||||
import me.chanjar.weixin.common.api.WxConsts;
|
||||
import me.chanjar.weixin.mp.bean.kefu.WxMpKefuMessage;
|
||||
|
||||
/**
|
||||
* 视频消息builder
|
||||
* <pre>
|
||||
* 用法: WxMpKefuMessage m = WxMpKefuMessage.VOICE()
|
||||
* .mediaId(...)
|
||||
* .title(...)
|
||||
* .thumbMediaId(..)
|
||||
* .description(..)
|
||||
* .toUser(...)
|
||||
* .build();
|
||||
* </pre>
|
||||
* @author chanjarster
|
||||
*
|
||||
*/
|
||||
public final class VideoBuilder extends BaseBuilder<VideoBuilder> {
|
||||
private String mediaId;
|
||||
private String title;
|
||||
private String description;
|
||||
private String thumbMediaId;
|
||||
|
||||
public VideoBuilder() {
|
||||
this.msgType = WxConsts.CUSTOM_MSG_VIDEO;
|
||||
}
|
||||
|
||||
public VideoBuilder mediaId(String mediaId) {
|
||||
this.mediaId = mediaId;
|
||||
return this;
|
||||
}
|
||||
|
||||
public VideoBuilder title(String title) {
|
||||
this.title = title;
|
||||
return this;
|
||||
}
|
||||
|
||||
public VideoBuilder description(String description) {
|
||||
this.description = description;
|
||||
return this;
|
||||
}
|
||||
|
||||
public VideoBuilder thumbMediaId(String thumb_media_id) {
|
||||
this.thumbMediaId = thumb_media_id;
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public WxMpKefuMessage build() {
|
||||
WxMpKefuMessage m = super.build();
|
||||
m.setMediaId(this.mediaId);
|
||||
m.setTitle(this.title);
|
||||
m.setDescription(this.description);
|
||||
m.setThumbMediaId(this.thumbMediaId);
|
||||
return m;
|
||||
}
|
||||
}
|
||||
@@ -1,32 +0,0 @@
|
||||
package me.chanjar.weixin.mp.bean.custombuilder;
|
||||
|
||||
import me.chanjar.weixin.common.api.WxConsts;
|
||||
import me.chanjar.weixin.mp.bean.kefu.WxMpKefuMessage;
|
||||
|
||||
/**
|
||||
* 语音消息builder
|
||||
* <pre>
|
||||
* 用法: WxMpKefuMessage m = WxMpKefuMessage.VOICE().mediaId(...).toUser(...).build();
|
||||
* </pre>
|
||||
* @author chanjarster
|
||||
*
|
||||
*/
|
||||
public final class VoiceBuilder extends BaseBuilder<VoiceBuilder> {
|
||||
private String mediaId;
|
||||
|
||||
public VoiceBuilder() {
|
||||
this.msgType = WxConsts.CUSTOM_MSG_VOICE;
|
||||
}
|
||||
|
||||
public VoiceBuilder mediaId(String media_id) {
|
||||
this.mediaId = media_id;
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public WxMpKefuMessage build() {
|
||||
WxMpKefuMessage m = super.build();
|
||||
m.setMediaId(this.mediaId);
|
||||
return m;
|
||||
}
|
||||
}
|
||||
@@ -1,32 +0,0 @@
|
||||
package me.chanjar.weixin.mp.bean.custombuilder;
|
||||
|
||||
import me.chanjar.weixin.common.api.WxConsts;
|
||||
import me.chanjar.weixin.mp.bean.kefu.WxMpKefuMessage;
|
||||
|
||||
/**
|
||||
* 卡券消息builder
|
||||
* <pre>
|
||||
* 用法: WxMpKefuMessage m = WxMpKefuMessage.WXCARD().cardId(...).toUser(...).build();
|
||||
* </pre>
|
||||
* @author mgcnrx11
|
||||
*
|
||||
*/
|
||||
public final class WxCardBuilder extends BaseBuilder<WxCardBuilder> {
|
||||
private String cardId;
|
||||
|
||||
public WxCardBuilder() {
|
||||
this.msgType = WxConsts.CUSTOM_MSG_WXCARD;
|
||||
}
|
||||
|
||||
public WxCardBuilder cardId(String cardId) {
|
||||
this.cardId = cardId;
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public WxMpKefuMessage build() {
|
||||
WxMpKefuMessage m = super.build();
|
||||
m.setCardId(this.cardId);
|
||||
return m;
|
||||
}
|
||||
}
|
||||
@@ -4,14 +4,14 @@ import java.io.Serializable;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import me.chanjar.weixin.mp.bean.custombuilder.ImageBuilder;
|
||||
import me.chanjar.weixin.mp.bean.custombuilder.MpNewsBuilder;
|
||||
import me.chanjar.weixin.mp.bean.custombuilder.MusicBuilder;
|
||||
import me.chanjar.weixin.mp.bean.custombuilder.NewsBuilder;
|
||||
import me.chanjar.weixin.mp.bean.custombuilder.TextBuilder;
|
||||
import me.chanjar.weixin.mp.bean.custombuilder.VideoBuilder;
|
||||
import me.chanjar.weixin.mp.bean.custombuilder.VoiceBuilder;
|
||||
import me.chanjar.weixin.mp.bean.custombuilder.WxCardBuilder;
|
||||
import me.chanjar.weixin.mp.builder.kefu.ImageBuilder;
|
||||
import me.chanjar.weixin.mp.builder.kefu.MpNewsBuilder;
|
||||
import me.chanjar.weixin.mp.builder.kefu.MusicBuilder;
|
||||
import me.chanjar.weixin.mp.builder.kefu.NewsBuilder;
|
||||
import me.chanjar.weixin.mp.builder.kefu.TextBuilder;
|
||||
import me.chanjar.weixin.mp.builder.kefu.VideoBuilder;
|
||||
import me.chanjar.weixin.mp.builder.kefu.VoiceBuilder;
|
||||
import me.chanjar.weixin.mp.builder.kefu.WxCardBuilder;
|
||||
import me.chanjar.weixin.mp.util.json.WxMpGsonBuilder;
|
||||
|
||||
/**
|
||||
|
||||
@@ -1,4 +1,14 @@
|
||||
package me.chanjar.weixin.mp.bean;
|
||||
package me.chanjar.weixin.mp.bean.message;
|
||||
|
||||
import com.thoughtworks.xstream.annotations.XStreamAlias;
|
||||
import com.thoughtworks.xstream.annotations.XStreamConverter;
|
||||
import me.chanjar.weixin.common.util.xml.XStreamCDataConverter;
|
||||
import me.chanjar.weixin.mp.api.WxMpConfigStorage;
|
||||
import me.chanjar.weixin.mp.util.crypto.WxMpCryptUtil;
|
||||
import me.chanjar.weixin.mp.util.xml.XStreamTransformer;
|
||||
import org.apache.commons.io.IOUtils;
|
||||
import org.apache.commons.lang3.builder.ToStringBuilder;
|
||||
import org.apache.commons.lang3.builder.ToStringStyle;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
@@ -6,18 +16,6 @@ import java.io.Serializable;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import org.apache.commons.io.IOUtils;
|
||||
import org.apache.commons.lang3.builder.ToStringBuilder;
|
||||
import org.apache.commons.lang3.builder.ToStringStyle;
|
||||
|
||||
import com.thoughtworks.xstream.annotations.XStreamAlias;
|
||||
import com.thoughtworks.xstream.annotations.XStreamConverter;
|
||||
|
||||
import me.chanjar.weixin.common.util.xml.XStreamCDataConverter;
|
||||
import me.chanjar.weixin.mp.api.WxMpConfigStorage;
|
||||
import me.chanjar.weixin.mp.util.crypto.WxMpCryptUtil;
|
||||
import me.chanjar.weixin.mp.util.xml.XStreamTransformer;
|
||||
|
||||
/**
|
||||
* <pre>
|
||||
* 微信推送过来的消息,xml格式
|
||||
@@ -1,4 +1,4 @@
|
||||
package me.chanjar.weixin.mp.bean;
|
||||
package me.chanjar.weixin.mp.bean.message;
|
||||
|
||||
import com.thoughtworks.xstream.annotations.XStreamAlias;
|
||||
import com.thoughtworks.xstream.annotations.XStreamConverter;
|
||||
@@ -9,7 +9,7 @@ import me.chanjar.weixin.common.util.xml.XStreamMediaIdConverter;
|
||||
public class WxMpXmlOutImageMessage extends WxMpXmlOutMessage {
|
||||
|
||||
/**
|
||||
*
|
||||
*
|
||||
*/
|
||||
private static final long serialVersionUID = -2684778597067990723L;
|
||||
@XStreamAlias("Image")
|
||||
@@ -1,10 +1,10 @@
|
||||
package me.chanjar.weixin.mp.bean;
|
||||
package me.chanjar.weixin.mp.bean.message;
|
||||
|
||||
import com.thoughtworks.xstream.annotations.XStreamAlias;
|
||||
import com.thoughtworks.xstream.annotations.XStreamConverter;
|
||||
import me.chanjar.weixin.common.util.xml.XStreamCDataConverter;
|
||||
import me.chanjar.weixin.mp.api.WxMpConfigStorage;
|
||||
import me.chanjar.weixin.mp.bean.outxmlbuilder.*;
|
||||
import me.chanjar.weixin.mp.builder.outxml.*;
|
||||
import me.chanjar.weixin.mp.util.crypto.WxMpCryptUtil;
|
||||
import me.chanjar.weixin.mp.util.xml.XStreamTransformer;
|
||||
|
||||
@@ -18,14 +18,14 @@ public abstract class WxMpXmlOutMessage implements Serializable {
|
||||
@XStreamAlias("ToUserName")
|
||||
@XStreamConverter(value=XStreamCDataConverter.class)
|
||||
protected String toUserName;
|
||||
|
||||
|
||||
@XStreamAlias("FromUserName")
|
||||
@XStreamConverter(value=XStreamCDataConverter.class)
|
||||
protected String fromUserName;
|
||||
|
||||
|
||||
@XStreamAlias("CreateTime")
|
||||
protected Long createTime;
|
||||
|
||||
|
||||
@XStreamAlias("MsgType")
|
||||
@XStreamConverter(value=XStreamCDataConverter.class)
|
||||
protected String msgType;
|
||||
@@ -61,7 +61,7 @@ public abstract class WxMpXmlOutMessage implements Serializable {
|
||||
public void setMsgType(String msgType) {
|
||||
this.msgType = msgType;
|
||||
}
|
||||
|
||||
|
||||
public String toXml() {
|
||||
return XStreamTransformer.toXml((Class<WxMpXmlOutMessage>) this.getClass(), this);
|
||||
}
|
||||
@@ -95,28 +95,28 @@ public abstract class WxMpXmlOutMessage implements Serializable {
|
||||
public static VoiceBuilder VOICE() {
|
||||
return new VoiceBuilder();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 获得视频消息builder
|
||||
*/
|
||||
public static VideoBuilder VIDEO() {
|
||||
return new VideoBuilder();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 获得音乐消息builder
|
||||
*/
|
||||
public static MusicBuilder MUSIC() {
|
||||
return new MusicBuilder();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 获得图文消息builder
|
||||
*/
|
||||
public static NewsBuilder NEWS() {
|
||||
return new NewsBuilder();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 获得客服消息builder
|
||||
*/
|
||||
@@ -1,4 +1,4 @@
|
||||
package me.chanjar.weixin.mp.bean;
|
||||
package me.chanjar.weixin.mp.bean.message;
|
||||
|
||||
import com.thoughtworks.xstream.annotations.XStreamAlias;
|
||||
import com.thoughtworks.xstream.annotations.XStreamConverter;
|
||||
@@ -9,7 +9,7 @@ import me.chanjar.weixin.common.util.xml.XStreamCDataConverter;
|
||||
public class WxMpXmlOutMusicMessage extends WxMpXmlOutMessage {
|
||||
|
||||
/**
|
||||
*
|
||||
*
|
||||
*/
|
||||
private static final long serialVersionUID = -4159937804975448945L;
|
||||
@XStreamAlias("Music")
|
||||
@@ -34,7 +34,7 @@ public class WxMpXmlOutMusicMessage extends WxMpXmlOutMessage {
|
||||
public void setDescription(String description) {
|
||||
this.music.setDescription(description);
|
||||
}
|
||||
|
||||
|
||||
public String getThumbMediaId() {
|
||||
return this.music.getThumbMediaId();
|
||||
}
|
||||
@@ -58,10 +58,10 @@ public class WxMpXmlOutMusicMessage extends WxMpXmlOutMessage {
|
||||
public void setHqMusicUrl(String hqMusicUrl) {
|
||||
this.music.setHqMusicUrl(hqMusicUrl);
|
||||
}
|
||||
|
||||
|
||||
@XStreamAlias("Music")
|
||||
public static class Music {
|
||||
|
||||
|
||||
@XStreamAlias("Title")
|
||||
@XStreamConverter(value=XStreamCDataConverter.class)
|
||||
private String title;
|
||||
@@ -73,15 +73,15 @@ public class WxMpXmlOutMusicMessage extends WxMpXmlOutMessage {
|
||||
@XStreamAlias("ThumbMediaId")
|
||||
@XStreamConverter(value=XStreamCDataConverter.class)
|
||||
private String thumbMediaId;
|
||||
|
||||
|
||||
@XStreamAlias("MusicUrl")
|
||||
@XStreamConverter(value=XStreamCDataConverter.class)
|
||||
private String musicUrl;
|
||||
|
||||
|
||||
@XStreamAlias("HQMusicUrl")
|
||||
@XStreamConverter(value=XStreamCDataConverter.class)
|
||||
private String hqMusicUrl;
|
||||
|
||||
|
||||
public String getTitle() {
|
||||
return this.title;
|
||||
}
|
||||
@@ -121,7 +121,7 @@ public class WxMpXmlOutMusicMessage extends WxMpXmlOutMessage {
|
||||
public void setHqMusicUrl(String hqMusicUrl) {
|
||||
this.hqMusicUrl = hqMusicUrl;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,4 +1,4 @@
|
||||
package me.chanjar.weixin.mp.bean;
|
||||
package me.chanjar.weixin.mp.bean.message;
|
||||
|
||||
import com.thoughtworks.xstream.annotations.XStreamAlias;
|
||||
import com.thoughtworks.xstream.annotations.XStreamConverter;
|
||||
@@ -12,16 +12,16 @@ import java.util.List;
|
||||
public class WxMpXmlOutNewsMessage extends WxMpXmlOutMessage {
|
||||
|
||||
/**
|
||||
*
|
||||
*
|
||||
*/
|
||||
private static final long serialVersionUID = -4604402850905714772L;
|
||||
|
||||
@XStreamAlias("ArticleCount")
|
||||
protected int articleCount;
|
||||
|
||||
|
||||
@XStreamAlias("Articles")
|
||||
protected final List<Item> articles = new ArrayList<>();
|
||||
|
||||
|
||||
public WxMpXmlOutNewsMessage() {
|
||||
this.msgType = WxConsts.XML_MSG_NEWS;
|
||||
}
|
||||
@@ -34,15 +34,15 @@ public class WxMpXmlOutNewsMessage extends WxMpXmlOutMessage {
|
||||
this.articles.add(item);
|
||||
this.articleCount = this.articles.size();
|
||||
}
|
||||
|
||||
|
||||
public List<Item> getArticles() {
|
||||
return this.articles;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
@XStreamAlias("item")
|
||||
public static class Item {
|
||||
|
||||
|
||||
@XStreamAlias("Title")
|
||||
@XStreamConverter(value=XStreamCDataConverter.class)
|
||||
private String Title;
|
||||
@@ -54,11 +54,11 @@ public class WxMpXmlOutNewsMessage extends WxMpXmlOutMessage {
|
||||
@XStreamAlias("PicUrl")
|
||||
@XStreamConverter(value=XStreamCDataConverter.class)
|
||||
private String PicUrl;
|
||||
|
||||
|
||||
@XStreamAlias("Url")
|
||||
@XStreamConverter(value=XStreamCDataConverter.class)
|
||||
private String Url;
|
||||
|
||||
|
||||
public String getTitle() {
|
||||
return this.Title;
|
||||
}
|
||||
@@ -1,4 +1,4 @@
|
||||
package me.chanjar.weixin.mp.bean;
|
||||
package me.chanjar.weixin.mp.bean.message;
|
||||
|
||||
import com.thoughtworks.xstream.annotations.XStreamAlias;
|
||||
import com.thoughtworks.xstream.annotations.XStreamConverter;
|
||||
@@ -7,9 +7,9 @@ import me.chanjar.weixin.common.util.xml.XStreamCDataConverter;
|
||||
|
||||
@XStreamAlias("xml")
|
||||
public class WxMpXmlOutTextMessage extends WxMpXmlOutMessage {
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
*
|
||||
*/
|
||||
private static final long serialVersionUID = -3972786455288763361L;
|
||||
@XStreamAlias("Content")
|
||||
@@ -19,7 +19,7 @@ public class WxMpXmlOutTextMessage extends WxMpXmlOutMessage {
|
||||
public WxMpXmlOutTextMessage() {
|
||||
this.msgType = WxConsts.XML_MSG_TEXT;
|
||||
}
|
||||
|
||||
|
||||
public String getContent() {
|
||||
return this.content;
|
||||
}
|
||||
@@ -28,5 +28,5 @@ public class WxMpXmlOutTextMessage extends WxMpXmlOutMessage {
|
||||
this.content = content;
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
@@ -1,4 +1,4 @@
|
||||
package me.chanjar.weixin.mp.bean;
|
||||
package me.chanjar.weixin.mp.bean.message;
|
||||
|
||||
import com.thoughtworks.xstream.annotations.XStreamAlias;
|
||||
import com.thoughtworks.xstream.annotations.XStreamConverter;
|
||||
@@ -1,4 +1,4 @@
|
||||
package me.chanjar.weixin.mp.bean;
|
||||
package me.chanjar.weixin.mp.bean.message;
|
||||
|
||||
import com.thoughtworks.xstream.annotations.XStreamAlias;
|
||||
import com.thoughtworks.xstream.annotations.XStreamConverter;
|
||||
@@ -9,7 +9,7 @@ import me.chanjar.weixin.common.util.xml.XStreamCDataConverter;
|
||||
public class WxMpXmlOutVideoMessage extends WxMpXmlOutMessage {
|
||||
|
||||
/**
|
||||
*
|
||||
*
|
||||
*/
|
||||
private static final long serialVersionUID = 1745902309380113978L;
|
||||
@XStreamAlias("Video")
|
||||
@@ -42,11 +42,11 @@ public class WxMpXmlOutVideoMessage extends WxMpXmlOutMessage {
|
||||
public void setDescription(String description) {
|
||||
this.video.setDescription(description);
|
||||
}
|
||||
|
||||
|
||||
|
||||
@XStreamAlias("Video")
|
||||
public static class Video {
|
||||
|
||||
|
||||
@XStreamAlias("MediaId")
|
||||
@XStreamConverter(value=XStreamCDataConverter.class)
|
||||
private String mediaId;
|
||||
@@ -82,7 +82,7 @@ public class WxMpXmlOutVideoMessage extends WxMpXmlOutMessage {
|
||||
public void setDescription(String description) {
|
||||
this.description = description;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,4 +1,4 @@
|
||||
package me.chanjar.weixin.mp.bean;
|
||||
package me.chanjar.weixin.mp.bean.message;
|
||||
|
||||
import com.thoughtworks.xstream.annotations.XStreamAlias;
|
||||
import com.thoughtworks.xstream.annotations.XStreamConverter;
|
||||
@@ -9,7 +9,7 @@ import me.chanjar.weixin.common.util.xml.XStreamMediaIdConverter;
|
||||
public class WxMpXmlOutVoiceMessage extends WxMpXmlOutMessage {
|
||||
|
||||
/**
|
||||
*
|
||||
*
|
||||
*/
|
||||
private static final long serialVersionUID = 240367390249860551L;
|
||||
@XStreamAlias("Voice")
|
||||
@@ -1,29 +0,0 @@
|
||||
package me.chanjar.weixin.mp.bean.outxmlbuilder;
|
||||
|
||||
import me.chanjar.weixin.mp.bean.WxMpXmlOutMessage;
|
||||
|
||||
public abstract class BaseBuilder<BuilderType, ValueType> {
|
||||
|
||||
protected String toUserName;
|
||||
|
||||
protected String fromUserName;
|
||||
|
||||
public BuilderType toUser(String touser) {
|
||||
this.toUserName = touser;
|
||||
return (BuilderType) this;
|
||||
}
|
||||
|
||||
public BuilderType fromUser(String fromusername) {
|
||||
this.fromUserName = fromusername;
|
||||
return (BuilderType) this;
|
||||
}
|
||||
|
||||
public abstract ValueType build();
|
||||
|
||||
public void setCommon(WxMpXmlOutMessage m) {
|
||||
m.setToUserName(this.toUserName);
|
||||
m.setFromUserName(this.fromUserName);
|
||||
m.setCreateTime(System.currentTimeMillis() / 1000l);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,26 +0,0 @@
|
||||
package me.chanjar.weixin.mp.bean.outxmlbuilder;
|
||||
|
||||
import me.chanjar.weixin.mp.bean.WxMpXmlOutImageMessage;
|
||||
|
||||
/**
|
||||
* 图片消息builder
|
||||
* @author chanjarster
|
||||
*/
|
||||
public final class ImageBuilder extends BaseBuilder<ImageBuilder, WxMpXmlOutImageMessage> {
|
||||
|
||||
private String mediaId;
|
||||
|
||||
public ImageBuilder mediaId(String media_id) {
|
||||
this.mediaId = media_id;
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public WxMpXmlOutImageMessage build() {
|
||||
WxMpXmlOutImageMessage m = new WxMpXmlOutImageMessage();
|
||||
setCommon(m);
|
||||
m.setMediaId(this.mediaId);
|
||||
return m;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,55 +0,0 @@
|
||||
package me.chanjar.weixin.mp.bean.outxmlbuilder;
|
||||
|
||||
import me.chanjar.weixin.mp.bean.WxMpXmlOutMusicMessage;
|
||||
|
||||
/**
|
||||
* 音乐消息builder
|
||||
*
|
||||
* @author chanjarster
|
||||
*/
|
||||
public final class MusicBuilder extends BaseBuilder<MusicBuilder, WxMpXmlOutMusicMessage> {
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
@Override
|
||||
public WxMpXmlOutMusicMessage build() {
|
||||
WxMpXmlOutMusicMessage m = new WxMpXmlOutMusicMessage();
|
||||
setCommon(m);
|
||||
m.setTitle(this.title);
|
||||
m.setDescription(this.description);
|
||||
m.setHqMusicUrl(this.hqMusicUrl);
|
||||
m.setMusicUrl(this.musicUrl);
|
||||
m.setThumbMediaId(this.thumbMediaId);
|
||||
return m;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,31 +0,0 @@
|
||||
package me.chanjar.weixin.mp.bean.outxmlbuilder;
|
||||
|
||||
import me.chanjar.weixin.mp.bean.WxMpXmlOutNewsMessage;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 图文消息builder
|
||||
* @author chanjarster
|
||||
*/
|
||||
public final class NewsBuilder extends BaseBuilder<NewsBuilder, WxMpXmlOutNewsMessage> {
|
||||
|
||||
protected final List<WxMpXmlOutNewsMessage.Item> articles = new ArrayList<>();
|
||||
|
||||
public NewsBuilder addArticle(WxMpXmlOutNewsMessage.Item item) {
|
||||
this.articles.add(item);
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public WxMpXmlOutNewsMessage build() {
|
||||
WxMpXmlOutNewsMessage m = new WxMpXmlOutNewsMessage();
|
||||
for(WxMpXmlOutNewsMessage.Item item : this.articles) {
|
||||
m.addArticle(item);
|
||||
}
|
||||
setCommon(m);
|
||||
return m;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,25 +0,0 @@
|
||||
package me.chanjar.weixin.mp.bean.outxmlbuilder;
|
||||
|
||||
import me.chanjar.weixin.mp.bean.WxMpXmlOutTextMessage;
|
||||
|
||||
/**
|
||||
* 文本消息builder
|
||||
* @author chanjarster
|
||||
*
|
||||
*/
|
||||
public final class TextBuilder extends BaseBuilder<TextBuilder, WxMpXmlOutTextMessage> {
|
||||
private String content;
|
||||
|
||||
public TextBuilder content(String content) {
|
||||
this.content = content;
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public WxMpXmlOutTextMessage build() {
|
||||
WxMpXmlOutTextMessage m = new WxMpXmlOutTextMessage();
|
||||
setCommon(m);
|
||||
m.setContent(this.content);
|
||||
return m;
|
||||
}
|
||||
}
|
||||
@@ -1,33 +0,0 @@
|
||||
package me.chanjar.weixin.mp.bean.outxmlbuilder;
|
||||
|
||||
import me.chanjar.weixin.common.util.StringUtils;
|
||||
import me.chanjar.weixin.mp.bean.WxMpXmlOutTransferKefuMessage;
|
||||
|
||||
/**
|
||||
* 客服消息builder
|
||||
* <pre>
|
||||
* 用法: WxMpKefuMessage m = WxMpXmlOutMessage.TRANSFER_CUSTOMER_SERVICE().content(...).toUser(...).build();
|
||||
* </pre>
|
||||
*
|
||||
* @author chanjarster
|
||||
*/
|
||||
public final class TransferCustomerServiceBuilder extends BaseBuilder<TransferCustomerServiceBuilder, WxMpXmlOutTransferKefuMessage> {
|
||||
private String kfAccount;
|
||||
|
||||
public TransferCustomerServiceBuilder kfAccount(String kf) {
|
||||
this.kfAccount = kf;
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public WxMpXmlOutTransferKefuMessage build() {
|
||||
WxMpXmlOutTransferKefuMessage m = new WxMpXmlOutTransferKefuMessage();
|
||||
setCommon(m);
|
||||
if(StringUtils.isNotBlank(this.kfAccount)){
|
||||
WxMpXmlOutTransferKefuMessage.TransInfo transInfo = new WxMpXmlOutTransferKefuMessage.TransInfo();
|
||||
transInfo.setKfAccount(this.kfAccount);
|
||||
m.setTransInfo(transInfo);
|
||||
}
|
||||
return m;
|
||||
}
|
||||
}
|
||||
@@ -1,39 +0,0 @@
|
||||
package me.chanjar.weixin.mp.bean.outxmlbuilder;
|
||||
|
||||
import me.chanjar.weixin.mp.bean.WxMpXmlOutVideoMessage;
|
||||
|
||||
/**
|
||||
* 视频消息builder
|
||||
* @author chanjarster
|
||||
*
|
||||
*/
|
||||
public final class VideoBuilder extends BaseBuilder<VideoBuilder, WxMpXmlOutVideoMessage> {
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
@Override
|
||||
public WxMpXmlOutVideoMessage build() {
|
||||
WxMpXmlOutVideoMessage m = new WxMpXmlOutVideoMessage();
|
||||
setCommon(m);
|
||||
m.setTitle(this.title);
|
||||
m.setDescription(this.description);
|
||||
m.setMediaId(this.mediaId);
|
||||
return m;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,26 +0,0 @@
|
||||
package me.chanjar.weixin.mp.bean.outxmlbuilder;
|
||||
|
||||
import me.chanjar.weixin.mp.bean.WxMpXmlOutVoiceMessage;
|
||||
|
||||
/**
|
||||
* 语音消息builder
|
||||
* @author chanjarster
|
||||
*/
|
||||
public final class VoiceBuilder extends BaseBuilder<VoiceBuilder, WxMpXmlOutVoiceMessage> {
|
||||
|
||||
private String mediaId;
|
||||
|
||||
public VoiceBuilder mediaId(String mediaId) {
|
||||
this.mediaId = mediaId;
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public WxMpXmlOutVoiceMessage build() {
|
||||
WxMpXmlOutVoiceMessage m = new WxMpXmlOutVoiceMessage();
|
||||
setCommon(m);
|
||||
m.setMediaId(this.mediaId);
|
||||
return m;
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user