diff --git a/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/bean/message/WxCpMessage.java b/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/bean/message/WxCpMessage.java index 9c579fd0d..7fa1212c7 100644 --- a/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/bean/message/WxCpMessage.java +++ b/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/bean/message/WxCpMessage.java @@ -48,6 +48,22 @@ public class WxCpMessage implements Serializable { private Boolean emphasisFirstItem; private Map contentItems; + /** + * enable_id_trans + * 表示是否开启id转译,0表示否,1表示是,默认0 + */ + private Boolean enableIdTrans; + /** + * enable_duplicate_check + * 表示是否开启重复消息检查,0表示否,1表示是,默认0 + */ + private Boolean enableDuplicateCheck; + /** + * duplicate_check_interval + * 表示是否重复消息检查的时间间隔,默认1800s,最大不超过4小时 + */ + private Integer duplicateCheckInterval; + /** * 任务卡片特有的属性. */ @@ -172,6 +188,18 @@ public class WxCpMessage implements Serializable { messageJson.addProperty("totag", this.getToTag()); } + if (this.getEnableIdTrans()) { + messageJson.addProperty("enable_id_trans", 1); + } + + if (this.getEnableDuplicateCheck()) { + messageJson.addProperty("enable_duplicate_check", 1); + } + + if (this.getDuplicateCheckInterval() != null) { + messageJson.addProperty("duplicate_check_interval", this.getDuplicateCheckInterval()); + } + this.handleMsgType(messageJson); if (StringUtils.isNotBlank(this.getSafe())) { @@ -253,15 +281,7 @@ public class WxCpMessage implements Serializable { } else { JsonArray articleJsonArray = new JsonArray(); for (MpnewsArticle article : this.getMpnewsArticles()) { - JsonObject articleJson = new JsonObject(); - articleJson.addProperty("title", article.getTitle()); - articleJson.addProperty("thumb_media_id", article.getThumbMediaId()); - articleJson.addProperty("author", article.getAuthor()); - articleJson.addProperty("content_source_url", article.getContentSourceUrl()); - articleJson.addProperty("content", article.getContent()); - articleJson.addProperty("digest", article.getDigest()); - articleJson.addProperty("show_cover_pic", article.getShowCoverPic()); - articleJsonArray.add(articleJson); + article2Json(articleJsonArray, article); } newsJsonObject.add("articles", articleJsonArray); @@ -282,23 +302,7 @@ public class WxCpMessage implements Serializable { JsonArray buttonJsonArray = new JsonArray(); for (TaskCardButton button : this.getTaskButtons()) { - JsonObject buttonJson = new JsonObject(); - buttonJson.addProperty("key", button.getKey()); - buttonJson.addProperty("name", button.getName()); - - if (StringUtils.isNotBlank(button.getReplaceName())) { - buttonJson.addProperty("replace_name", button.getReplaceName()); - } - - if (StringUtils.isNotBlank(button.getColor())) { - buttonJson.addProperty("color", button.getColor()); - } - - if (button.getBold() != null) { - buttonJson.addProperty("is_bold", button.getBold()); - } - - buttonJsonArray.add(buttonJson); + btn2Json(buttonJsonArray, button); } text.add("btn", buttonJsonArray); @@ -330,4 +334,36 @@ public class WxCpMessage implements Serializable { } } + private void btn2Json(JsonArray buttonJsonArray, TaskCardButton button) { + JsonObject buttonJson = new JsonObject(); + buttonJson.addProperty("key", button.getKey()); + buttonJson.addProperty("name", button.getName()); + + if (StringUtils.isNotBlank(button.getReplaceName())) { + buttonJson.addProperty("replace_name", button.getReplaceName()); + } + + if (StringUtils.isNotBlank(button.getColor())) { + buttonJson.addProperty("color", button.getColor()); + } + + if (button.getBold() != null) { + buttonJson.addProperty("is_bold", button.getBold()); + } + + buttonJsonArray.add(buttonJson); + } + + private void article2Json(JsonArray articleJsonArray, MpnewsArticle article) { + JsonObject articleJson = new JsonObject(); + articleJson.addProperty("title", article.getTitle()); + articleJson.addProperty("thumb_media_id", article.getThumbMediaId()); + articleJson.addProperty("author", article.getAuthor()); + articleJson.addProperty("content_source_url", article.getContentSourceUrl()); + articleJson.addProperty("content", article.getContent()); + articleJson.addProperty("digest", article.getDigest()); + articleJson.addProperty("show_cover_pic", article.getShowCoverPic()); + articleJsonArray.add(articleJson); + } + } diff --git a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/WxMpQrcodeService.java b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/WxMpQrcodeService.java index 6622159d2..4ba7fc982 100644 --- a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/WxMpQrcodeService.java +++ b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/WxMpQrcodeService.java @@ -22,6 +22,8 @@ public interface WxMpQrcodeService { * * @param sceneId 场景值ID,临时二维码时为32位非0整型 * @param expireSeconds 该二维码有效时间,以秒为单位。 最大不超过2592000(即30天),此字段如果不填,则默认有效期为30秒。 + * @return the wx mp qr code ticket + * @throws WxErrorException the wx error exception */ WxMpQrCodeTicket qrCodeCreateTmpTicket(int sceneId, Integer expireSeconds) throws WxErrorException; @@ -34,6 +36,8 @@ public interface WxMpQrcodeService { * * @param sceneStr 场景值ID(字符串形式的ID),字符串类型,长度限制为1到64 * @param expireSeconds 该二维码有效时间,以秒为单位。 最大不超过2592000(即30天),此字段如果不填,则默认有效期为30秒。 + * @return the wx mp qr code ticket + * @throws WxErrorException the wx error exception */ WxMpQrCodeTicket qrCodeCreateTmpTicket(String sceneStr, Integer expireSeconds) throws WxErrorException; @@ -44,6 +48,8 @@ public interface WxMpQrcodeService { * * * @param sceneId 场景值ID,最大值为100000(目前参数只支持1--100000) + * @return the wx mp qr code ticket + * @throws WxErrorException the wx error exception */ WxMpQrCodeTicket qrCodeCreateLastTicket(int sceneId) throws WxErrorException; @@ -54,6 +60,8 @@ public interface WxMpQrcodeService { * * * @param sceneStr 参数。字符串类型长度现在为1到64 + * @return the wx mp qr code ticket + * @throws WxErrorException the wx error exception */ WxMpQrCodeTicket qrCodeCreateLastTicket(String sceneStr) throws WxErrorException; @@ -64,6 +72,8 @@ public interface WxMpQrcodeService { * * * @param ticket 二维码ticket + * @return the file + * @throws WxErrorException the wx error exception */ File qrCodePicture(WxMpQrCodeTicket ticket) throws WxErrorException; @@ -75,6 +85,8 @@ public interface WxMpQrcodeService { * * @param ticket 二维码ticket * @param needShortUrl 是否需要压缩的二维码地址 + * @return the string + * @throws WxErrorException the wx error exception */ String qrCodePictureUrl(String ticket, boolean needShortUrl) throws WxErrorException; @@ -85,6 +97,8 @@ public interface WxMpQrcodeService { * * * @param ticket 二维码ticket + * @return the string + * @throws WxErrorException the wx error exception */ String qrCodePictureUrl(String ticket) throws WxErrorException;