mirror of
https://gitee.com/binary/weixin-java-tools.git
synced 2025-04-05 17:38:05 +08:00
新增卡券的客服消息类型
1. WxCardBuilder用于构建卡券的客服消息; 2. WxMpCustomMessage新作cardId字段及卡券builder; 3. CustomMessageGsonAdapter处理cardId序列化名字; 4. WxConsts新作WXCARD卡券类型。
This commit is contained in:
parent
21f14971c1
commit
ad71e3c0f3
@ -30,6 +30,7 @@ public class WxConsts {
|
||||
public static final String CUSTOM_MSG_MUSIC = "music";
|
||||
public static final String CUSTOM_MSG_NEWS = "news";
|
||||
public static final String CUSTOM_MSG_FILE = "file";
|
||||
public static final String CUSTOM_MSG_WXCARD = "wxcard";
|
||||
public static final String CUSTOM_MSG_TRANSFER_CUSTOMER_SERVICE = "transfer_customer_service";
|
||||
public static final String CUSTOM_MSG_SAFE_NO = "0";
|
||||
public static final String CUSTOM_MSG_SAFE_YES = "1";
|
||||
|
@ -14,7 +14,7 @@ import java.util.List;
|
||||
*/
|
||||
public class WxMpCustomMessage implements Serializable {
|
||||
private static final long serialVersionUID = -9196732086954365246L;
|
||||
|
||||
|
||||
private String toUser;
|
||||
private String msgType;
|
||||
private String content;
|
||||
@ -25,8 +25,9 @@ public class WxMpCustomMessage implements Serializable {
|
||||
private String musicUrl;
|
||||
private String hqMusicUrl;
|
||||
private String kfAccount;
|
||||
private String cardId;
|
||||
private List<WxArticle> articles = new ArrayList<>();
|
||||
|
||||
|
||||
public String getToUser() {
|
||||
return this.toUser;
|
||||
}
|
||||
@ -36,7 +37,7 @@ public class WxMpCustomMessage implements Serializable {
|
||||
public String getMsgType() {
|
||||
return this.msgType;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* <pre>
|
||||
* 请使用
|
||||
@ -46,6 +47,7 @@ public class WxMpCustomMessage implements Serializable {
|
||||
* {@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
|
||||
*/
|
||||
@ -94,24 +96,33 @@ public class WxMpCustomMessage implements Serializable {
|
||||
public void setHqMusicUrl(String hqMusicUrl) {
|
||||
this.hqMusicUrl = hqMusicUrl;
|
||||
}
|
||||
|
||||
public String getCardId() {
|
||||
return 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;
|
||||
}
|
||||
@ -136,9 +147,9 @@ public class WxMpCustomMessage implements Serializable {
|
||||
public void setPicUrl(String picUrl) {
|
||||
this.picUrl = picUrl;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 获得文本消息builder
|
||||
*/
|
||||
@ -159,34 +170,42 @@ public class WxMpCustomMessage 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
|
||||
* @return
|
||||
*/
|
||||
public static WxCardBuilder WXCARD() {
|
||||
return new WxCardBuilder();
|
||||
}
|
||||
|
||||
public String getKfAccount() {
|
||||
return this.kfAccount;
|
||||
}
|
||||
|
||||
|
||||
public void setKfAccount(String kfAccount) {
|
||||
this.kfAccount = kfAccount;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -0,0 +1,31 @@
|
||||
package me.chanjar.weixin.mp.bean.custombuilder;
|
||||
|
||||
import me.chanjar.weixin.common.api.WxConsts;
|
||||
import me.chanjar.weixin.mp.bean.WxMpCustomMessage;
|
||||
|
||||
/**
|
||||
* 卡券消息builder
|
||||
* <pre>
|
||||
* 用法: WxMpCustomMessage m = WxMpCustomMessage.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;
|
||||
}
|
||||
|
||||
public WxMpCustomMessage build() {
|
||||
WxMpCustomMessage m = super.build();
|
||||
m.setCardId(this.cardId);
|
||||
return m;
|
||||
}
|
||||
}
|
@ -75,6 +75,12 @@ public class WxMpCustomMessageGsonAdapter implements JsonSerializer<WxMpCustomMe
|
||||
newsJsonObject.add("articles", articleJsonArray);
|
||||
messageJson.add("news", newsJsonObject);
|
||||
}
|
||||
|
||||
if (WxConsts.CUSTOM_MSG_WXCARD.equals(message.getMsgType())) {
|
||||
JsonObject wxcard = new JsonObject();
|
||||
wxcard.addProperty("card_id", message.getCardId());
|
||||
messageJson.add("wxcard", wxcard);
|
||||
}
|
||||
|
||||
if (StringUtils.isNotBlank(message.getKfAccount())){
|
||||
JsonObject newsJsonObject = new JsonObject();
|
||||
|
Loading…
Reference in New Issue
Block a user