新增卡券的客服消息类型

1. WxCardBuilder用于构建卡券的客服消息;
2. WxMpCustomMessage新作cardId字段及卡券builder;
3. CustomMessageGsonAdapter处理cardId序列化名字;
4. WxConsts新作WXCARD卡券类型。
This commit is contained in:
YuJian 2016-09-18 21:30:39 +08:00
parent 21f14971c1
commit ad71e3c0f3
4 changed files with 72 additions and 15 deletions

View File

@ -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";

View File

@ -25,6 +25,7 @@ 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() {
@ -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,6 +96,15 @@ 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;
}
@ -181,6 +192,15 @@ public class WxMpCustomMessage implements Serializable {
return new NewsBuilder();
}
/**
* 获得卡券消息builder
* @return
*/
public static WxCardBuilder WXCARD() {
return new WxCardBuilder();
}
public String getKfAccount() {
return this.kfAccount;
}
@ -188,5 +208,4 @@ public class WxMpCustomMessage implements Serializable {
public void setKfAccount(String kfAccount) {
this.kfAccount = kfAccount;
}
}

View File

@ -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;
}
}

View File

@ -76,6 +76,12 @@ public class WxMpCustomMessageGsonAdapter implements JsonSerializer<WxMpCustomMe
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();
newsJsonObject.addProperty("kf_account", message.getKfAccount());