Skip to content

Commit 6d6bd66

Browse files
committed
【企业微信】更新若干模板卡片消息的接口(对应 来源文字的颜色、卡片右上角更多操作按钮);更新按钮为不可点击状态;
1 parent 6390dea commit 6d6bd66

File tree

9 files changed

+200
-13
lines changed

9 files changed

+200
-13
lines changed

pom.xml

+25-5
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
<?xml version="1.0"?>
2-
<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd" xmlns="http://maven.apache.org/POM/4.0.0">
2+
<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
3+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"
4+
xmlns="http://maven.apache.org/POM/4.0.0">
35
<modelVersion>4.0.0</modelVersion>
46
<groupId>com.github.binarywang</groupId>
57
<artifactId>wx-java</artifactId>
@@ -92,6 +94,11 @@
9294
<email>[email protected]</email>
9395
<url>https://github.com/huangxm129</url>
9496
</developer>
97+
<developer>
98+
<name>xiaohe</name>
99+
<email>[email protected]</email>
100+
<url>https://github.com/xiaohe-53</url>
101+
</developer>
95102
</developers>
96103

97104
<scm>
@@ -155,7 +162,7 @@
155162
<dependency>
156163
<groupId>commons-codec</groupId>
157164
<artifactId>commons-codec</artifactId>
158-
<version>1.10</version>
165+
<version>1.15</version>
159166
</dependency>
160167
<dependency>
161168
<groupId>commons-io</groupId>
@@ -203,7 +210,7 @@
203210
<dependency>
204211
<groupId>ch.qos.logback</groupId>
205212
<artifactId>logback-classic</artifactId>
206-
<version>1.2.3</version>
213+
<version>1.2.10</version>
207214
<scope>test</scope>
208215
</dependency>
209216
<dependency>
@@ -302,7 +309,7 @@
302309
<dependency>
303310
<groupId>org.projectlombok</groupId>
304311
<artifactId>lombok</artifactId>
305-
<version>1.18.8</version>
312+
<version>1.18.22</version>
306313
<scope>provided</scope>
307314
</dependency>
308315
<dependency>
@@ -403,7 +410,7 @@
403410
<plugin>
404411
<groupId>org.apache.maven.plugins</groupId>
405412
<artifactId>maven-surefire-plugin</artifactId>
406-
<version>2.17</version>
413+
<version>3.0.0-M5</version>
407414
<configuration>
408415
<skip>true</skip>
409416
</configuration>
@@ -457,4 +464,17 @@
457464
</plugins>
458465
</build>
459466

467+
<repositories>
468+
<repository>
469+
<id>nexus-aliyun</id>
470+
<name>nexus-aliyun</name>
471+
<url>https://maven.aliyun.com/nexus/content/groups/public/</url>
472+
<releases>
473+
<enabled>true</enabled>
474+
</releases>
475+
<snapshots>
476+
<enabled>false</enabled>
477+
</snapshots>
478+
</repository>
479+
</repositories>
460480
</project>

weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/WxCpTaskCardService.java

+20-2
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
* <pre>
99
* 任务卡片管理接口.
1010
* Created by Jeff on 2019-05-16.
11+
* Updted by HeXiao on 2022-03-09.
1112
* </pre>
1213
*
1314
* @author <a href="https://github.com/domainname">Jeff</a>
@@ -23,9 +24,26 @@ public interface WxCpTaskCardService {
2324
* 注意: 这个方法使用WxCpConfigStorage里的agentId
2425
* </pre>
2526
*
26-
* @param userIds 企业的成员ID列表
27-
* @param taskId 任务卡片ID
27+
* @param userIds 企业的成员ID列表
28+
* @param taskId 任务卡片ID
2829
* @param replaceName 替换文案
2930
*/
3031
void update(List<String> userIds, String taskId, String replaceName) throws WxErrorException;
32+
33+
34+
/**
35+
* 更新按钮为不可点击状态
36+
* 详情请见https://developer.work.weixin.qq.com/document/path/94888#%E6%9B%B4%E6%96%B0%E6%8C%89%E9%92%AE%E4%B8%BA%E4%B8%8D%E5%8F%AF%E7%82%B9%E5%87%BB%E7%8A%B6%E6%80%81
37+
* @param userIds 企业的成员ID列表
38+
* @param partyIds 企业的部门ID列表
39+
* @param tagIds 企业的标签ID列表
40+
* @param atAll 更新整个任务接收人员
41+
* @param responseCode 更新卡片所需要消费的code,可通过发消息接口和回调接口返回值获取,一个code只能调用一次该接口,且只能在24小时内调用
42+
* @param replaceName 需要更新的按钮的文案
43+
* @throws WxErrorException
44+
*/
45+
void updateTemplateCardButton(List<String> userIds, List<Integer> partyIds,
46+
List<Integer> tagIds, Integer atAll, String responseCode,
47+
String replaceName) throws WxErrorException;
48+
3149
}

weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/impl/WxCpTaskCardServiceImpl.java

+21
Original file line numberDiff line numberDiff line change
@@ -38,4 +38,25 @@ public void update(List<String> userIds, String taskId, String replaceName) thro
3838
String url = this.mainService.getWxCpConfigStorage().getApiUrl(UPDATE_TASK_CARD);
3939
this.mainService.post(url, WxGsonBuilder.create().toJson(data));
4040
}
41+
42+
@Override
43+
public void updateTemplateCardButton(List<String> userIds, List<Integer> partyIds,
44+
List<Integer> tagIds, Integer atAll,
45+
String responseCode, String replaceName) throws WxErrorException {
46+
Integer agentId = this.mainService.getWxCpConfigStorage().getAgentId();
47+
Map<String, Object> data = new HashMap<>(7);
48+
data.put("userids", userIds);
49+
data.put("partyids", partyIds);
50+
data.put("tagids", tagIds);
51+
data.put("atall", atAll);
52+
data.put("agentid", agentId);
53+
data.put("response_code", responseCode);
54+
Map<String, String> btnMap = new HashMap<>();
55+
btnMap.put("replace_name", replaceName);
56+
data.put("button", btnMap);
57+
58+
String url = this.mainService.getWxCpConfigStorage().getApiUrl(UPDATE_TEMPLATE_CARD);
59+
this.mainService.post(url, WxGsonBuilder.create().toJson(data));
60+
61+
}
4162
}

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

