Skip to content

Commit a2448d5

Browse files
committed
🆕 binarywang#1915 【企业微信】发送应用消息接口增加是否开启重复消息检查等字段
1 parent 1555011 commit a2448d5

2 files changed

Lines changed: 76 additions & 26 deletions

File tree

weixin-java-cp/src/main/java/me/chanjar/weixin/cp/bean/message/WxCpMessage.java

Lines changed: 62 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,22 @@ public class WxCpMessage implements Serializable {
4848
private Boolean emphasisFirstItem;
4949
private Map<String, String> contentItems;
5050

51+
/**
52+
* enable_id_trans
53+
* 表示是否开启id转译,0表示否,1表示是,默认0
54+
*/
55+
private Boolean enableIdTrans;
56+
/**
57+
* enable_duplicate_check
58+
* 表示是否开启重复消息检查,0表示否,1表示是,默认0
59+
*/
60+
private Boolean enableDuplicateCheck;
61+
/**
62+
* duplicate_check_interval
63+
* 表示是否重复消息检查的时间间隔,默认1800s,最大不超过4小时
64+
*/
65+
private Integer duplicateCheckInterval;
66+
5167
/**
5268
* 任务卡片特有的属性.
5369
*/
@@ -172,6 +188,18 @@ public String toJson() {
172188
messageJson.addProperty("totag", this.getToTag());
173189
}
174190

191+
if (this.getEnableIdTrans()) {
192+
messageJson.addProperty("enable_id_trans", 1);
193+
}
194+
195+
if (this.getEnableDuplicateCheck()) {
196+
messageJson.addProperty("enable_duplicate_check", 1);
197+
}
198+
199+
if (this.getDuplicateCheckInterval() != null) {
200+
messageJson.addProperty("duplicate_check_interval", this.getDuplicateCheckInterval());
201+
}
202+
175203
this.handleMsgType(messageJson);
176204

177205
if (StringUtils.isNotBlank(this.getSafe())) {
@@ -253,15 +281,7 @@ private void handleMsgType(JsonObject messageJson) {
253281
} else {
254282
JsonArray articleJsonArray = new JsonArray();
255283
for (MpnewsArticle article : this.getMpnewsArticles()) {
256-
JsonObject articleJson = new JsonObject();
257-
articleJson.addProperty("title", article.getTitle());
258-
articleJson.addProperty("thumb_media_id", article.getThumbMediaId());
259-
articleJson.addProperty("author", article.getAuthor());
260-
articleJson.addProperty("content_source_url", article.getContentSourceUrl());
261-
articleJson.addProperty("content", article.getContent());
262-
articleJson.addProperty("digest", article.getDigest());
263-
articleJson.addProperty("show_cover_pic", article.getShowCoverPic());
264-
articleJsonArray.add(articleJson);
284+
article2Json(articleJsonArray, article);
265285
}
266286

267287
newsJsonObject.add("articles", articleJsonArray);
@@ -282,23 +302,7 @@ private void handleMsgType(JsonObject messageJson) {
282302

283303
JsonArray buttonJsonArray = new JsonArray();
284304
for (TaskCardButton button : this.getTaskButtons()) {
285-
JsonObject buttonJson = new JsonObject();
286-
buttonJson.addProperty("key", button.getKey());
287-
buttonJson.addProperty("name", button.getName());
288-
289-
if (StringUtils.isNotBlank(button.getReplaceName())) {
290-
buttonJson.addProperty("replace_name", button.getReplaceName());
291-
}
292-
293-
if (StringUtils.isNotBlank(button.getColor())) {
294-
buttonJson.addProperty("color", button.getColor());
295-
}
296-
297-
if (button.getBold() != null) {
298-
buttonJson.addProperty("is_bold", button.getBold());
299-
}
300-
301-
buttonJsonArray.add(buttonJson);
305+
btn2Json(buttonJsonArray, button);
302306
}
303307
text.add("btn", buttonJsonArray);
304308

@@ -330,4 +334,36 @@ private void handleMsgType(JsonObject messageJson) {
330334
}
331335
}
332336

337+
private void btn2Json(JsonArray buttonJsonArray, TaskCardButton button) {
338+
JsonObject buttonJson = new JsonObject();
339+
buttonJson.addProperty("key", button.getKey());
340+
buttonJson.addProperty("name", button.getName());
341+
342+
if (StringUtils.isNotBlank(button.getReplaceName())) {
343+
buttonJson.addProperty("replace_name", button.getReplaceName());
344+
}
345+
346+
if (StringUtils.isNotBlank(button.getColor())) {
347+
buttonJson.addProperty("color", button.getColor());
348+
}
349+
350+
if (button.getBold() != null) {
351+
buttonJson.addProperty("is_bold", button.getBold());
352+
}
353+
354+
buttonJsonArray.add(buttonJson);
355+
}
356+
357+
private void article2Json(JsonArray articleJsonArray, MpnewsArticle article) {
358+
JsonObject articleJson = new JsonObject();
359+
articleJson.addProperty("title", article.getTitle());
360+
articleJson.addProperty("thumb_media_id", article.getThumbMediaId());
361+
articleJson.addProperty("author", article.getAuthor());
362+
articleJson.addProperty("content_source_url", article.getContentSourceUrl());
363+
articleJson.addProperty("content", article.getContent());
364+
articleJson.addProperty("digest", article.getDigest());
365+
articleJson.addProperty("show_cover_pic", article.getShowCoverPic());
366+
articleJsonArray.add(articleJson);
367+
}
368+
333369
}

weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/WxMpQrcodeService.java

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@ public interface WxMpQrcodeService {
2222
*
2323
* @param sceneId 场景值ID,临时二维码时为32位非0整型
2424
* @param expireSeconds 该二维码有效时间,以秒为单位。 最大不超过2592000(即30天),此字段如果不填,则默认有效期为30秒。
25+
* @return the wx mp qr code ticket
26+
* @throws WxErrorException the wx error exception
2527
*/
2628
WxMpQrCodeTicket qrCodeCreateTmpTicket(int sceneId, Integer expireSeconds) throws WxErrorException;
2729

@@ -34,6 +36,8 @@ public interface WxMpQrcodeService {
3436
*
3537
* @param sceneStr 场景值ID(字符串形式的ID),字符串类型,长度限制为1到64
3638
* @param expireSeconds 该二维码有效时间,以秒为单位。 最大不超过2592000(即30天),此字段如果不填,则默认有效期为30秒。
39+
* @return the wx mp qr code ticket
40+
* @throws WxErrorException the wx error exception
3741
*/
3842
WxMpQrCodeTicket qrCodeCreateTmpTicket(String sceneStr, Integer expireSeconds) throws WxErrorException;
3943

@@ -44,6 +48,8 @@ public interface WxMpQrcodeService {
4448
* </pre>
4549
*
4650
* @param sceneId 场景值ID,最大值为100000(目前参数只支持1--100000)
51+
* @return the wx mp qr code ticket
52+
* @throws WxErrorException the wx error exception
4753
*/
4854
WxMpQrCodeTicket qrCodeCreateLastTicket(int sceneId) throws WxErrorException;
4955

@@ -54,6 +60,8 @@ public interface WxMpQrcodeService {
5460
* </pre>
5561
*
5662
* @param sceneStr 参数。字符串类型长度现在为1到64
63+
* @return the wx mp qr code ticket
64+
* @throws WxErrorException the wx error exception
5765
*/
5866
WxMpQrCodeTicket qrCodeCreateLastTicket(String sceneStr) throws WxErrorException;
5967

@@ -64,6 +72,8 @@ public interface WxMpQrcodeService {
6472
* </pre>
6573
*
6674
* @param ticket 二维码ticket
75+
* @return the file
76+
* @throws WxErrorException the wx error exception
6777
*/
6878
File qrCodePicture(WxMpQrCodeTicket ticket) throws WxErrorException;
6979

@@ -75,6 +85,8 @@ public interface WxMpQrcodeService {
7585
*
7686
* @param ticket 二维码ticket
7787
* @param needShortUrl 是否需要压缩的二维码地址
88+
* @return the string
89+
* @throws WxErrorException the wx error exception
7890
*/
7991
String qrCodePictureUrl(String ticket, boolean needShortUrl) throws WxErrorException;
8092

@@ -85,6 +97,8 @@ public interface WxMpQrcodeService {
8597
* </pre>
8698
*
8799
* @param ticket 二维码ticket
100+
* @return the string
101+
* @throws WxErrorException the wx error exception
88102
*/
89103
String qrCodePictureUrl(String ticket) throws WxErrorException;
90104

0 commit comments

Comments
 (0)