Skip to content

Commit ad71e3c

Browse files
committed
新增卡券的客服消息类型
1. WxCardBuilder用于构建卡券的客服消息; 2. WxMpCustomMessage新作cardId字段及卡券builder; 3. CustomMessageGsonAdapter处理cardId序列化名字; 4. WxConsts新作WXCARD卡券类型。
1 parent 21f1497 commit ad71e3c

4 files changed

Lines changed: 72 additions & 15 deletions

File tree

‎weixin-java-common/src/main/java/me/chanjar/weixin/common/api/WxConsts.java‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ public class WxConsts {
3030
public static final String CUSTOM_MSG_MUSIC = "music";
3131
public static final String CUSTOM_MSG_NEWS = "news";
3232
public static final String CUSTOM_MSG_FILE = "file";
33+
public static final String CUSTOM_MSG_WXCARD = "wxcard";
3334
public static final String CUSTOM_MSG_TRANSFER_CUSTOMER_SERVICE = "transfer_customer_service";
3435
public static final String CUSTOM_MSG_SAFE_NO = "0";
3536
public static final String CUSTOM_MSG_SAFE_YES = "1";

‎weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/WxMpCustomMessage.java‎

Lines changed: 34 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
*/
1515
public class WxMpCustomMessage implements Serializable {
1616
private static final long serialVersionUID = -9196732086954365246L;
17-
17+
1818
private String toUser;
1919
private String msgType;
2020
private String content;
@@ -25,8 +25,9 @@ public class WxMpCustomMessage implements Serializable {
2525
private String musicUrl;
2626
private String hqMusicUrl;
2727
private String kfAccount;
28+
private String cardId;
2829
private List<WxArticle> articles = new ArrayList<>();
29-
30+
3031
public String getToUser() {
3132
return this.toUser;
3233
}
@@ -36,7 +37,7 @@ public void setToUser(String toUser) {
3637
public String getMsgType() {
3738
return this.msgType;
3839
}
39-
40+
4041
/**
4142
* <pre>
4243
* 请使用
@@ -46,6 +47,7 @@ public String getMsgType() {
4647
* {@link me.chanjar.weixin.common.api.WxConsts#CUSTOM_MSG_MUSIC}
4748
* {@link me.chanjar.weixin.common.api.WxConsts#CUSTOM_MSG_VIDEO}
4849
* {@link me.chanjar.weixin.common.api.WxConsts#CUSTOM_MSG_NEWS}
50+
* {@link me.chanjar.weixin.common.api.WxConsts#CUSTOM_MSG_WXCARD}
4951
* </pre>
5052
* @param msgType
5153
*/
@@ -94,24 +96,33 @@ public String getHqMusicUrl() {
9496
public void setHqMusicUrl(String hqMusicUrl) {
9597
this.hqMusicUrl = hqMusicUrl;
9698
}
99+
100+
public String getCardId() {
101+
return cardId;
102+
}
103+
104+
public void setCardId(String cardId) {
105+
this.cardId = cardId;
106+
}
107+
97108
public List<WxArticle> getArticles() {
98109
return this.articles;
99110
}
100111
public void setArticles(List<WxArticle> articles) {
101112
this.articles = articles;
102113
}
103-
114+
104115
public String toJson() {
105116
return WxMpGsonBuilder.INSTANCE.create().toJson(this);
106117
}
107-
118+
108119
public static class WxArticle {
109-
120+
110121
private String title;
111122
private String description;
112123
private String url;
113124
private String picUrl;
114-
125+
115126
public String getTitle() {
116127
return this.title;
117128
}
@@ -136,9 +147,9 @@ public String getPicUrl() {
136147
public void setPicUrl(String picUrl) {
137148
this.picUrl = picUrl;
138149
}
139-
150+
140151
}
141-
152+
142153
/**
143154
* 获得文本消息builder
144155
*/
@@ -159,34 +170,42 @@ public static ImageBuilder IMAGE() {
159170
public static VoiceBuilder VOICE() {
160171
return new VoiceBuilder();
161172
}
162-
173+
163174
/**
164175
* 获得视频消息builder
165176
*/
166177
public static VideoBuilder VIDEO() {
167178
return new VideoBuilder();
168179
}
169-
180+
170181
/**
171182
* 获得音乐消息builder
172183
*/
173184
public static MusicBuilder MUSIC() {
174185
return new MusicBuilder();
175186
}
176-
187+
177188
/**
178189
* 获得图文消息builder
179190
*/
180191
public static NewsBuilder NEWS() {
181192
return new NewsBuilder();
182193
}
183-
194+
195+
196+
/**
197+
* 获得卡券消息builder
198+
* @return
199+
*/
200+
public static WxCardBuilder WXCARD() {
201+
return new WxCardBuilder();
202+
}
203+
184204
public String getKfAccount() {
185205
return this.kfAccount;
186206
}
187-
207+
188208
public void setKfAccount(String kfAccount) {
189209
this.kfAccount = kfAccount;
190210
}
191-
192211
}
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
package me.chanjar.weixin.mp.bean.custombuilder;
2+
3+
import me.chanjar.weixin.common.api.WxConsts;
4+
import me.chanjar.weixin.mp.bean.WxMpCustomMessage;
5+
6+
/**
7+
* 卡券消息builder
8+
* <pre>
9+
* 用法: WxMpCustomMessage m = WxMpCustomMessage.WXCARD().cardId(...).toUser(...).build();
10+
* </pre>
11+
* @author mgcnrx11
12+
*
13+
*/
14+
public final class WxCardBuilder extends BaseBuilder<WxCardBuilder> {
15+
private String cardId;
16+
17+
public WxCardBuilder() {
18+
this.msgType = WxConsts.CUSTOM_MSG_WXCARD;
19+
}
20+
21+
public WxCardBuilder cardId(String cardId) {
22+
this.cardId = cardId;
23+
return this;
24+
}
25+
26+
public WxMpCustomMessage build() {
27+
WxMpCustomMessage m = super.build();
28+
m.setCardId(this.cardId);
29+
return m;
30+
}
31+
}

‎weixin-java-mp/src/main/java/me/chanjar/weixin/mp/util/json/WxMpCustomMessageGsonAdapter.java‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,12 @@ public JsonElement serialize(WxMpCustomMessage message, Type typeOfSrc, JsonSeri
7575
newsJsonObject.add("articles", articleJsonArray);
7676
messageJson.add("news", newsJsonObject);
7777
}
78+
79+
if (WxConsts.CUSTOM_MSG_WXCARD.equals(message.getMsgType())) {
80+
JsonObject wxcard = new JsonObject();
81+
wxcard.addProperty("card_id", message.getCardId());
82+
messageJson.add("wxcard", wxcard);
83+
}
7884

7985
if (StringUtils.isNotBlank(message.getKfAccount())){
8086
JsonObject newsJsonObject = new JsonObject();

0 commit comments

Comments
 (0)