mirror of
https://gitee.com/binary/weixin-java-tools.git
synced 2025-05-02 20:02:37 +08:00
🎨 #2873 【企业微信】模板卡片消息支持左图右文样式和按钮型卡片的下拉框样式(企业微信v3.1.18版本引入的新特性)
This commit is contained in:
parent
c26b055ccf
commit
c109e81842
@ -27,26 +27,99 @@ import static me.chanjar.weixin.common.api.WxConsts.KefuMsgType.*;
|
||||
public class WxCpMessage implements Serializable {
|
||||
private static final long serialVersionUID = -2082278303476631708L;
|
||||
|
||||
/**
|
||||
* 指定接收消息的成员,成员ID列表(多个接收者用‘|’分隔,最多支持1000个)。
|
||||
* 特殊情况:指定为"@all",则向该企业应用的全部成员发送
|
||||
*/
|
||||
private String toUser;
|
||||
/**
|
||||
* 指定接收消息的部门,部门ID列表,多个接收者用‘|’分隔,最多支持100个。
|
||||
* 当touser为"@all"时忽略本参数
|
||||
*/
|
||||
private String toParty;
|
||||
/**
|
||||
* 指定接收消息的标签,标签ID列表,多个接收者用‘|’分隔,最多支持100个。
|
||||
* 当touser为"@all"时忽略本参数
|
||||
*/
|
||||
private String toTag;
|
||||
/**
|
||||
* 企业应用的id,整型。企业内部开发,可在应用的设置页面查看;第三方服务商,可通过接口 获取企业授权信息 获取该参数值
|
||||
*/
|
||||
private Integer agentId;
|
||||
/**
|
||||
* 消息类型
|
||||
* 文本消息: text
|
||||
* 图片消息: image
|
||||
* 语音消息: voice
|
||||
* 视频消息: video
|
||||
* 文件消息: file
|
||||
* 文本卡片消息: textcard
|
||||
* 图文消息: news
|
||||
* 图文消息: mpnews
|
||||
* markdown消息: markdown
|
||||
* 模板卡片消息: template_card
|
||||
*/
|
||||
private String msgType;
|
||||
/**
|
||||
* 消息内容,最长不超过2048个字节,超过将截断(支持id转译)
|
||||
*/
|
||||
private String content;
|
||||
/**
|
||||
* 媒体文件id,可以调用上传临时素材接口获取
|
||||
*/
|
||||
private String mediaId;
|
||||
/**
|
||||
* 图文消息缩略图的media_id, 可以通过素材管理接口获得。此处thumb_media_id即上传接口返回的media_id
|
||||
*/
|
||||
private String thumbMediaId;
|
||||
/**
|
||||
* 标题,不超过128个字节,超过会自动截断(支持id转译)
|
||||
*/
|
||||
private String title;
|
||||
/**
|
||||
* 描述,不超过512个字节,超过会自动截断(支持id转译)
|
||||
*/
|
||||
private String description;
|
||||
private String musicUrl;
|
||||
private String hqMusicUrl;
|
||||
/**
|
||||
* 表示是否是保密消息,默认为0;注意仅 mpnews 类型的消息支持safe值为2,其他消息类型不支持
|
||||
* 0表示可对外分享
|
||||
* 1表示不能分享且内容显示水印
|
||||
* 2表示仅限在企业内分享
|
||||
*/
|
||||
private String safe;
|
||||
/**
|
||||
* 点击后跳转的链接。最长2048字节,请确保包含了协议头(http/https)
|
||||
*/
|
||||
private String url;
|
||||
/**
|
||||
* 按钮文字。 默认为“详情”, 不超过4个文字,超过自动截断。
|
||||
*/
|
||||
private String btnTxt;
|
||||
/**
|
||||
* 图文消息,一个图文消息支持1到8条图文
|
||||
*/
|
||||
private List<NewArticle> articles = new ArrayList<>();
|
||||
/**
|
||||
* 图文消息,一个图文消息支持1到8条图文
|
||||
*/
|
||||
private List<MpnewsArticle> mpnewsArticles = new ArrayList<>();
|
||||
/**
|
||||
* 小程序appid,必须是与当前应用关联的小程序,appid和pagepath必须同时填写,填写后会忽略url字段
|
||||
*/
|
||||
private String appId;
|
||||
/**
|
||||
* 点击消息卡片后的小程序页面,最长1024个字节,仅限本小程序内的页面。该字段不填则消息点击后不跳转。
|
||||
*/
|
||||
private String page;
|
||||
/**
|
||||
* 是否放大第一个content_item
|
||||
*/
|
||||
private Boolean emphasisFirstItem;
|
||||
/**
|
||||
* 消息内容键值对,最多允许10个item
|
||||
*/
|
||||
private Map<String, String> contentItems;
|
||||
|
||||
/**
|
||||
@ -111,11 +184,17 @@ public class WxCpMessage implements Serializable {
|
||||
* 一级标题,建议不超过36个字
|
||||
*/
|
||||
private String mainTitleTitle;
|
||||
|
||||
/**
|
||||
* 标题辅助信息,建议不超过44个字
|
||||
*/
|
||||
private String mainTitleDesc;
|
||||
|
||||
/**
|
||||
* 左图右文样式,news_notice类型的卡片,card_image 和 image_text_area 两者必填一个字段,不可都不填
|
||||
*/
|
||||
private TemplateCardImageTextArea imageTextArea;
|
||||
|
||||
/**
|
||||
* 图文展示型的卡片必须有图片字段。
|
||||
* 图片的url.
|
||||
@ -176,6 +255,12 @@ public class WxCpMessage implements Serializable {
|
||||
*/
|
||||
private String cardActionPagepath;
|
||||
|
||||
/**
|
||||
* 按钮交互型卡片需指定。
|
||||
* button_selection
|
||||
*/
|
||||
private TemplateCardButtonSelection buttonSelection;
|
||||
|
||||
/**
|
||||
* 按钮交互型卡片需指定。
|
||||
* 按钮列表,该字段可为空数组,但有数据的话需确认对应字段是否必填,列表长度不超过6
|
||||
@ -553,6 +638,10 @@ public class WxCpMessage implements Serializable {
|
||||
template.add("main_title", mainTitle);
|
||||
}
|
||||
|
||||
if (this.getImageTextArea() != null) {
|
||||
template.add("image_text_area", this.getImageTextArea().toJson());
|
||||
}
|
||||
|
||||
if (StringUtils.isNotBlank(this.getCardImageUrl()) || this.getCardImageAspectRatio() != null) {
|
||||
JsonObject cardImage = new JsonObject();
|
||||
if (StringUtils.isNotBlank(this.getCardImageUrl())) {
|
||||
@ -629,6 +718,11 @@ public class WxCpMessage implements Serializable {
|
||||
template.add("card_action", cardAction);
|
||||
}
|
||||
|
||||
TemplateCardButtonSelection buttonSelection = this.getButtonSelection();
|
||||
if (null != buttonSelection) {
|
||||
template.add("button_selection", buttonSelection.toJson());
|
||||
}
|
||||
|
||||
List<TemplateCardButton> buttons = this.getButtons();
|
||||
if (null != buttons && !buttons.isEmpty()) {
|
||||
JsonArray btnJsonArray = new JsonArray();
|
||||
|
@ -99,6 +99,11 @@ public class TemplateCardBuilder extends BaseBuilder<TemplateCardBuilder> {
|
||||
*/
|
||||
private List<TemplateCardJump> jumps;
|
||||
|
||||
/**
|
||||
* 左图右文样式,news_notice类型的卡片,card_image 和 image_text_area 两者必填一个字段,不可都不填
|
||||
*/
|
||||
private TemplateCardImageTextArea imageTextArea;
|
||||
|
||||
/**
|
||||
* 整体卡片的点击跳转事件,text_notice必填本字段
|
||||
* 跳转事件类型,1 代表跳转url,2 代表打开小程序。text_notice卡片模版中该字段取值范围为[1,2]
|
||||
@ -124,6 +129,12 @@ public class TemplateCardBuilder extends BaseBuilder<TemplateCardBuilder> {
|
||||
*/
|
||||
private String taskId;
|
||||
|
||||
/**
|
||||
* 按钮交互型卡片需指定。
|
||||
* button_selection
|
||||
*/
|
||||
private TemplateCardButtonSelection buttonSelection;
|
||||
|
||||
/**
|
||||
* 按钮交互型卡片需指定。
|
||||
* 按钮列表,该字段可为空数组,但有数据的话需确认对应字段是否必填,列表长度不超过6
|
||||
@ -350,6 +361,17 @@ public class TemplateCardBuilder extends BaseBuilder<TemplateCardBuilder> {
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* image_text_area template card builder.
|
||||
*
|
||||
* @param imageTextArea the card image_text_area
|
||||
* @return the template card builder
|
||||
*/
|
||||
public TemplateCardBuilder imageTextArea(TemplateCardImageTextArea imageTextArea) {
|
||||
this.imageTextArea = imageTextArea;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Card action type template card builder.
|
||||
*
|
||||
@ -505,6 +527,7 @@ public class TemplateCardBuilder extends BaseBuilder<TemplateCardBuilder> {
|
||||
m.setActionMenuActionList(this.actionMenuActionList);
|
||||
m.setMainTitleTitle(this.mainTitleTitle);
|
||||
m.setMainTitleDesc(this.mainTitleDesc);
|
||||
m.setImageTextArea(this.imageTextArea);
|
||||
m.setCardImageUrl(this.cardImageUrl);
|
||||
m.setCardImageAspectRatio(this.cardImageAspectRatio);
|
||||
m.setEmphasisContentTitle(this.emphasisContentTitle);
|
||||
@ -518,6 +541,7 @@ public class TemplateCardBuilder extends BaseBuilder<TemplateCardBuilder> {
|
||||
m.setCardActionPagepath(this.cardActionPagepath);
|
||||
m.setCardActionUrl(this.cardActionUrl);
|
||||
m.setTaskId(this.taskId);
|
||||
m.setButtonSelection(this.buttonSelection);
|
||||
m.setButtons(this.buttons);
|
||||
m.setCheckboxMode(this.checkboxMode);
|
||||
m.setCheckboxQuestionKey(this.checkboxQuestionKey);
|
||||
|
@ -0,0 +1,58 @@
|
||||
package me.chanjar.weixin.cp.bean.templatecard;
|
||||
|
||||
import com.google.gson.JsonArray;
|
||||
import com.google.gson.JsonObject;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Builder;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author chenjie03
|
||||
* @version 1.0
|
||||
* @date 2022/11/4 11:54
|
||||
*/
|
||||
@Data
|
||||
@Builder
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
public class TemplateCardButtonSelection implements Serializable {
|
||||
private String questionKey;
|
||||
private String title;
|
||||
private String selectedId;
|
||||
private List<TemplateCardButtonSelectionOption> optionList;
|
||||
|
||||
/**
|
||||
* To json json object.
|
||||
*
|
||||
* @return the json object
|
||||
*/
|
||||
public JsonObject toJson() {
|
||||
JsonObject btnObject = new JsonObject();
|
||||
|
||||
if (StringUtils.isNotBlank(this.questionKey)) {
|
||||
btnObject.addProperty("question_key", this.questionKey);
|
||||
}
|
||||
if (StringUtils.isNotBlank(this.title)) {
|
||||
btnObject.addProperty("title", this.title);
|
||||
}
|
||||
if (StringUtils.isNotBlank(this.selectedId)) {
|
||||
btnObject.addProperty("selected_id", this.selectedId);
|
||||
}
|
||||
|
||||
if (this.optionList != null && this.optionList.size() > 0) {
|
||||
JsonArray optionJsonArray = new JsonArray();
|
||||
for (TemplateCardButtonSelectionOption jump : this.getOptionList()) {
|
||||
JsonObject tempObject = jump.toJson();
|
||||
optionJsonArray.add(tempObject);
|
||||
}
|
||||
btnObject.add("option_list", optionJsonArray);
|
||||
}
|
||||
return btnObject;
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,42 @@
|
||||
package me.chanjar.weixin.cp.bean.templatecard;
|
||||
|
||||
import com.google.gson.JsonObject;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Builder;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
/**
|
||||
* @author chenjie03
|
||||
* @version 1.0
|
||||
* @date 2022/11/4 11:57
|
||||
*/
|
||||
@Data
|
||||
@Builder
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
public class TemplateCardButtonSelectionOption implements Serializable {
|
||||
private String id;
|
||||
private String text;
|
||||
|
||||
|
||||
/**
|
||||
* To json json object.
|
||||
*
|
||||
* @return the json object
|
||||
*/
|
||||
public JsonObject toJson() {
|
||||
JsonObject btnObject = new JsonObject();
|
||||
|
||||
if (StringUtils.isNotBlank(this.id)) {
|
||||
btnObject.addProperty("id", this.id);
|
||||
}
|
||||
if (StringUtils.isNotBlank(this.text)) {
|
||||
btnObject.addProperty("text", this.text);
|
||||
}
|
||||
return btnObject;
|
||||
}
|
||||
}
|
@ -0,0 +1,53 @@
|
||||
package me.chanjar.weixin.cp.bean.templatecard;
|
||||
|
||||
import com.google.gson.JsonObject;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Builder;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
/**
|
||||
* @author chenjie03
|
||||
* @version 1.0
|
||||
* @date 2022/11/4 12:12
|
||||
*/
|
||||
@Data
|
||||
@Builder
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
public class TemplateCardImageTextArea implements Serializable {
|
||||
private Integer type;
|
||||
private String url;
|
||||
private String title;
|
||||
private String desc;
|
||||
private String imageUrl;
|
||||
|
||||
/**
|
||||
* To json json object.
|
||||
*
|
||||
* @return the json object
|
||||
*/
|
||||
public JsonObject toJson() {
|
||||
JsonObject btnObject = new JsonObject();
|
||||
|
||||
if (null != this.type) {
|
||||
btnObject.addProperty("type", this.type);
|
||||
}
|
||||
if (StringUtils.isNotBlank(this.url)) {
|
||||
btnObject.addProperty("url", this.url);
|
||||
}
|
||||
if (StringUtils.isNotBlank(this.title)) {
|
||||
btnObject.addProperty("title", this.title);
|
||||
}
|
||||
if (StringUtils.isNotBlank(this.desc)) {
|
||||
btnObject.addProperty("desc", this.desc);
|
||||
}
|
||||
if (StringUtils.isNotBlank(this.imageUrl)) {
|
||||
btnObject.addProperty("image_url", this.imageUrl);
|
||||
}
|
||||
return btnObject;
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user