From b569b3489a7081fa4ac7e46a73a5ff9d6738e7e3 Mon Sep 17 00:00:00 2001 From: zhongjun96 Date: Fri, 22 Apr 2022 15:24:03 +0800 Subject: [PATCH] =?UTF-8?q?feat(=E4=BC=81=E4=B8=9A=E5=BE=AE=E4=BF=A1):?= =?UTF-8?q?=E7=AE=A1=E7=90=86=E5=95=86=E5=93=81=E5=9B=BE=E5=86=8C-?= =?UTF-8?q?=E6=96=B0=E5=A2=9E=EF=BC=8C=E7=BC=96=E8=BE=91=E5=88=A0=E9=99=A4?= =?UTF-8?q?=E6=8E=A5=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../cp/api/WxCpExternalContactService.java | 48 ++++++++++++++++--- .../impl/WxCpExternalContactServiceImpl.java | 34 ++++++++++--- .../bean/external/WxCpProductAlbumInfo.java | 4 ++ .../weixin/cp/constant/WxCpApiPathConsts.java | 4 ++ 4 files changed, 77 insertions(+), 13 deletions(-) diff --git a/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/WxCpExternalContactService.java b/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/WxCpExternalContactService.java index a87079d5ae..f75f72a76a 100644 --- a/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/WxCpExternalContactService.java +++ b/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/WxCpExternalContactService.java @@ -1,17 +1,16 @@ package me.chanjar.weixin.cp.api; -import java.io.File; -import java.io.IOException; -import java.io.InputStream; import lombok.NonNull; import me.chanjar.weixin.common.bean.result.WxMediaUploadResult; import me.chanjar.weixin.common.error.WxErrorException; import me.chanjar.weixin.cp.bean.WxCpBaseResp; import me.chanjar.weixin.cp.bean.external.*; import me.chanjar.weixin.cp.bean.external.contact.*; -import me.chanjar.weixin.cp.bean.oa.WxCpApprovalInfoQueryFilter; import org.jetbrains.annotations.NotNull; +import java.io.File; +import java.io.IOException; +import java.io.InputStream; import java.util.Date; import java.util.List; @@ -977,7 +976,8 @@ WxMediaUploadResult uploadAttachment(String mediaType, Integer attachmentType, F * 请求地址:https://qyapi.weixin.qq.com/cgi-bin/externalcontact/update_intercept_rule?access_token=ACCESS_TOKEN *
    */
-  WxCpInterceptRuleResultResp updateInterceptRule(WxCpInterceptRuleResp ruleResp) throws  WxErrorException;
+  WxCpInterceptRuleResultResp updateInterceptRule(WxCpInterceptRuleResp ruleResp) throws WxErrorException;
+
   /**
    * 
    * 删除敏感词规则
@@ -987,6 +987,42 @@ WxMediaUploadResult uploadAttachment(String mediaType, Integer attachmentType, F
    * 
    * @param rule_id 规则id
    */
-  WxCpBaseResp delInterceptRule(String rule_id) throws  WxErrorException;
+  WxCpBaseResp delInterceptRule(String rule_id) throws WxErrorException;
+
+  /**
+   * 
+   * 创建商品图册
+   * 企业和第三方应用可以通过此接口增加商品
+   * 请求方式:POST(HTTPS)
+   * 请求地址:https://qyapi.weixin.qq.com/cgi-bin/externalcontact/add_product_album?access_token=ACCESS_TOKEN
+   * 文档地址:https://developer.work.weixin.qq.com/document/path/95096#%E5%88%9B%E5%BB%BA%E5%95%86%E5%93%81%E5%9B%BE%E5%86%8C
+   * 
+   * @param wxCpProductAlbumInfo 商品图册信息
+   * @return 商品id
+   */
+  String addProductAlbum(WxCpProductAlbumInfo wxCpProductAlbumInfo) throws WxErrorException;
+
+  /**
+   * 
+   * 编辑商品图册
+   * 企业和第三方应用可以通过此接口修改商品信息
+   * 请求方式:POST(HTTPS)
+   * 请求地址:https://qyapi.weixin.qq.com/cgi-bin/externalcontact/update_product_album?access_token=ACCESS_TOKEN
+   * 文档地址:https://developer.work.weixin.qq.com/document/path/95096#%E7%BC%96%E8%BE%91%E5%95%86%E5%93%81%E5%9B%BE%E5%86%8C
+   * 
+   * @param wxCpProductAlbumInfo 商品图册信息
+   */
+  void updateProductAlbum(WxCpProductAlbumInfo wxCpProductAlbumInfo) throws WxErrorException;
 
+  /**
+   * 
+   * 删除商品图册
+   * 企业和第三方应用可以通过此接口删除商品信息
+   * 请求方式:POST(HTTPS)
+   * 请求地址:https://qyapi.weixin.qq.com/cgi-bin/externalcontact/delete_product_album?access_token=ACCESS_TOKEN
+   * 文档地址:https://developer.work.weixin.qq.com/document/path/95096#%E5%88%A0%E9%99%A4%E5%95%86%E5%93%81%E5%9B%BE%E5%86%8C
+   * 
+   * @param productId 商品id
+   */
+  void deleteProductAlbum(String productId) throws WxErrorException;
 }
