mirror of
https://gitee.com/binary/weixin-java-tools.git
synced 2026-02-16 13:26:23 +08:00
重构WxConsts类,对所有常量进行分类整理,便于阅读使用
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
package me.chanjar.weixin.cp.bean;
|
||||
|
||||
import me.chanjar.weixin.common.api.WxConsts;
|
||||
import me.chanjar.weixin.cp.bean.article.MpnewsArticle;
|
||||
import me.chanjar.weixin.cp.bean.article.NewArticle;
|
||||
import me.chanjar.weixin.cp.bean.messagebuilder.*;
|
||||
@@ -137,13 +138,13 @@ public class WxCpMessage implements Serializable {
|
||||
/**
|
||||
* <pre>
|
||||
* 请使用
|
||||
* {@link me.chanjar.weixin.common.api.WxConsts#CUSTOM_MSG_TEXT}
|
||||
* {@link me.chanjar.weixin.common.api.WxConsts#CUSTOM_MSG_IMAGE}
|
||||
* {@link me.chanjar.weixin.common.api.WxConsts#CUSTOM_MSG_VOICE}
|
||||
* {@link me.chanjar.weixin.common.api.WxConsts#CUSTOM_MSG_MUSIC}
|
||||
* {@link me.chanjar.weixin.common.api.WxConsts#CUSTOM_MSG_VIDEO}
|
||||
* {@link me.chanjar.weixin.common.api.WxConsts#CUSTOM_MSG_NEWS}
|
||||
* {@link me.chanjar.weixin.common.api.WxConsts#CUSTOM_MSG_MPNEWS}
|
||||
* {@link WxConsts.KefuMsgType#TEXT}
|
||||
* {@link WxConsts.KefuMsgType#IMAGE}
|
||||
* {@link WxConsts.KefuMsgType#VOICE}
|
||||
* {@link WxConsts.KefuMsgType#MUSIC}
|
||||
* {@link WxConsts.KefuMsgType#VIDEO}
|
||||
* {@link WxConsts.KefuMsgType#NEWS}
|
||||
* {@link WxConsts.KefuMsgType#MPNEWS}
|
||||
* </pre>
|
||||
*
|
||||
* @param msgType 消息类型
|
||||
|
||||
@@ -2,6 +2,7 @@ package me.chanjar.weixin.cp.bean;
|
||||
|
||||
import com.thoughtworks.xstream.annotations.XStreamAlias;
|
||||
import com.thoughtworks.xstream.annotations.XStreamConverter;
|
||||
import me.chanjar.weixin.common.api.WxConsts;
|
||||
import me.chanjar.weixin.common.util.ToStringUtils;
|
||||
import me.chanjar.weixin.common.util.xml.XStreamCDataConverter;
|
||||
import me.chanjar.weixin.cp.config.WxCpConfigStorage;
|
||||
@@ -224,13 +225,13 @@ public class WxCpXmlMessage implements Serializable {
|
||||
/**
|
||||
* <pre>
|
||||
* 当接受用户消息时,可能会获得以下值:
|
||||
* {@link me.chanjar.weixin.common.api.WxConsts#XML_MSG_TEXT}
|
||||
* {@link me.chanjar.weixin.common.api.WxConsts#XML_MSG_IMAGE}
|
||||
* {@link me.chanjar.weixin.common.api.WxConsts#XML_MSG_VOICE}
|
||||
* {@link me.chanjar.weixin.common.api.WxConsts#XML_MSG_VIDEO}
|
||||
* {@link me.chanjar.weixin.common.api.WxConsts#XML_MSG_LOCATION}
|
||||
* {@link me.chanjar.weixin.common.api.WxConsts#XML_MSG_LINK}
|
||||
* {@link me.chanjar.weixin.common.api.WxConsts#XML_MSG_EVENT}
|
||||
* {@link WxConsts.XmlMsgType#TEXT}
|
||||
* {@link WxConsts.XmlMsgType#IMAGE}
|
||||
* {@link WxConsts.XmlMsgType#VOICE}
|
||||
* {@link WxConsts.XmlMsgType#VIDEO}
|
||||
* {@link WxConsts.XmlMsgType#LOCATION}
|
||||
* {@link WxConsts.XmlMsgType#LINK}
|
||||
* {@link WxConsts.XmlMsgType#EVENT}
|
||||
* </pre>
|
||||
*/
|
||||
public String getMsgType() {
|
||||
@@ -240,11 +241,11 @@ public class WxCpXmlMessage implements Serializable {
|
||||
/**
|
||||
* <pre>
|
||||
* 当发送消息的时候使用:
|
||||
* {@link me.chanjar.weixin.common.api.WxConsts#XML_MSG_TEXT}
|
||||
* {@link me.chanjar.weixin.common.api.WxConsts#XML_MSG_IMAGE}
|
||||
* {@link me.chanjar.weixin.common.api.WxConsts#XML_MSG_VOICE}
|
||||
* {@link me.chanjar.weixin.common.api.WxConsts#XML_MSG_VIDEO}
|
||||
* {@link me.chanjar.weixin.common.api.WxConsts#XML_MSG_NEWS}
|
||||
* {@link WxConsts.XmlMsgType#TEXT}
|
||||
* {@link WxConsts.XmlMsgType#IMAGE}
|
||||
* {@link WxConsts.XmlMsgType#VOICE}
|
||||
* {@link WxConsts.XmlMsgType#VIDEO}
|
||||
* {@link WxConsts.XmlMsgType#NEWS}
|
||||
* </pre>
|
||||
*
|
||||
* @param msgType
|
||||
|
||||
@@ -14,7 +14,7 @@ public class WxCpXmlOutImageMessage extends WxCpXmlOutMessage {
|
||||
private String mediaId;
|
||||
|
||||
public WxCpXmlOutImageMessage() {
|
||||
this.msgType = WxConsts.XML_MSG_IMAGE;
|
||||
this.msgType = WxConsts.XmlMsgType.IMAGE;
|
||||
}
|
||||
|
||||
public String getMediaId() {
|
||||
|
||||
@@ -18,7 +18,7 @@ public class WxCpXmlOutNewsMessage extends WxCpXmlOutMessage {
|
||||
protected int articleCount;
|
||||
|
||||
public WxCpXmlOutNewsMessage() {
|
||||
this.msgType = WxConsts.XML_MSG_NEWS;
|
||||
this.msgType = WxConsts.XmlMsgType.NEWS;
|
||||
}
|
||||
|
||||
public int getArticleCount() {
|
||||
|
||||
@@ -14,7 +14,7 @@ public class WxCpXmlOutTextMessage extends WxCpXmlOutMessage {
|
||||
private String content;
|
||||
|
||||
public WxCpXmlOutTextMessage() {
|
||||
this.msgType = WxConsts.XML_MSG_TEXT;
|
||||
this.msgType = WxConsts.XmlMsgType.TEXT;
|
||||
}
|
||||
|
||||
public String getContent() {
|
||||
|
||||
@@ -13,7 +13,7 @@ public class WxCpXmlOutVideoMessage extends WxCpXmlOutMessage {
|
||||
protected final Video video = new Video();
|
||||
|
||||
public WxCpXmlOutVideoMessage() {
|
||||
this.msgType = WxConsts.XML_MSG_VIDEO;
|
||||
this.msgType = WxConsts.XmlMsgType.VIDEO;
|
||||
}
|
||||
|
||||
public String getMediaId() {
|
||||
|
||||
@@ -14,7 +14,7 @@ public class WxCpXmlOutVoiceMessage extends WxCpXmlOutMessage {
|
||||
private String mediaId;
|
||||
|
||||
public WxCpXmlOutVoiceMessage() {
|
||||
this.msgType = WxConsts.XML_MSG_VOICE;
|
||||
this.msgType = WxConsts.XmlMsgType.VOICE;
|
||||
}
|
||||
|
||||
public String getMediaId() {
|
||||
|
||||
@@ -44,7 +44,7 @@ public class BaseBuilder<T> {
|
||||
m.setToUser(this.toUser);
|
||||
m.setToParty(this.toParty);
|
||||
m.setToTag(this.toTag);
|
||||
m.setSafe(StringUtils.defaultIfBlank(this.safe, WxConsts.CUSTOM_MSG_SAFE_NO));
|
||||
m.setSafe(StringUtils.defaultIfBlank(this.safe, WxConsts.KefuMsgSafe.NO));
|
||||
return m;
|
||||
}
|
||||
|
||||
|
||||
@@ -15,7 +15,7 @@ public final class FileBuilder extends BaseBuilder<FileBuilder> {
|
||||
private String mediaId;
|
||||
|
||||
public FileBuilder() {
|
||||
this.msgType = WxConsts.CUSTOM_MSG_FILE;
|
||||
this.msgType = WxConsts.KefuMsgType.FILE;
|
||||
}
|
||||
|
||||
public FileBuilder mediaId(String media_id) {
|
||||
|
||||
@@ -15,7 +15,7 @@ public final class ImageBuilder extends BaseBuilder<ImageBuilder> {
|
||||
private String mediaId;
|
||||
|
||||
public ImageBuilder() {
|
||||
this.msgType = WxConsts.CUSTOM_MSG_IMAGE;
|
||||
this.msgType = WxConsts.KefuMsgType.IMAGE;
|
||||
}
|
||||
|
||||
public ImageBuilder mediaId(String media_id) {
|
||||
|
||||
@@ -23,7 +23,7 @@ public final class MpnewsBuilder extends BaseBuilder<MpnewsBuilder> {
|
||||
private String mediaId;
|
||||
|
||||
public MpnewsBuilder() {
|
||||
this.msgType = WxConsts.CUSTOM_MSG_MPNEWS;
|
||||
this.msgType = WxConsts.KefuMsgType.MPNEWS;
|
||||
}
|
||||
|
||||
public MpnewsBuilder mediaId(String mediaId) {
|
||||
|
||||
@@ -22,7 +22,7 @@ public final class NewsBuilder extends BaseBuilder<NewsBuilder> {
|
||||
private List<NewArticle> articles = new ArrayList<>();
|
||||
|
||||
public NewsBuilder() {
|
||||
this.msgType = WxConsts.CUSTOM_MSG_NEWS;
|
||||
this.msgType = WxConsts.KefuMsgType.NEWS;
|
||||
}
|
||||
|
||||
public NewsBuilder addArticle(NewArticle... articles) {
|
||||
|
||||
@@ -15,7 +15,7 @@ public final class TextBuilder extends BaseBuilder<TextBuilder> {
|
||||
private String content;
|
||||
|
||||
public TextBuilder() {
|
||||
this.msgType = WxConsts.CUSTOM_MSG_TEXT;
|
||||
this.msgType = WxConsts.KefuMsgType.TEXT;
|
||||
}
|
||||
|
||||
public TextBuilder content(String content) {
|
||||
|
||||
@@ -18,7 +18,7 @@ public class TextCardBuilder extends BaseBuilder<TextCardBuilder> {
|
||||
private String url;
|
||||
|
||||
public TextCardBuilder() {
|
||||
this.msgType = WxConsts.CUSTOM_MSG_TEXTCARD;
|
||||
this.msgType = WxConsts.KefuMsgType.TEXTCARD;
|
||||
}
|
||||
|
||||
public TextCardBuilder title(String title) {
|
||||
|
||||
@@ -24,7 +24,7 @@ public final class VideoBuilder extends BaseBuilder<VideoBuilder> {
|
||||
private String thumbMediaId;
|
||||
|
||||
public VideoBuilder() {
|
||||
this.msgType = WxConsts.CUSTOM_MSG_VIDEO;
|
||||
this.msgType = WxConsts.KefuMsgType.VIDEO;
|
||||
}
|
||||
|
||||
public VideoBuilder mediaId(String mediaId) {
|
||||
|
||||
@@ -15,7 +15,7 @@ public final class VoiceBuilder extends BaseBuilder<VoiceBuilder> {
|
||||
private String mediaId;
|
||||
|
||||
public VoiceBuilder() {
|
||||
this.msgType = WxConsts.CUSTOM_MSG_VOICE;
|
||||
this.msgType = WxConsts.KefuMsgType.VOICE;
|
||||
}
|
||||
|
||||
public VoiceBuilder mediaId(String media_id) {
|
||||
|
||||
@@ -37,13 +37,13 @@ public class WxCpMessageGsonAdapter implements JsonSerializer<WxCpMessage> {
|
||||
if (StringUtils.isNotBlank(message.getToTag())) {
|
||||
messageJson.addProperty("totag", message.getToTag());
|
||||
}
|
||||
if (WxConsts.CUSTOM_MSG_TEXT.equals(message.getMsgType())) {
|
||||
if (WxConsts.KefuMsgType.TEXT.equals(message.getMsgType())) {
|
||||
JsonObject text = new JsonObject();
|
||||
text.addProperty("content", message.getContent());
|
||||
messageJson.add("text", text);
|
||||
}
|
||||
|
||||
if (WxConsts.CUSTOM_MSG_TEXTCARD.equals(message.getMsgType())) {
|
||||
if (WxConsts.KefuMsgType.TEXTCARD.equals(message.getMsgType())) {
|
||||
JsonObject text = new JsonObject();
|
||||
text.addProperty("title", message.getTitle());
|
||||
text.addProperty("description", message.getDescription());
|
||||
@@ -51,19 +51,19 @@ public class WxCpMessageGsonAdapter implements JsonSerializer<WxCpMessage> {
|
||||
messageJson.add("textcard", text);
|
||||
}
|
||||
|
||||
if (WxConsts.CUSTOM_MSG_IMAGE.equals(message.getMsgType())) {
|
||||
if (WxConsts.KefuMsgType.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 (WxConsts.KefuMsgType.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 (WxConsts.KefuMsgType.VOICE.equals(message.getMsgType())) {
|
||||
JsonObject voice = new JsonObject();
|
||||
voice.addProperty("media_id", message.getMediaId());
|
||||
messageJson.add("voice", voice);
|
||||
@@ -73,7 +73,7 @@ public class WxCpMessageGsonAdapter implements JsonSerializer<WxCpMessage> {
|
||||
messageJson.addProperty("safe", message.getSafe());
|
||||
}
|
||||
|
||||
if (WxConsts.CUSTOM_MSG_VIDEO.equals(message.getMsgType())) {
|
||||
if (WxConsts.KefuMsgType.VIDEO.equals(message.getMsgType())) {
|
||||
JsonObject video = new JsonObject();
|
||||
video.addProperty("media_id", message.getMediaId());
|
||||
video.addProperty("thumb_media_id", message.getThumbMediaId());
|
||||
@@ -82,7 +82,7 @@ public class WxCpMessageGsonAdapter implements JsonSerializer<WxCpMessage> {
|
||||
messageJson.add("video", video);
|
||||
}
|
||||
|
||||
if (WxConsts.CUSTOM_MSG_NEWS.equals(message.getMsgType())) {
|
||||
if (WxConsts.KefuMsgType.NEWS.equals(message.getMsgType())) {
|
||||
JsonObject newsJsonObject = new JsonObject();
|
||||
JsonArray articleJsonArray = new JsonArray();
|
||||
for (NewArticle article : message.getArticles()) {
|
||||
@@ -97,7 +97,7 @@ public class WxCpMessageGsonAdapter implements JsonSerializer<WxCpMessage> {
|
||||
messageJson.add("news", newsJsonObject);
|
||||
}
|
||||
|
||||
if (WxConsts.CUSTOM_MSG_MPNEWS.equals(message.getMsgType())) {
|
||||
if (WxConsts.KefuMsgType.MPNEWS.equals(message.getMsgType())) {
|
||||
JsonObject newsJsonObject = new JsonObject();
|
||||
if (message.getMediaId() != null) {
|
||||
newsJsonObject.addProperty("media_id", message.getMediaId());
|
||||
|
||||
Reference in New Issue
Block a user