+28
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,21 @@ public class WxCpMessage implements Serializable {
9292
*/
9393
private String sourceDesc;
9494

95+
/**
96+
* 来源文字的颜色,目前支持:0(默认) 灰色,1 黑色,2 红色,3 绿色
97+
*/
98+
private Integer sourceDescColor;
99+
100+
/**
101+
* 更多操作界面的描述
102+
*/
103+
private String actionMenuDesc;
104+
105+
/**
106+
* 操作列表,列表长度取值范围为 [1, 3]
107+
*/
108+
private List<ActionMenuItem> actionMenuActionList;
109+
95110
/**
96111
* 一级标题,建议不超过36个字
97112
*/
@@ -482,9 +497,22 @@ private void handleMsgType(JsonObject messageJson) {
482497
if (StringUtils.isNotBlank(this.getSourceDesc())) {
483498
source.addProperty("desc", this.getSourceDesc());
484499
}
500+
source.addProperty("desc_color", this.getSourceDescColor());
485501
template.add("source", source);
486502
}
487503

504+
if (StringUtils.isNotBlank(this.getActionMenuDesc())) {
505+
JsonObject action_menu = new JsonObject();
506+
action_menu.addProperty("desc", this.getActionMenuDesc());
507+
JsonArray actionList = new JsonArray();
508+
List<ActionMenuItem> actionMenuItemList = this.getActionMenuActionList();
509+
for (ActionMenuItem actionItemI : actionMenuItemList) {
510+
actionList.add(actionItemI.toJson());
511+
}
512+
action_menu.add("action_list", actionList);
513+
template.add("action_menu", action_menu);
514+
}
515+
488516
if (StringUtils.isNotBlank(this.getMainTitleTitle()) || StringUtils.isNotBlank(this.getMainTitleDesc())) {
489517
JsonObject mainTitle = new JsonObject();
490518
if (StringUtils.isNotBlank(this.getMainTitleTitle())) {

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

+33
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,21 @@ public class TemplateCardBuilder extends BaseBuilder<TemplateCardBuilder> {
3636
*/
3737
private String sourceDesc;
3838

39+
/**
40+
* 来源文字的颜色,目前支持:0(默认) 灰色,1 黑色,2 红色,3 绿色
41+
*/
42+
private Integer sourceDescColor;
43+
44+
/**
45+
* 更多操作界面的描述
46+
*/
47+
private String actionMenuDesc;
48+
49+
/**
50+
* 操作列表,列表长度取值范围为 [1, 3]
51+
*/
52+
private List<ActionMenuItem> actionMenuActionList;
53+
3954
/**
4055
* 一级标题,建议不超过36个字
4156
*/
@@ -172,6 +187,16 @@ public TemplateCardBuilder cardImageAspectRatio(Float cardImageAspectRatio) {
172187
return this;
173188
}
174189

190+
public TemplateCardBuilder actionMenuDesc(String actionMenuDesc) {
191+
this.actionMenuDesc = actionMenuDesc;
192+
return this;
193+
}
194+
195+
public TemplateCardBuilder actionMenuActionList(List<ActionMenuItem> actionMenuItemList) {
196+
this.actionMenuActionList = actionMenuItemList;
197+
return this;
198+
}
199+
175200
public TemplateCardBuilder sourceIconUrl(String sourceIconUrl) {
176201
this.sourceIconUrl = sourceIconUrl;
177202
return this;
@@ -182,6 +207,11 @@ public TemplateCardBuilder sourceDesc(String sourceDesc) {
182207
return this;
183208
}
184209

210+
public TemplateCardBuilder sourceDescColor(Integer sourceDescColor) {
211+
this.sourceDescColor = sourceDescColor;
212+
return this;
213+
}
214+
185215
public TemplateCardBuilder mainTitleTitle(String mainTitleTitle) {
186216
this.mainTitleTitle = mainTitleTitle;
187217
return this;
@@ -294,6 +324,9 @@ public WxCpMessage build() {
294324
m.setCardType(this.cardType);
295325
m.setSourceIconUrl(this.sourceIconUrl);
296326
m.setSourceDesc(this.sourceDesc);
327+
m.setSourceDescColor(this.sourceDescColor);
328+
m.setActionMenuDesc(this.actionMenuDesc);
329+
m.setActionMenuActionList(this.actionMenuActionList);
297330
m.setMainTitleTitle(this.mainTitleTitle);
298331
m.setMainTitleDesc(this.mainTitleDesc);
299332
m.setCardImageUrl(this.cardImageUrl);
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
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+
9+
import java.io.Serializable;
10+
11+
/**
12+
* @author xiaohe
13+
* @date 2022-03-06
14+
*/
15+
@Data
16+
@Builder
17+
@NoArgsConstructor
18+
@AllArgsConstructor
19+
public class ActionMenuItem implements Serializable {
20+
private static final long serialVersionUID = 400885585614100693L;
21+
22+
/**
23+
* 操作的描述文案
24+
*/
25+
private String text;
26+
27+
/**
28+
* 按钮key值,用户点击后,会产生回调事件将本参数作为EventKey返回,回调事件会带上该key值,最长支持1024字节,不可重复
29+
*/
30+
private String key;
31+
32+
public JsonObject toJson() {
33+
JsonObject btnObject = new JsonObject();
34+
btnObject.addProperty("text", this.getText());
35+
btnObject.addProperty("key", this.getKey());
36+
return btnObject;
37+
}
38+
39+
}

weixin-java-cp/src/main/java/me/chanjar/weixin/cp/bean/templatecard/HorizontalContent.java

+8
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,11 @@ public class HorizontalContent implements Serializable {
4444
*/
4545
private String media_id;
4646

47+
/**
48+
* 成员详情的userid,horizontal_content_list.type是3时必填
49+
*/
50+
private String userid;
51+
4752
public JsonObject toJson() {
4853
JsonObject hContentJson = new JsonObject();
4954

@@ -61,6 +66,9 @@ public JsonObject toJson() {
6166
if (StringUtils.isNotBlank(this.getMedia_id())) {
6267
hContentJson.addProperty("media_id", this.getMedia_id());
6368
}
69+
if (StringUtils.isNotBlank(this.getUserid())) {
70+
hContentJson.addProperty("userid", this.getUserid());
71+
}
6472
return hContentJson;
6573
}
6674

weixin-java-cp/src/main/java/me/chanjar/weixin/cp/constant/WxCpApiPathConsts.java

+1
Original file line numberDiff line numberDiff line change
@@ -187,6 +187,7 @@ interface Tag {
187187

188188
interface TaskCard {
189189
String UPDATE_TASK_CARD = "/cgi-bin/message/update_taskcard";
190+
String UPDATE_TEMPLATE_CARD = "/cgi-bin/message/update_template_card";
190191
}
191192

192193
interface Tp {

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

+25-6
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,12 @@ public void TestTemplateCardBuilder_text_notice() {
166166
.value("企业微信.apk")
167167
.media_id("文件的media_id")
168168
.build();
169+
HorizontalContent hContent4 = HorizontalContent.builder()
170+
.type(3)
171+
.keyname("员工信息")
172+
.value("点击查看")
173+
.userid("zhangsan")
174+
.build();
169175

170176
TemplateCardJump jump1 = TemplateCardJump.builder()
171177
.type(1)
@@ -178,25 +184,39 @@ public void TestTemplateCardBuilder_text_notice() {
178184
.appid("小程序的appid")
179185
.pagepath("/index.html")
180186
.build();
181-
QuoteArea quoteArea=QuoteArea.builder()
187+
QuoteArea quoteArea = QuoteArea.builder()
182188
.type(1)
183189
.title("引用文献标题")
184190
.appid("小程序的appid")
185191
.pagepath("/index.html")
186192
.url("https://work.weixin.qq.com")
187193
.quoteText("引用文献样式的引用文案")
188194
.build();
195+
ActionMenuItem action1 = ActionMenuItem.builder()
196+
.text("接受推送")
197+
.key("A")
198+
.build();
199+
ActionMenuItem action2 = ActionMenuItem.builder()
200+
.text("不再推送")
201+
.key("B")
202+
.build();
189203
WxCpMessage reply = WxCpMessage.TEMPLATECARD().toUser("OPENID")
204+
.toParty("PartyID1 | PartyID2")
205+
.toTag("TagID1 | TagID2")
190206
.agentId(1000002)
191207
.cardType(WxConsts.TemplateCardType.TEXT_NOTICE)
208+
.taskId("task_id")
192209
.sourceIconUrl("图片的url")
193210
.sourceDesc("企业微信")
211+
.sourceDescColor(1)
212+
.actionMenuDesc("卡片副交互辅助文本说明")
213+
.actionMenuActionList(Arrays.asList(action1, action2))
194214
.mainTitleTitle("欢迎使用企业微信")
195215
.mainTitleDesc("您的好友正在邀请您加入企业微信")
196216
.emphasisContentTitle("100")
197217
.emphasisContentDesc("核心数据")
198218
.subTitleText("下载企业微信还能抢红包!")
199-
.horizontalContents(Arrays.asList(hContent1,hContent2,hContent3))
219+
.horizontalContents(Arrays.asList(hContent1, hContent2, hContent3, hContent4))
200220
.jumps(Arrays.asList(jump1,jump2))
201221
.cardActionType(2)
202222
.cardActionAppid("小程序的appid")
@@ -209,8 +229,7 @@ public void TestTemplateCardBuilder_text_notice() {
209229
reply.setDuplicateCheckInterval(1800);
210230
// System.out.println(reply.toJson());
211231
assertThat(reply.toJson())
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\":\"引用文献样式的引用文案\"}}}");
213-
232+
.isEqualTo("{\"agentid\":1000002,\"touser\":\"OPENID\",\"msgtype\":\"template_card\",\"toparty\":\"PartyID1 | PartyID2\",\"totag\":\"TagID1 | TagID2\",\"duplicate_check_interval\":1800,\"template_card\":{\"card_type\":\"text_notice\",\"source\":{\"icon_url\":\"图片的url\",\"desc\":\"企业微信\",\"desc_color\":1},\"action_menu\":{\"desc\":\"卡片副交互辅助文本说明\",\"action_list\":[{\"text\":\"接受推送\",\"key\":\"A\"},{\"text\":\"不再推送\",\"key\":\"B\"}]},\"main_title\":{\"title\":\"欢迎使用企业微信\",\"desc\":\"您的好友正在邀请您加入企业微信\"},\"emphasis_content\":{\"title\":\"100\",\"desc\":\"核心数据\"},\"sub_title_text\":\"下载企业微信还能抢红包!\",\"task_id\":\"task_id\",\"horizontal_content_list\":[{\"keyname\":\"邀请人\",\"value\":\"张三\"},{\"type\":1,\"keyname\":\"企业微信官网\",\"value\":\"点击访问\",\"url\":\"https://work.weixin.qq.com\"},{\"type\":2,\"keyname\":\"企业微信下载\",\"value\":\"企业微信.apk\",\"media_id\":\"文件的media_id\"},{\"type\":3,\"keyname\":\"员工信息\",\"value\":\"点击查看\",\"userid\":\"zhangsan\"}],\"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\":\"引用文献样式的引用文案\"}}}");
214233
}
215234

216235
/**
@@ -404,13 +423,13 @@ public void TestTemplateCardBuilder_multiple_interaction() {
404423
.question_key("question_key1")
405424
.title("选择器标签1")
406425
.selected_id("selection_id1")
407-
.options(Arrays.asList(option1,option2))
426+
.options(Arrays.asList(option1, option2))
408427
.build();
409428
MultipleSelect mSelect2 = MultipleSelect.builder()
410429
.question_key("question_key2")
411430
.title("选择器标签2")
412431
.selected_id("selection_id3")
413-
.options(Arrays.asList(option3,option4))
432+
.options(Arrays.asList(option3, option4))
414433
.build();
415434

416435

0 commit comments

Comments
 (0)