Просмотр исходного кода

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

xiaohe-53 3 лет назад
Родитель
Сommit
946f693bd0

+ 6 - 1
pom.xml

@@ -92,6 +92,11 @@
       <email>huangxm129@163.com</email>
       <url>https://github.com/huangxm129</url>
     </developer>
+    <developer>
+      <name>xiaohe</name>
+      <email>xiaohe@53jy.net</email>
+      <url>https://github.com/xiaohe-53</url>
+    </developer>
   </developers>
 
   <scm>
@@ -302,7 +307,7 @@
       <dependency>
         <groupId>org.projectlombok</groupId>
         <artifactId>lombok</artifactId>
-        <version>1.18.8</version>
+        <version>1.18.24</version>
         <scope>provided</scope>
       </dependency>
       <dependency>

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

@@ -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;
+
 }

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

@@ -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));
+
+  }
 }

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

@@ -93,6 +93,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个字
    */
   private String mainTitleTitle;
@@ -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())) {

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

@@ -37,6 +37,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个字
    */
   private String mainTitleTitle;
@@ -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);

+ 40 - 0
weixin-java-cp/src/main/java/me/chanjar/weixin/cp/bean/templatecard/ActionMenuItem.java

@@ -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;
+  }
+
+}

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

@@ -44,6 +44,11 @@ public class HorizontalContent implements Serializable {
    */
   private String media_id;
 
+  /**
+   * 成员详情的userid,horizontal_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;
   }
 

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

@@ -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 {

Разница между файлами не показана из-за своего большого размера
+ 25 - 6
weixin-java-cp/src/test/java/me/chanjar/weixin/cp/bean/message/WxCpMessageTest.java