🎨 #2481 【企业微信】发送应用消息接口里的文本通知型的模板卡片消息增加引用文本字段

This commit is contained in:
zp961466717 2022-01-03 23:09:27 +08:00 committed by GitHub
parent fd8e02a81a
commit 0c35f778db
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 106 additions and 2 deletions

View File

@ -199,6 +199,11 @@ public class WxCpMessage implements Serializable {
*/
private List<MultipleSelect> selects;
/**
* 引用文献样式
*/
private QuoteArea quoteArea;
/**
* 获得文本消息builder.
*/
@ -606,6 +611,12 @@ public class WxCpMessage implements Serializable {
template.add("select_list", selectJsonArray);
}
QuoteArea quoteArea = this.getQuoteArea();
if (null != quoteArea){
JsonObject quoteAreaJson = quoteArea.toJson();
template.add("quote_area",quoteAreaJson);
}
messageJson.add("template_card", template);
break;
}

View File

@ -146,6 +146,11 @@ public class TemplateCardBuilder extends BaseBuilder<TemplateCardBuilder>{
*/
private List<MultipleSelect> selects;
/**
* 引用文献样式
*/
private QuoteArea quoteArea;
public TemplateCardBuilder() {
this.msgType = WxConsts.KefuMsgType.TEMPLATE_CARD;
@ -266,6 +271,11 @@ public class TemplateCardBuilder extends BaseBuilder<TemplateCardBuilder>{
return this;
}
public TemplateCardBuilder quoteArea(QuoteArea quoteArea) {
this.quoteArea = quoteArea;
return this;
}
@Override
public WxCpMessage build() {
WxCpMessage m = super.build();
@ -295,6 +305,7 @@ public class TemplateCardBuilder extends BaseBuilder<TemplateCardBuilder>{
m.setSubmit_button_text(this.submit_button_text);
m.setSubmit_button_key(this.submit_button_key);
m.setSelects(this.selects);
m.setQuoteArea(this.quoteArea);
return m;
}
}

View File

@ -0,0 +1,74 @@
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 zp
* @date 2022/1/2
*/
@Data
@Builder
@NoArgsConstructor
@AllArgsConstructor
public class QuoteArea implements Serializable {
private static final long serialVersionUID = -2209656515382964356L;
/**
* 非必填 引用文献样式区域点击事件0或不填代表没有点击事件1 代表跳转url2 代表跳转小程序
*/
private Integer type;
/**
* 点击跳转的urlquote_area.type是1时必填
*/
private String url;
/**
* 点击跳转的小程序的appid必须是与当前应用关联的小程序quote_area.type是2时必填
*/
private String appid;
/**
* 点击跳转的小程序的pagepathquote_area.type是2时选填
*/
private String pagepath;
/**
* 引用文献样式的标题
*/
private String title;
/**
* 引用文献样式的引用文案
*/
private String quoteText;
public JsonObject toJson() {
JsonObject quoteAreaJson = new JsonObject();
if (null != this.getType()) {
quoteAreaJson.addProperty("type", this.getType());
}
if (StringUtils.isNotBlank(this.getUrl())) {
quoteAreaJson.addProperty("url", this.getUrl());
}
if (StringUtils.isNotBlank(this.getAppid())) {
quoteAreaJson.addProperty("appid", this.getAppid());
}
if (StringUtils.isNotBlank(this.getPagepath())) {
quoteAreaJson.addProperty("pagepath", this.getPagepath());
}
if (StringUtils.isNotBlank(this.getTitle())) {
quoteAreaJson.addProperty("title", this.getTitle());
}
if (StringUtils.isNotBlank(this.getQuoteText())) {
quoteAreaJson.addProperty("quote_text", this.getQuoteText());
}
return quoteAreaJson;
}
}

View File

@ -178,7 +178,14 @@ public class WxCpMessageTest {
.appid("小程序的appid")
.pagepath("/index.html")
.build();
QuoteArea quoteArea=QuoteArea.builder()
.type(1)
.title("引用文献标题")
.appid("小程序的appid")
.pagepath("/index.html")
.url("https://work.weixin.qq.com")
.quoteText("引用文献样式的引用文案")
.build();
WxCpMessage reply = WxCpMessage.TEMPLATECARD().toUser("OPENID")
.agentId(1000002)
.card_type(WxConsts.TemplateCardType.TEXT_NOTICE)
@ -195,13 +202,14 @@ public class WxCpMessageTest {
.card_action_appid("小程序的appid")
.card_action_url("https://work.weixin.qq.com")
.card_action_pagepath("/index.html")
.quoteArea(quoteArea)
.build();
reply.setEnableIdTrans(false);
reply.setEnableDuplicateCheck(false);
reply.setDuplicateCheckInterval(1800);
// System.out.println(reply.toJson());
assertThat(reply.toJson())
.isEqualTo("{\"agentid\":1000002,\"touser\":\"OPENID\",\"msgtype\":\"template_card\",\"duplicate_check_interval\":1800,\"template_card\":{\"card_type\":\"text_notice\",\"source\":{\"icon_url\":\"图片的url\",\"desc\":\"企业微信\"},\"main_title\":{\"title\":\"欢迎使用企业微信\",\"desc\":\"您的好友正在邀请您加入企业微信\"},\"emphasis_content\":{\"title\":\"100\",\"desc\":\"核心数据\"},\"sub_title_text\":\"下载企业微信还能抢红包!\",\"horizontal_content_list\":[{\"keyname\":\"邀请人\",\"value\":\"张三\"},{\"type\":1,\"keyname\":\"企业微信官网\",\"value\":\"点击访问\",\"url\":\"https://work.weixin.qq.com\"},{\"type\":2,\"keyname\":\"企业微信下载\",\"value\":\"企业微信.apk\",\"media_id\":\"文件的media_id\"}],\"jump_list\":[{\"type\":1,\"title\":\"企业微信官网\",\"url\":\"https://work.weixin.qq.com\"},{\"type\":2,\"title\":\"跳转小程序\",\"appid\":\"小程序的appid\",\"pagepath\":\"/index.html\"}],\"card_action\":{\"type\":2,\"url\":\"https://work.weixin.qq.com\",\"appid\":\"小程序的appid\",\"pagepath\":\"/index.html\"}}}");
.isEqualTo("{\"agentid\":1000002,\"touser\":\"OPENID\",\"msgtype\":\"template_card\",\"duplicate_check_interval\":1800,\"template_card\":{\"card_type\":\"text_notice\",\"source\":{\"icon_url\":\"图片的url\",\"desc\":\"企业微信\"},\"main_title\":{\"title\":\"欢迎使用企业微信\",\"desc\":\"您的好友正在邀请您加入企业微信\"},\"emphasis_content\":{\"title\":\"100\",\"desc\":\"核心数据\"},\"sub_title_text\":\"下载企业微信还能抢红包!\",\"horizontal_content_list\":[{\"keyname\":\"邀请人\",\"value\":\"张三\"},{\"type\":1,\"keyname\":\"企业微信官网\",\"value\":\"点击访问\",\"url\":\"https://work.weixin.qq.com\"},{\"type\":2,\"keyname\":\"企业微信下载\",\"value\":\"企业微信.apk\",\"media_id\":\"文件的media_id\"}],\"jump_list\":[{\"type\":1,\"title\":\"企业微信官网\",\"url\":\"https://work.weixin.qq.com\"},{\"type\":2,\"title\":\"跳转小程序\",\"appid\":\"小程序的appid\",\"pagepath\":\"/index.html\"}],\"card_action\":{\"type\":2,\"url\":\"https://work.weixin.qq.com\",\"appid\":\"小程序的appid\",\"pagepath\":\"/index.html\"},\"quote_area\":{\"type\":1,\"url\":\"https://work.weixin.qq.com\",\"appid\":\"小程序的appid\",\"pagepath\":\"/index.html\",\"title\":\"引用文献标题\",\"quote_text\":\"引用文献样式的引用文案\"}}}");
}