mirror of
https://gitee.com/binary/weixin-java-tools.git
synced 2026-02-18 22:26:22 +08:00
添加对客服消息发送(点击跳转到图文消息页面) 图文消息的支持 #67
This commit is contained in:
@@ -1,17 +1,16 @@
|
||||
package me.chanjar.weixin.mp.bean;
|
||||
|
||||
import me.chanjar.weixin.mp.util.json.WxMpGsonBuilder;
|
||||
import org.apache.commons.lang3.builder.ToStringBuilder;
|
||||
import org.apache.commons.lang3.builder.ToStringStyle;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class WxMpMaterialNews implements Serializable {
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
private static final long serialVersionUID = -3283203652013494976L;
|
||||
|
||||
private List<WxMpMaterialNewsArticle> articles = new ArrayList<>();
|
||||
|
||||
public List<WxMpMaterialNewsArticle> getArticles() {
|
||||
@@ -81,7 +80,6 @@ public class WxMpMaterialNews implements Serializable {
|
||||
|
||||
/**
|
||||
* 点击图文消息跳转链接
|
||||
* @return
|
||||
*/
|
||||
private String url;
|
||||
|
||||
@@ -159,14 +157,12 @@ public class WxMpMaterialNews implements Serializable {
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "WxMpMassNewsArticle [" + "thumbMediaId=" + this.thumbMediaId + "thumbUrl=" + this.thumbUrl + ", author=" + this.author + ", title=" + this.title +
|
||||
", contentSourceUrl=" + this.contentSourceUrl + ", content=" + this.content + ", digest=" + this.digest +
|
||||
", showCoverPic=" + this.showCoverPic +", url=" + this.url + "]";
|
||||
return ToStringBuilder.reflectionToString(this, ToStringStyle.MULTI_LINE_STYLE);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "WxMpMaterialNews [" + "articles=" + this.articles + "]";
|
||||
return ToStringBuilder.reflectionToString(this, ToStringStyle.MULTI_LINE_STYLE);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,33 @@
|
||||
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,16 +1,23 @@
|
||||
package me.chanjar.weixin.mp.bean.kefu;
|
||||
|
||||
import me.chanjar.weixin.mp.bean.custombuilder.*;
|
||||
import me.chanjar.weixin.mp.util.json.WxMpGsonBuilder;
|
||||
|
||||
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.util.json.WxMpGsonBuilder;
|
||||
|
||||
/**
|
||||
* 客服消息
|
||||
* @author chanjarster
|
||||
*
|
||||
* @author chanjarster
|
||||
*/
|
||||
public class WxMpKefuMessage implements Serializable {
|
||||
private static final long serialVersionUID = -9196732086954365246L;
|
||||
@@ -26,130 +33,9 @@ public class WxMpKefuMessage implements Serializable {
|
||||
private String hqMusicUrl;
|
||||
private String kfAccount;
|
||||
private String cardId;
|
||||
private String mpNewsMediaId;
|
||||
private List<WxArticle> articles = new ArrayList<>();
|
||||
|
||||
public String getToUser() {
|
||||
return this.toUser;
|
||||
}
|
||||
public void setToUser(String toUser) {
|
||||
this.toUser = toUser;
|
||||
}
|
||||
public String getMsgType() {
|
||||
return this.msgType;
|
||||
}
|
||||
|
||||
/**
|
||||
* <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_WXCARD}
|
||||
* </pre>
|
||||
* @param msgType
|
||||
*/
|
||||
public void setMsgType(String msgType) {
|
||||
this.msgType = msgType;
|
||||
}
|
||||
public String getContent() {
|
||||
return this.content;
|
||||
}
|
||||
public void setContent(String content) {
|
||||
this.content = content;
|
||||
}
|
||||
public String getMediaId() {
|
||||
return this.mediaId;
|
||||
}
|
||||
public void setMediaId(String mediaId) {
|
||||
this.mediaId = mediaId;
|
||||
}
|
||||
public String getThumbMediaId() {
|
||||
return this.thumbMediaId;
|
||||
}
|
||||
public void setThumbMediaId(String thumbMediaId) {
|
||||
this.thumbMediaId = thumbMediaId;
|
||||
}
|
||||
public String getTitle() {
|
||||
return this.title;
|
||||
}
|
||||
public void setTitle(String title) {
|
||||
this.title = title;
|
||||
}
|
||||
public String getDescription() {
|
||||
return this.description;
|
||||
}
|
||||
public void setDescription(String description) {
|
||||
this.description = description;
|
||||
}
|
||||
public String getMusicUrl() {
|
||||
return this.musicUrl;
|
||||
}
|
||||
public void setMusicUrl(String musicUrl) {
|
||||
this.musicUrl = musicUrl;
|
||||
}
|
||||
public String getHqMusicUrl() {
|
||||
return this.hqMusicUrl;
|
||||
}
|
||||
public void setHqMusicUrl(String hqMusicUrl) {
|
||||
this.hqMusicUrl = hqMusicUrl;
|
||||
}
|
||||
|
||||
public String getCardId() {
|
||||
return this.cardId;
|
||||
}
|
||||
|
||||
public void setCardId(String cardId) {
|
||||
this.cardId = cardId;
|
||||
}
|
||||
|
||||
public List<WxArticle> getArticles() {
|
||||
return this.articles;
|
||||
}
|
||||
public void setArticles(List<WxArticle> articles) {
|
||||
this.articles = articles;
|
||||
}
|
||||
|
||||
public String toJson() {
|
||||
return WxMpGsonBuilder.INSTANCE.create().toJson(this);
|
||||
}
|
||||
|
||||
public static class WxArticle {
|
||||
|
||||
private String title;
|
||||
private String description;
|
||||
private String url;
|
||||
private String picUrl;
|
||||
|
||||
public String getTitle() {
|
||||
return this.title;
|
||||
}
|
||||
public void setTitle(String title) {
|
||||
this.title = title;
|
||||
}
|
||||
public String getDescription() {
|
||||
return this.description;
|
||||
}
|
||||
public void setDescription(String description) {
|
||||
this.description = description;
|
||||
}
|
||||
public String getUrl() {
|
||||
return this.url;
|
||||
}
|
||||
public void setUrl(String url) {
|
||||
this.url = url;
|
||||
}
|
||||
public String getPicUrl() {
|
||||
return this.picUrl;
|
||||
}
|
||||
public void setPicUrl(String picUrl) {
|
||||
this.picUrl = picUrl;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* 获得文本消息builder
|
||||
*/
|
||||
@@ -186,12 +72,18 @@ public class WxMpKefuMessage implements Serializable {
|
||||
}
|
||||
|
||||
/**
|
||||
* 获得图文消息builder
|
||||
* 获得图文消息(点击跳转到外链)builder
|
||||
*/
|
||||
public static NewsBuilder NEWS() {
|
||||
return new NewsBuilder();
|
||||
}
|
||||
|
||||
/**
|
||||
* 获得图文消息(点击跳转到图文消息页面)builder
|
||||
*/
|
||||
public static MpNewsBuilder MPNEWS() {
|
||||
return new MpNewsBuilder();
|
||||
}
|
||||
|
||||
/**
|
||||
* 获得卡券消息builder
|
||||
@@ -200,6 +92,121 @@ public class WxMpKefuMessage implements Serializable {
|
||||
return new WxCardBuilder();
|
||||
}
|
||||
|
||||
public String getToUser() {
|
||||
return this.toUser;
|
||||
}
|
||||
|
||||
public void setToUser(String toUser) {
|
||||
this.toUser = toUser;
|
||||
}
|
||||
|
||||
public String getMsgType() {
|
||||
return this.msgType;
|
||||
}
|
||||
|
||||
public String getMpNewsMediaId() {
|
||||
return this.mpNewsMediaId;
|
||||
}
|
||||
|
||||
public void setMpNewsMediaId(String mpNewsMediaId) {
|
||||
this.mpNewsMediaId = mpNewsMediaId;
|
||||
}
|
||||
|
||||
/**
|
||||
* <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 me.chanjar.weixin.common.api.WxConsts#CUSTOM_MSG_WXCARD}
|
||||
* </pre>
|
||||
*
|
||||
* @param msgType
|
||||
*/
|
||||
public void setMsgType(String msgType) {
|
||||
this.msgType = msgType;
|
||||
}
|
||||
|
||||
public String getContent() {
|
||||
return this.content;
|
||||
}
|
||||
|
||||
public void setContent(String content) {
|
||||
this.content = content;
|
||||
}
|
||||
|
||||
public String getMediaId() {
|
||||
return this.mediaId;
|
||||
}
|
||||
|
||||
public void setMediaId(String mediaId) {
|
||||
this.mediaId = mediaId;
|
||||
}
|
||||
|
||||
public String getThumbMediaId() {
|
||||
return this.thumbMediaId;
|
||||
}
|
||||
|
||||
public void setThumbMediaId(String thumbMediaId) {
|
||||
this.thumbMediaId = thumbMediaId;
|
||||
}
|
||||
|
||||
public String getTitle() {
|
||||
return this.title;
|
||||
}
|
||||
|
||||
public void setTitle(String title) {
|
||||
this.title = title;
|
||||
}
|
||||
|
||||
public String getDescription() {
|
||||
return this.description;
|
||||
}
|
||||
|
||||
public void setDescription(String description) {
|
||||
this.description = description;
|
||||
}
|
||||
|
||||
public String getMusicUrl() {
|
||||
return this.musicUrl;
|
||||
}
|
||||
|
||||
public void setMusicUrl(String musicUrl) {
|
||||
this.musicUrl = musicUrl;
|
||||
}
|
||||
|
||||
public String getHqMusicUrl() {
|
||||
return this.hqMusicUrl;
|
||||
}
|
||||
|
||||
public void setHqMusicUrl(String hqMusicUrl) {
|
||||
this.hqMusicUrl = hqMusicUrl;
|
||||
}
|
||||
|
||||
public String getCardId() {
|
||||
return this.cardId;
|
||||
}
|
||||
|
||||
public void setCardId(String cardId) {
|
||||
this.cardId = cardId;
|
||||
}
|
||||
|
||||
public List<WxArticle> getArticles() {
|
||||
return this.articles;
|
||||
}
|
||||
|
||||
public void setArticles(List<WxArticle> articles) {
|
||||
this.articles = articles;
|
||||
}
|
||||
|
||||
public String toJson() {
|
||||
return WxMpGsonBuilder.INSTANCE.create().toJson(this);
|
||||
}
|
||||
|
||||
public String getKfAccount() {
|
||||
return this.kfAccount;
|
||||
}
|
||||
@@ -207,4 +214,44 @@ public class WxMpKefuMessage implements Serializable {
|
||||
public void setKfAccount(String kfAccount) {
|
||||
this.kfAccount = kfAccount;
|
||||
}
|
||||
|
||||
public static class WxArticle {
|
||||
private String title;
|
||||
private String description;
|
||||
private String url;
|
||||
private String picUrl;
|
||||
|
||||
public String getTitle() {
|
||||
return this.title;
|
||||
}
|
||||
|
||||
public void setTitle(String title) {
|
||||
this.title = title;
|
||||
}
|
||||
|
||||
public String getDescription() {
|
||||
return this.description;
|
||||
}
|
||||
|
||||
public void setDescription(String description) {
|
||||
this.description = description;
|
||||
}
|
||||
|
||||
public String getUrl() {
|
||||
return this.url;
|
||||
}
|
||||
|
||||
public void setUrl(String url) {
|
||||
this.url = url;
|
||||
}
|
||||
|
||||
public String getPicUrl() {
|
||||
return this.picUrl;
|
||||
}
|
||||
|
||||
public void setPicUrl(String picUrl) {
|
||||
this.picUrl = picUrl;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -75,6 +75,12 @@ public class WxMpKefuMessageGsonAdapter implements JsonSerializer<WxMpKefuMessag
|
||||
messageJson.add("news", newsJsonObject);
|
||||
}
|
||||
|
||||
if (WxConsts.CUSTOM_MSG_MPNEWS.equals(message.getMsgType())) {
|
||||
JsonObject json = new JsonObject();
|
||||
json.addProperty("media_id", message.getMpNewsMediaId());
|
||||
messageJson.add("mpnews", json);
|
||||
}
|
||||
|
||||
if (WxConsts.CUSTOM_MSG_WXCARD.equals(message.getMsgType())) {
|
||||
JsonObject wxcard = new JsonObject();
|
||||
wxcard.addProperty("card_id", message.getCardId());
|
||||
|
||||
Reference in New Issue
Block a user