Skip to content

Commit 0c35f77

Browse files
authored
🎨 #2481 【企业微信】发送应用消息接口里的文本通知型的模板卡片消息增加引用文本字段
1 parent fd8e02a commit 0c35f77

File tree

4 files changed

+106
-2
lines changed

4 files changed

+106
-2
lines changed

weixin-java-cp/src/main/java/me/chanjar/weixin/cp/bean/message/WxCpMessage.java

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -199,6 +199,11 @@ public class WxCpMessage implements Serializable {
199199
*/
200200
private List<MultipleSelect> selects;
201201

202+
/**
203+
* 引用文献样式
204+
*/
205+
private QuoteArea quoteArea;
206+
202207
/**
203208
* 获得文本消息builder.
204209
*/
@@ -606,6 +611,12 @@ private void handleMsgType(JsonObject messageJson) {
606611
template.add("select_list", selectJsonArray);
607612
}
608613

614+
QuoteArea quoteArea = this.getQuoteArea();
615+
if (null != quoteArea){
616+
JsonObject quoteAreaJson = quoteArea.toJson();
617+
template.add("quote_area",quoteAreaJson);
618+
}
619+
609620
messageJson.add("template_card", template);
610621
break;
611622
}

weixin-java-cp/src/main/java/me/chanjar/weixin/cp/bean/messagebuilder/TemplateCardBuilder.java

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,11 @@ public class TemplateCardBuilder extends BaseBuilder<TemplateCardBuilder>{
146146
*/
147147
private List<MultipleSelect> selects;
148148

149+
/**
150+
* 引用文献样式
151+
*/
152+
private QuoteArea quoteArea;
153+
149154

150155
public TemplateCardBuilder() {
151156
this.msgType = WxConsts.KefuMsgType.TEMPLATE_CARD;
@@ -266,6 +271,11 @@ public TemplateCardBuilder selects(List<MultipleSelect> selects) {
266271
return this;
267272
}
268273

274+
public TemplateCardBuilder quoteArea(QuoteArea quoteArea) {
275+
this.quoteArea = quoteArea;
276+
return this;
277+
}
278+
269279
@Override
270280
public WxCpMessage build() {
271281
WxCpMessage m = super.build();
@@ -295,6 +305,7 @@ public WxCpMessage build() {
295305
m.setSubmit_button_text(this.submit_button_text);
296306
m.setSubmit_button_key(this.submit_button_key);
297307
m.setSelects(this.selects);
308+
m.setQuoteArea(this.quoteArea);
298309
return m;
299310
}
300311
}
Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
package me.chanjar.weixin.cp.bean.templatecard;
2+
3+
import com.google.gson.JsonObject;
4+
import lombok.AllArgsConstructor;
5+
import lombok.Builder;
6+
import lombok.Data;
7+
import lombok.NoArgsConstructor;
8+
import org.apache.commons.lang3.StringUtils;
9+
10+
import java.io.Serializable;
11+
12+
/**
13+
* 引用文献样式
14+
*
15+
* @author zp
16+
* @date 2022/1/2
17+
*/
18+
@Data
19+
@Builder
20+
@NoArgsConstructor
21+
@AllArgsConstructor
22+
public class QuoteArea implements Serializable {
23+
24+
private static final long serialVersionUID = -2209656515382964356L;
25+
26+
/**
27+
* 非必填 引用文献样式区域点击事件,0或不填代表没有点击事件,1 代表跳转url,2 代表跳转小程序
28+
*/
29+
private Integer type;
30+
/**
31+
* 点击跳转的url,quote_area.type是1时必填
32+
*/
33+
private String url;
34+
/**
35+
* 点击跳转的小程序的appid,必须是与当前应用关联的小程序,quote_area.type是2时必填
36+
*/
37+
private String appid;
38+
/**
39+
* 点击跳转的小程序的pagepath,quote_area.type是2时选填
40+
*/
41+
private String pagepath;
42+
/**
43+
* 引用文献样式的标题
44+
*/
45+
private String title;
46+
/**
47+
* 引用文献样式的引用文案
48+
*/
49+
private String quoteText;
50+
51+
public JsonObject toJson() {
52+
JsonObject quoteAreaJson = new JsonObject();
53+
if (null != this.getType()) {
54+
quoteAreaJson.addProperty("type", this.getType());
55+
}
56+
if (StringUtils.isNotBlank(this.getUrl())) {
57+
quoteAreaJson.addProperty("url", this.getUrl());
58+
}
59+
if (StringUtils.isNotBlank(this.getAppid())) {
60+
quoteAreaJson.addProperty("appid", this.getAppid());
61+
}
62+
if (StringUtils.isNotBlank(this.getPagepath())) {
63+
quoteAreaJson.addProperty("pagepath", this.getPagepath());
64+
}
65+
if (StringUtils.isNotBlank(this.getTitle())) {
66+
quoteAreaJson.addProperty("title", this.getTitle());
67+
}
68+
if (StringUtils.isNotBlank(this.getQuoteText())) {
69+
quoteAreaJson.addProperty("quote_text", this.getQuoteText());
70+
}
71+
return quoteAreaJson;
72+
}
73+
74+
}

weixin-java-cp/src/test/java/me/chanjar/weixin/cp/bean/message/WxCpMessageTest.java

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -178,7 +178,14 @@ public void TestTemplateCardBuilder_text_notice() {
178178
.appid("小程序的appid")
179179
.pagepath("/index.html")
180180
.build();
181-
181+
QuoteArea quoteArea=QuoteArea.builder()
182+
.type(1)
183+
.title("引用文献标题")
184+
.appid("小程序的appid")
185+
.pagepath("/index.html")
186+
.url("https://work.weixin.qq.com")
187+
.quoteText("引用文献样式的引用文案")
188+
.build();
182189
WxCpMessage reply = WxCpMessage.TEMPLATECARD().toUser("OPENID")
183190
.agentId(1000002)
184191
.card_type(WxConsts.TemplateCardType.TEXT_NOTICE)
@@ -195,13 +202,14 @@ public void TestTemplateCardBuilder_text_notice() {
195202
.card_action_appid("小程序的appid")
196203
.card_action_url("https://work.weixin.qq.com")
197204
.card_action_pagepath("/index.html")
205+
.quoteArea(quoteArea)
198206
.build();
199207
reply.setEnableIdTrans(false);
200208
reply.setEnableDuplicateCheck(false);
201209
reply.setDuplicateCheckInterval(1800);
202210
// System.out.println(reply.toJson());
203211
assertThat(reply.toJson())
204-
.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\"}}}");
212+
.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\":\"引用文献样式的引用文案\"}}}");
205213

206214
}
207215

0 commit comments

Comments
 (0)