From 34622b300b2b64efba0a1ad2764ef1698044b580 Mon Sep 17 00:00:00 2001 From: Hugo-Ho <52446959+Hugo-Ho@users.noreply.github.com> Date: Tue, 30 Jan 2024 00:02:49 +0800 Subject: [PATCH] =?UTF-8?q?:new:=20#3226=20=E3=80=90=E4=BC=81=E4=B8=9A?= =?UTF-8?q?=E5=BE=AE=E4=BF=A1=E3=80=91=E5=A2=9E=E5=8A=A0=E5=8A=9E=E5=85=AC?= =?UTF-8?q?-=E6=96=87=E6=A1=A3=E7=AE=A1=E7=90=86=E6=A8=A1=E5=9D=97?= =?UTF-8?q?=E7=9B=B8=E5=85=B3=E6=8E=A5=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../weixin/cp/api/WxCpOaWeDocService.java | 82 ++++++++++++++++ .../cp/api/impl/WxCpOaWeDocServiceImpl.java | 66 +++++++++++++ .../weixin/cp/bean/oa/doc/WxCpDocCreateData | 45 +++++++++ .../cp/bean/oa/doc/WxCpDocCreateRequest.java | 71 ++++++++++++++ .../weixin/cp/bean/oa/doc/WxCpDocInfo.java | 98 +++++++++++++++++++ .../cp/bean/oa/doc/WxCpDocRenameRequest.java | 63 ++++++++++++ .../weixin/cp/bean/oa/doc/WxCpDocShare.java | 39 ++++++++ .../weixin/cp/constant/WxCpApiPathConsts.java | 26 +++++ 8 files changed, 490 insertions(+) create mode 100644 weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/WxCpOaWeDocService.java create mode 100644 weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/impl/WxCpOaWeDocServiceImpl.java create mode 100644 weixin-java-cp/src/main/java/me/chanjar/weixin/cp/bean/oa/doc/WxCpDocCreateData create mode 100644 weixin-java-cp/src/main/java/me/chanjar/weixin/cp/bean/oa/doc/WxCpDocCreateRequest.java create mode 100644 weixin-java-cp/src/main/java/me/chanjar/weixin/cp/bean/oa/doc/WxCpDocInfo.java create mode 100644 weixin-java-cp/src/main/java/me/chanjar/weixin/cp/bean/oa/doc/WxCpDocRenameRequest.java create mode 100644 weixin-java-cp/src/main/java/me/chanjar/weixin/cp/bean/oa/doc/WxCpDocShare.java diff --git a/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/WxCpOaWeDocService.java b/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/WxCpOaWeDocService.java new file mode 100644 index 0000000000..8cd8827af3 --- /dev/null +++ b/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/WxCpOaWeDocService.java @@ -0,0 +1,82 @@ +package me.chanjar.weixin.cp.api; + +import lombok.NonNull; +import me.chanjar.weixin.common.error.WxErrorException; +import me.chanjar.weixin.cp.bean.WxCpBaseResp; +import me.chanjar.weixin.cp.bean.oa.doc.*; + +/** + * 企业微信文档相关接口. + * https://developer.work.weixin.qq.com/document/path/97392 + * + * @author Hugo + */ +public interface WxCpOaWeDocService { + + /** + * 新建文档 + * 该接口用于新建文档和表格,新建收集表可前往 收集表管理 查看。 + *
+ * 请求方式:POST(HTTPS) + * 请求地址: https://qyapi.weixin.qq.com/cgi-bin/wedoc/create_doc?access_token=ACCESS_TOKEN + * + * @param request 新建文档对应请求参数 + * @return url 新建文档的访问链接 + * @return docid 新建文档的docid + * @throws WxErrorException the wx error exception + */ + WxCpDocCreateData docCreate(@NonNull WxCpDocCreateRequest request) throws WxErrorException; + + /** + * 重命名文档/收集表 + * 该接口用于对指定文档/收集表进行重命名。 + *
+ * 请求方式:POST(HTTPS) + * 请求地址: https://qyapi.weixin.qq.com/cgi-bin/wedoc/rename_doc?access_token=ACCESS_TOKEN + * + * @param request 重命名文档/收集表 + * @return wx cp base resp + * @throws WxErrorException the wx error exception + */ + WxCpBaseResp docRename(@NonNull WxCpDocRenameRequest request) throws WxErrorException; + + /** + * 删除文档/收集表 + * 该接口用于删除指定文档/收集表。 + *
+ * 请求方式:POST(HTTPS) + * 请求地址: https://qyapi.weixin.qq.com/cgi-bin/wedoc/del_doc?access_token=ACCESS_TOKEN + * + * @param docId 文档docid(docid、formid只能填其中一个) + * @param formId 收集表id(docid、formid只能填其中一个) + * @return wx cp base resp + * @throws WxErrorException the wx error exception + */ + WxCpBaseResp docDelete(String docId, String formId) throws WxErrorException; + + /** + * 获取文档基础信息 + * 该接口用于获取指定文档的基础信息。 + *
+ * 请求方式:POST(HTTPS) + * 请求地址: https://qyapi.weixin.qq.com/cgi-bin/wedoc/get_doc_base_info?access_token=ACCESS_TOKEN + * + * @param docId 文档docid + * @return wx cp doc info + * @throws WxErrorException the wx error exception + */ + WxCpDocInfo docInfo(@NonNull String docId) throws WxErrorException; + + /** + * 分享文档 + * 该接口用于获取文档的分享链接。 + *
+ * 请求方式:POST(HTTPS)
+ * 请求地址: https://qyapi.weixin.qq.com/cgi-bin/wedoc/doc_share?access_token=ACCESS_TOKEN
+ *
+ * @param docId 文档docid
+ * @return url 文档分享链接
+ * @throws WxErrorException the wx error exception
+ */
+ WxCpDocShare docShare(@NonNull String docId) throws WxErrorException;
+}
diff --git a/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/impl/WxCpOaWeDocServiceImpl.java b/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/impl/WxCpOaWeDocServiceImpl.java
new file mode 100644
index 0000000000..81de32453d
--- /dev/null
+++ b/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/impl/WxCpOaWeDocServiceImpl.java
@@ -0,0 +1,66 @@
+package me.chanjar.weixin.cp.api.impl;
+
+import com.google.gson.JsonObject;
+import lombok.NonNull;
+import lombok.RequiredArgsConstructor;
+import lombok.extern.slf4j.Slf4j;
+import me.chanjar.weixin.common.error.WxErrorException;
+import me.chanjar.weixin.cp.api.WxCpOaWeDocService;
+import me.chanjar.weixin.cp.api.WxCpService;
+import me.chanjar.weixin.cp.bean.WxCpBaseResp;
+import me.chanjar.weixin.cp.bean.oa.doc.*;
+
+import static me.chanjar.weixin.cp.constant.WxCpApiPathConsts.Oa.*;
+
+/**
+ * 企业微信微盘接口实现类.
+ *
+ * @author Wang_Wong created on 2022-04-22
+ */
+@Slf4j
+@RequiredArgsConstructor
+public class WxCpOaWeDocServiceImpl implements WxCpOaWeDocService {
+ private final WxCpService cpService;
+
+ @Override
+ public WxCpDocCreateData docCreate(@NonNull WxCpDocCreateRequest request) throws WxErrorException {
+ String apiUrl = this.cpService.getWxCpConfigStorage().getApiUrl(WEDOC_CREATE_DOC);
+ String responseContent = this.cpService.post(apiUrl, request.toJson());
+ return WxCpDocCreateData.fromJson(responseContent);
+ }
+
+ @Override
+ public WxCpBaseResp docRename(@NonNull WxCpDocRenameRequest request) throws WxErrorException {
+ String apiUrl = this.cpService.getWxCpConfigStorage().getApiUrl(WEDOC_RENAME_DOC);
+ String responseContent = this.cpService.post(apiUrl, request.toJson());
+ return WxCpBaseResp.fromJson(responseContent);
+ }
+
+ @Override
+ public WxCpBaseResp docDelete(String docId, String formId) throws WxErrorException {
+ String apiUrl = this.cpService.getWxCpConfigStorage().getApiUrl(WEDOC_DEL_DOC);
+ JsonObject jsonObject = new JsonObject();
+ jsonObject.addProperty("docid", docId);
+ jsonObject.addProperty("formid", formId);
+ String responseContent = this.cpService.post(apiUrl, jsonObject.toString());
+ return WxCpBaseResp.fromJson(responseContent);
+ }
+
+ @Override
+ public WxCpDocInfo docInfo(@NonNull String docId) throws WxErrorException {
+ String apiUrl = this.cpService.getWxCpConfigStorage().getApiUrl(WEDOC_GET_DOC_BASE_INFO);
+ JsonObject jsonObject = new JsonObject();
+ jsonObject.addProperty("docid", docId);
+ String responseContent = this.cpService.post(apiUrl, jsonObject.toString());
+ return WxCpDocInfo.fromJson(responseContent);
+ }
+
+ @Override
+ public WxCpDocShare docShare(@NonNull String docId) throws WxErrorException {
+ String apiUrl = this.cpService.getWxCpConfigStorage().getApiUrl(WEDOC_DOC_SHARE);
+ JsonObject jsonObject = new JsonObject();
+ jsonObject.addProperty("docid", docId);
+ String responseContent = this.cpService.post(apiUrl, jsonObject.toString());
+ return WxCpDocShare.fromJson(responseContent);
+ }
+}
diff --git a/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/bean/oa/doc/WxCpDocCreateData b/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/bean/oa/doc/WxCpDocCreateData
new file mode 100644
index 0000000000..c882ab1cf0
--- /dev/null
+++ b/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/bean/oa/doc/WxCpDocCreateData
@@ -0,0 +1,45 @@
+package me.chanjar.weixin.cp.bean.oa.doc;
+
+import com.google.gson.annotations.SerializedName;
+import lombok.Data;
+import me.chanjar.weixin.cp.bean.WxCpBaseResp;
+import me.chanjar.weixin.cp.util.json.WxCpGsonBuilder;
+
+import java.io.Serializable;
+
+/**
+ * 新建空间信息.
+ *
+ * @author Wang_Wong
+ */
+@Data
+public class WxCpDocCreateData extends WxCpBaseResp implements Serializable {
+ private static final long serialVersionUID = -5028321625242879581L;
+
+ /**
+ * 新建文档的访问链接
+ */
+ @SerializedName("url")
+ private String url;
+
+ /**
+ * 新建文档的docid
+ */
+ @SerializedName("docid")
+ private String docId;
+
+ /**
+ * From json wx cp space create data.
+ *
+ * @param json the json
+ * @return the wx cp space create data
+ */
+ public static WxCpDocCreateData fromJson(String json) {
+ return WxCpGsonBuilder.create().fromJson(json, WxCpDocCreateData.class);
+ }
+
+ public String toJson() {
+ return WxCpGsonBuilder.create().toJson(this);
+ }
+
+}
diff --git a/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/bean/oa/doc/WxCpDocCreateRequest.java b/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/bean/oa/doc/WxCpDocCreateRequest.java
new file mode 100644
index 0000000000..cabf2cdb75
--- /dev/null
+++ b/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/bean/oa/doc/WxCpDocCreateRequest.java
@@ -0,0 +1,71 @@
+package me.chanjar.weixin.cp.bean.oa.doc;
+
+import com.google.gson.annotations.SerializedName;
+import lombok.*;
+import lombok.experimental.Accessors;
+import me.chanjar.weixin.cp.util.json.WxCpGsonBuilder;
+
+import java.io.Serializable;
+import java.util.List;
+
+/**
+ * 新建文档请求.
+ */
+@Data
+@Builder
+@NoArgsConstructor
+@AllArgsConstructor
+@Accessors(chain = true)
+public class WxCpDocCreateRequest implements Serializable {
+ private static final long serialVersionUID = -4960239393895454138L;
+
+ /**
+ * 空间spaceid。若指定spaceid,则fatherid也要同时指定
+ */
+ @SerializedName("spaceid")
+ private String spaceId;
+
+ /**
+ * 父目录fileid, 在根目录时为空间spaceid
+ */
+ @SerializedName("fatherid")
+ private String fatherId;
+
+ /**
+ * 文档类型, 3:文档 4:表格
+ */
+ @SerializedName("doc_type")
+ private Integer docType;
+
+ /**
+ * 文档名字(注意:文件名最多填255个字符, 超过255个字符会被截断)
+ */
+ @SerializedName("doc_name")
+ private String docName;
+
+ /**
+ * 文档管理员userid
+ */
+ @SerializedName("admin_users")
+ private List