1
0
mirror of synced 2025-12-22 00:48:00 +08:00

🎨 #2632【企业微信】完善模板卡片消息接口部分参数

This commit is contained in:
xiaohe-53
2022-05-05 11:42:44 +08:00
committed by GitHub
parent 303a0ea155
commit 946f693bd0
9 changed files with 182 additions and 9 deletions

View File

@@ -8,6 +8,7 @@ import java.util.List;
* <pre>
* 任务卡片管理接口.
* Created by Jeff on 2019-05-16.
* Updted by HeXiao on 2022-03-09.
* </pre>
*
* @author <a href="https://github.com/domainname">Jeff</a>
@@ -23,9 +24,26 @@ public interface WxCpTaskCardService {
* 注意: 这个方法使用WxCpConfigStorage里的agentId
* </pre>
*
* @param userIds 企业的成员ID列表
* @param taskId 任务卡片ID
* @param userIds 企业的成员ID列表
* @param taskId 任务卡片ID
* @param replaceName 替换文案
*/
void update(List<String> userIds, String taskId, String replaceName) throws WxErrorException;
/**
* 更新按钮为不可点击状态
* 详情请见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
* @param userIds 企业的成员ID列表
* @param partyIds 企业的部门ID列表
* @param tagIds 企业的标签ID列表
* @param atAll 更新整个任务接收人员
* @param responseCode 更新卡片所需要消费的code可通过发消息接口和回调接口返回值获取一个code只能调用一次该接口且只能在24小时内调用
* @param replaceName 需要更新的按钮的文案
* @throws WxErrorException
*/
void updateTemplateCardButton(List<String> userIds, List<Integer> partyIds,
List<Integer> tagIds, Integer atAll, String responseCode,
String replaceName) throws WxErrorException;
}

View File

@@ -38,4 +38,25 @@ public class WxCpTaskCardServiceImpl implements WxCpTaskCardService {
String url = this.mainService.getWxCpConfigStorage().getApiUrl(UPDATE_TASK_CARD);
this.mainService.post(url, WxGsonBuilder.create().toJson(data));
}
@Override
public void updateTemplateCardButton(List<String> userIds, List<Integer> partyIds,
List<Integer> tagIds, Integer atAll,
String responseCode, String replaceName) throws WxErrorException {
Integer agentId = this.mainService.getWxCpConfigStorage().getAgentId();
Map<String, Object> data = new HashMap<>(7);
data.put("userids", userIds);
data.put("partyids", partyIds);
data.put("tagids", tagIds);
data.put("atall", atAll);
data.put("agentid", agentId);
data.put("response_code", responseCode);
Map<String, String> btnMap = new HashMap<>();
btnMap.put("replace_name", replaceName);
data.put("button", btnMap);
String url = this.mainService.getWxCpConfigStorage().getApiUrl(UPDATE_TEMPLATE_CARD);
this.mainService.post(url, WxGsonBuilder.create().toJson(data));
}
}

View File