diff --git a/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/impl/WxCpExternalContactServiceImpl.java b/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/impl/WxCpExternalContactServiceImpl.java
index 89fc6961d1..bfd5608ed9 100644
--- a/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/impl/WxCpExternalContactServiceImpl.java
+++ b/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/impl/WxCpExternalContactServiceImpl.java
@@ -2,12 +2,6 @@
 
 import com.google.gson.Gson;
 import com.google.gson.JsonObject;
-
-import java.io.File;
-import java.io.IOException;
-import java.io.InputStream;
-import java.util.UUID;
-
 import lombok.NonNull;
 import lombok.RequiredArgsConstructor;
 import me.chanjar.weixin.common.bean.result.WxMediaUploadResult;
@@ -27,9 +21,13 @@
 import org.apache.commons.lang3.StringUtils;
 import org.jetbrains.annotations.NotNull;
 
+import java.io.File;
+import java.io.IOException;
+import java.io.InputStream;
 import java.util.Collections;
 import java.util.Date;
 import java.util.List;
+import java.util.UUID;
 
 import static me.chanjar.weixin.cp.constant.WxCpApiPathConsts.ExternalContact.*;
 
@@ -857,10 +855,32 @@ public WxCpInterceptRuleResultResp updateInterceptRule(WxCpInterceptRuleResp rul
   @Override
   public WxCpBaseResp delInterceptRule(String rule_id) throws WxErrorException {
     JsonObject jsonObject = new JsonObject();
-    jsonObject.addProperty("rule_id",rule_id);
+    jsonObject.addProperty("rule_id", rule_id);
     return WxCpBaseResp
       .fromJson(this.mainService.post(this.mainService.getWxCpConfigStorage().getApiUrl(DEL_INTERCEPT_RULE), jsonObject));
   }
 
+  @Override
+  public String addProductAlbum(WxCpProductAlbumInfo wxCpProductAlbumInfo) throws WxErrorException {
+    String url = this.mainService.getWxCpConfigStorage().getApiUrl(ADD_PRODUCT_ALBUM);
+    String responseContent = this.mainService.post(url, wxCpProductAlbumInfo.toJson());
+    JsonObject tmpJson = GsonParser.parse(responseContent);
+    return tmpJson.get("product_id").getAsString();
+  }
+
+  @Override
+  public void updateProductAlbum(WxCpProductAlbumInfo wxCpProductAlbumInfo) throws WxErrorException {
+    String url = this.mainService.getWxCpConfigStorage().getApiUrl(UPDATE_PRODUCT_ALBUM);
+    this.mainService.post(url, wxCpProductAlbumInfo.toJson());
+  }
+
+  @Override
+  public void deleteProductAlbum(String productId) throws WxErrorException {
+    JsonObject o = new JsonObject();
+    o.addProperty("product_id", productId);
+    String url = this.mainService.getWxCpConfigStorage().getApiUrl(DELETE_PRODUCT_ALBUM);
+    this.mainService.post(url, o.toString());
+  }
+
 
 }
diff --git a/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/bean/external/WxCpProductAlbumInfo.java b/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/bean/external/WxCpProductAlbumInfo.java
index e0ad62ea36..c837d30850 100644
--- a/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/bean/external/WxCpProductAlbumInfo.java
+++ b/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/bean/external/WxCpProductAlbumInfo.java
@@ -50,4 +50,8 @@ public static WxCpProductAlbumInfo fromJson(String json) {
     return WxCpGsonBuilder.create().fromJson(json, WxCpProductAlbumInfo.class);
   }
 
+  public String toJson() {
+    return WxCpGsonBuilder.create().toJson(this);
+  }
+
 }
diff --git a/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/constant/WxCpApiPathConsts.java b/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/constant/WxCpApiPathConsts.java
index c3b4e03ecb..71a6d03451 100644
--- a/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/constant/WxCpApiPathConsts.java
+++ b/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/constant/WxCpApiPathConsts.java
@@ -273,8 +273,12 @@ interface ExternalContact {
     String GET_GROUP_MSG_LIST_V2 = "/cgi-bin/externalcontact/get_groupmsg_list_v2";
     String GET_GROUP_MSG_RESULT = "/cgi-bin/externalcontact/get_group_msg_result";
 
+
     String GET_PRODUCT_ALBUM = "/cgi-bin/externalcontact/get_product_album";
     String GET_PRODUCT_ALBUM_LIST = "/cgi-bin/externalcontact/get_product_album_list";
+    String ADD_PRODUCT_ALBUM = "/cgi-bin/externalcontact/add_product_album";
+    String UPDATE_PRODUCT_ALBUM = "/cgi-bin/externalcontact/update_product_album";
+    String DELETE_PRODUCT_ALBUM = "/cgi-bin/externalcontact/delete_product_album";
 
     String GROUP_WELCOME_TEMPLATE_ADD = "/cgi-bin/externalcontact/group_welcome_template/add";
     String GROUP_WELCOME_TEMPLATE_EDIT = "/cgi-bin/externalcontact/group_welcome_template/edit";