mirror of
https://gitee.com/binary/weixin-java-tools.git
synced 2025-06-28 13:16:19 +08:00
🎨 #2481 【企业微信】发送应用消息接口里的文本通知型的模板卡片消息增加引用文本字段
This commit is contained in:
parent
fd8e02a81a
commit
0c35f778db
@ -199,6 +199,11 @@ public class WxCpMessage implements Serializable {
|
|||||||
*/
|
*/
|
||||||
private List<MultipleSelect> selects;
|
private List<MultipleSelect> selects;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 引用文献样式
|
||||||
|
*/
|
||||||
|
private QuoteArea quoteArea;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 获得文本消息builder.
|
* 获得文本消息builder.
|
||||||
*/
|
*/
|
||||||
@ -606,6 +611,12 @@ public class WxCpMessage implements Serializable {
|
|||||||
template.add("select_list", selectJsonArray);
|
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);
|
messageJson.add("template_card", template);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -146,6 +146,11 @@ public class TemplateCardBuilder extends BaseBuilder<TemplateCardBuilder>{
|
|||||||
*/
|
*/
|
||||||
private List<MultipleSelect> selects;
|
private List<MultipleSelect> selects;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 引用文献样式
|
||||||
|
*/
|
||||||
|
private QuoteArea quoteArea;
|
||||||
|
|
||||||
|
|
||||||
public TemplateCardBuilder() {
|
public TemplateCardBuilder() {
|
||||||
this.msgType = WxConsts.KefuMsgType.TEMPLATE_CARD;
|
this.msgType = WxConsts.KefuMsgType.TEMPLATE_CARD;
|
||||||
@ -266,6 +271,11 @@ public class TemplateCardBuilder extends BaseBuilder<TemplateCardBuilder>{
|
|||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public TemplateCardBuilder quoteArea(QuoteArea quoteArea) {
|
||||||
|
this.quoteArea = quoteArea;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public WxCpMessage build() {
|
public WxCpMessage build() {
|
||||||
WxCpMessage m = super.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_text(this.submit_button_text);
|
||||||
m.setSubmit_button_key(this.submit_button_key);
|
m.setSubmit_button_key(this.submit_button_key);
|
||||||
m.setSelects(this.selects);
|
m.setSelects(this.selects);
|
||||||
|
m.setQuoteArea(this.quoteArea);
|
||||||
return m;
|
return m;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -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 代表跳转url,2 代表跳转小程序
|
||||||
|
*/
|
||||||
|
private Integer type;
|
||||||
|
/**
|
||||||
|
* 点击跳转的url,quote_area.type是1时必填
|
||||||
|
*/
|
||||||
|
private String url;
|
||||||
|
/**
|
||||||
|
* 点击跳转的小程序的appid,必须是与当前应用关联的小程序,quote_area.type是2时必填
|
||||||
|
*/
|
||||||
|
private String appid;
|
||||||
|
/**
|
||||||
|
* 点击跳转的小程序的pagepath,quote_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;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -178,7 +178,14 @@ public class WxCpMessageTest {
|
|||||||
.appid("小程序的appid")
|
.appid("小程序的appid")
|
||||||
.pagepath("/index.html")
|
.pagepath("/index.html")
|
||||||
.build();
|
.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")
|
WxCpMessage reply = WxCpMessage.TEMPLATECARD().toUser("OPENID")
|
||||||
.agentId(1000002)
|
.agentId(1000002)
|
||||||
.card_type(WxConsts.TemplateCardType.TEXT_NOTICE)
|
.card_type(WxConsts.TemplateCardType.TEXT_NOTICE)
|
||||||
@ -195,13 +202,14 @@ public class WxCpMessageTest {
|
|||||||
.card_action_appid("小程序的appid")
|
.card_action_appid("小程序的appid")
|
||||||
.card_action_url("https://work.weixin.qq.com")
|
.card_action_url("https://work.weixin.qq.com")
|
||||||
.card_action_pagepath("/index.html")
|
.card_action_pagepath("/index.html")
|
||||||
|
.quoteArea(quoteArea)
|
||||||
.build();
|
.build();
|
||||||
reply.setEnableIdTrans(false);
|
reply.setEnableIdTrans(false);
|
||||||
reply.setEnableDuplicateCheck(false);
|
reply.setEnableDuplicateCheck(false);
|
||||||
reply.setDuplicateCheckInterval(1800);
|
reply.setDuplicateCheckInterval(1800);
|
||||||
// System.out.println(reply.toJson());
|
// System.out.println(reply.toJson());
|
||||||
assertThat(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\":\"引用文献样式的引用文案\"}}}");
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user