Browse Source

:art: #2481 【企业微信】发送应用消息接口里的文本通知型的模板卡片消息增加引用文本字段

zp961466717 3 years ago
parent
commit
0c35f778db

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

@@ -200,6 +200,11 @@ public class WxCpMessage implements Serializable {
   private List<MultipleSelect> selects;
 
   /**
+   * 引用文献样式
+   */
+  private QuoteArea quoteArea;
+
+  /**
    * 获得文本消息builder.
    */
   public static TextBuilder TEXT() {
@@ -606,6 +611,12 @@ public class WxCpMessage implements Serializable {
           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;
       }

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

@@ -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;
@@ -266,6 +271,11 @@ public class TemplateCardBuilder  extends BaseBuilder<TemplateCardBuilder>{
     return this;
   }
 
+  public TemplateCardBuilder quoteArea(QuoteArea quoteArea) {
+    this.quoteArea = quoteArea;
+    return this;
+  }
+
   @Override
   public WxCpMessage build() {
     WxCpMessage m = super.build();
@@ -295,6 +305,7 @@ public class TemplateCardBuilder  extends BaseBuilder<TemplateCardBuilder>{
     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;
   }
 }

+ 74 - 0
weixin-java-cp/src/main/java/me/chanjar/weixin/cp/bean/templatecard/QuoteArea.java

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

File diff suppressed because it is too large
+ 10 - 2
weixin-java-cp/src/test/java/me/chanjar/weixin/cp/bean/message/WxCpMessageTest.java