@@ -92,6 +92,21 @@ public class WxCpMessage implements Serializable {
*/
private String sourceDesc;
/**
* 来源文字的颜色目前支持0(默认) 灰色1 黑色2 红色3 绿色
*/
private Integer sourceDescColor;
/**
* 更多操作界面的描述
*/
private String actionMenuDesc;
/**
* 操作列表,列表长度取值范围为 [1, 3]
*/
private List<ActionMenuItem> actionMenuActionList;
/**
* 一级标题建议不超过36个字
*/
@@ -482,9 +497,22 @@ public class WxCpMessage implements Serializable {
if (StringUtils.isNotBlank(this.getSourceDesc())) {
source.addProperty("desc", this.getSourceDesc());
}
source.addProperty("desc_color", this.getSourceDescColor());
template.add("source", source);
}
if (StringUtils.isNotBlank(this.getActionMenuDesc())) {
JsonObject action_menu = new JsonObject();
action_menu.addProperty("desc", this.getActionMenuDesc());
JsonArray actionList = new JsonArray();
List<ActionMenuItem> actionMenuItemList = this.getActionMenuActionList();
for (ActionMenuItem actionItemI : actionMenuItemList) {
actionList.add(actionItemI.toJson());
}
action_menu.add("action_list", actionList);
template.add("action_menu", action_menu);
}
if (StringUtils.isNotBlank(this.getMainTitleTitle()) || StringUtils.isNotBlank(this.getMainTitleDesc())) {
JsonObject mainTitle = new JsonObject();
if (StringUtils.isNotBlank(this.getMainTitleTitle())) {

View File

@@ -36,6 +36,21 @@ public class TemplateCardBuilder extends BaseBuilder<TemplateCardBuilder> {
*/
private String sourceDesc;
/**
* 来源文字的颜色目前支持0(默认) 灰色1 黑色2 红色3 绿色
*/
private Integer sourceDescColor;
/**
* 更多操作界面的描述
*/
private String actionMenuDesc;
/**
* 操作列表,列表长度取值范围为 [1, 3]
*/
private List<ActionMenuItem> actionMenuActionList;
/**
* 一级标题建议不超过36个字
*/
@@ -172,6 +187,16 @@ public class TemplateCardBuilder extends BaseBuilder<TemplateCardBuilder> {
return this;
}
public TemplateCardBuilder actionMenuDesc(String actionMenuDesc) {
this.actionMenuDesc = actionMenuDesc;
return this;
}
public TemplateCardBuilder actionMenuActionList(List<ActionMenuItem> actionMenuItemList) {
this.actionMenuActionList = actionMenuItemList;
return this;
}
public TemplateCardBuilder sourceIconUrl(String sourceIconUrl) {
this.sourceIconUrl = sourceIconUrl;
return this;
@@ -182,6 +207,11 @@ public class TemplateCardBuilder extends BaseBuilder<TemplateCardBuilder> {
return this;
}
public TemplateCardBuilder sourceDescColor(Integer sourceDescColor) {
this.sourceDescColor = sourceDescColor;
return this;
}
public TemplateCardBuilder mainTitleTitle(String mainTitleTitle) {
this.mainTitleTitle = mainTitleTitle;
return this;
@@ -294,6 +324,9 @@ public class TemplateCardBuilder extends BaseBuilder<TemplateCardBuilder> {
m.setCardType(this.cardType);
m.setSourceIconUrl(this.sourceIconUrl);
m.setSourceDesc(this.sourceDesc);
m.setSourceDescColor(this.sourceDescColor);
m.setActionMenuDesc(this.actionMenuDesc);
m.setActionMenuActionList(this.actionMenuActionList);
m.setMainTitleTitle(this.mainTitleTitle);
m.setMainTitleDesc(this.mainTitleDesc);
m.setCardImageUrl(this.cardImageUrl);

View File

@@ -0,0 +1,40 @@
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 java.io.Serializable;
/**
* 卡片右上角更多操作按钮点击后出现的操作列表,列表长度取值范围为 [1, 3]
* @author xiaohe
* @date 2022-03-06
*/
@Data
@Builder
@NoArgsConstructor
@AllArgsConstructor
public class ActionMenuItem implements Serializable {
private static final long serialVersionUID = 400885585614100693L;
/**
* 操作的描述文案
*/
private String text;
/**
* 按钮key值用户点击后会产生回调事件将本参数作为EventKey返回回调事件会带上该key值最长支持1024字节不可重复
*/
private String key;
public JsonObject toJson() {
JsonObject btnObject = new JsonObject();
btnObject.addProperty("text", this.getText());
btnObject.addProperty("key", this.getKey());
return btnObject;
}
}

View File

@@ -44,6 +44,11 @@ public class HorizontalContent implements Serializable {
*/
private String media_id;
/**
* 成员详情的useridhorizontal_content_list.type是3时必填
*/
private String userid;
public JsonObject toJson() {
JsonObject hContentJson = new JsonObject();
@@ -61,6 +66,9 @@ public class HorizontalContent implements Serializable {
if (StringUtils.isNotBlank(this.getMedia_id())) {
hContentJson.addProperty("media_id", this.getMedia_id());
}
if (StringUtils.isNotBlank(this.getUserid())) {
hContentJson.addProperty("userid", this.getUserid());
}
return hContentJson;
}

View File

@@ -187,6 +187,7 @@ public interface WxCpApiPathConsts {
interface TaskCard {
String UPDATE_TASK_CARD = "/cgi-bin/message/update_taskcard";
String UPDATE_TEMPLATE_CARD = "/cgi-bin/message/update_template_card";
}
interface Tp {