Skip to content

企业微信官方模板卡片消息-文本通知型 新增加引用文本字段 #2481

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Jan 3, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,11 @@ public class WxCpMessage implements Serializable {
*/
private List<MultipleSelect> selects;

/**
* 引用文献样式
*/
private QuoteArea quoteArea;

/**
* 获得文本消息builder.
*/
Expand Down Expand Up @@ -606,6 +611,12 @@ private void handleMsgType(JsonObject messageJson) {
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;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -266,6 +271,11 @@ public TemplateCardBuilder selects(List<MultipleSelect> selects) {
return this;
}

public TemplateCardBuilder quoteArea(QuoteArea quoteArea) {
this.quoteArea = quoteArea;
return this;
}

@Override
public WxCpMessage build() {
WxCpMessage m = super.build();
Expand Down Expand Up @@ -295,6 +305,7 @@ public WxCpMessage build() {
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;
}
}
Original file line number Diff line number Diff line change
@@ -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;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,14 @@ public void TestTemplateCardBuilder_text_notice() {
.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)
Expand All @@ -195,13 +202,14 @@ public void TestTemplateCardBuilder_text_notice() {
.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\":\"引用文献样式的引用文案\"}}}");

}

Expand Down