From 6e713d8102775b555fff5607158c9cfab76fa678 Mon Sep 17 00:00:00 2001
From: guang <guang@guang.com>
Date: 星期四, 27 七月 2023 17:42:30 +0800
Subject: [PATCH] 增加企业微盘操作工具类

---
 src/main/java/com/hx/mp/util/CorpMpSpaceUtil.java |  223 +++++++++++++++++++++++++++++++
 src/main/java/com/hx/api/CorpMpSpaceApi.java      |  182 ++++++++++++++++++++++++++
 2 files changed, 405 insertions(+), 0 deletions(-)

diff --git a/src/main/java/com/hx/api/CorpMpSpaceApi.java b/src/main/java/com/hx/api/CorpMpSpaceApi.java
new file mode 100644
index 0000000..470671d
--- /dev/null
+++ b/src/main/java/com/hx/api/CorpMpSpaceApi.java
@@ -0,0 +1,182 @@
+package com.hx.api;
+
+import com.alibaba.fastjson.JSONObject;
+import com.dtflys.forest.annotation.DataVariable;
+import com.dtflys.forest.annotation.JSONBody;
+import com.dtflys.forest.annotation.Post;
+
+/**
+ * 浼佷笟寰俊寰洏鎺ュ彛API
+ * @Author: cmg
+ * @Date: 2023-7-13 11:08
+ */
+public interface CorpMpSpaceApi {
+
+    /**
+     * 澧炲姞绌洪棿
+     * @param accessToken
+     * @param param
+     * @return
+     */
+    @Post(
+            url = "https://qyapi.weixin.qq.com/cgi-bin/wedrive/space_create?access_token=${accessToken}",
+            headers = {
+                    "Content-Type: application/json"
+            }
+    )
+    JSONObject addSpace(@DataVariable("accessToken") String accessToken, @JSONBody String param);
+
+    /**
+     * 閲嶅懡鍚嶇┖闂�
+     * @param accessToken
+     * @param param
+     * @return
+     */
+    @Post(
+            url = "https://qyapi.weixin.qq.com/cgi-bin/wedrive/space_rename?access_token=${accessToken}",
+            headers = {
+                    "Content-Type: application/json"
+            }
+    )
+    JSONObject renameSpace(@DataVariable("accessToken") String accessToken, @JSONBody String param);
+
+    /**
+     * 瑙f暎绌洪棿
+     * @param accessToken
+     * @param param
+     * @return
+     */
+    @Post(
+            url = "https://qyapi.weixin.qq.com/cgi-bin/wedrive/space_dismiss?access_token=${accessToken}",
+            headers = {
+                    "Content-Type: application/json"
+            }
+    )
+    JSONObject dismissSpace(@DataVariable("accessToken") String accessToken, @JSONBody String param);
+
+    /**
+     * 绌洪棿瀹夊叏璁剧疆
+     * @param accessToken
+     * @param param
+     * @return
+     */
+    @Post(
+            url = "https://qyapi.weixin.qq.com/cgi-bin/wedrive/space_setting?access_token=${accessToken}",
+            headers = {
+                    "Content-Type: application/json"
+            }
+    )
+    JSONObject spaceSetting(@DataVariable("accessToken") String accessToken, @JSONBody String param);
+
+    /**
+     * 鏂板缓鏂囦欢澶�/鏂囨。
+     * @param accessToken
+     * @param param
+     * @return
+     */
+    @Post(
+            url = "https://qyapi.weixin.qq.com/cgi-bin/wedrive/file_create?access_token=${accessToken}",
+            headers = {
+                    "Content-Type: application/json"
+            }
+    )
+    JSONObject createFile(@DataVariable("accessToken") String accessToken, @JSONBody String param);
+
+    /**
+     * 鏂囦欢閲嶅懡鍚�
+     * @param accessToken
+     * @param param
+     * @return
+     */
+    @Post(
+            url = "https://qyapi.weixin.qq.com/cgi-bin/wedrive/file_rename?access_token=${accessToken}",
+            headers = {
+                    "Content-Type: application/json"
+            }
+    )
+    JSONObject renameFile(@DataVariable("accessToken") String accessToken, @JSONBody String param);
+
+    /**
+     * 绉婚櫎鏂囦欢
+     * @param accessToken
+     * @param param
+     * @return
+     */
+    @Post(
+            url = "https://qyapi.weixin.qq.com/cgi-bin/wedrive/file_delete?access_token=${accessToken}",
+            headers = {
+                    "Content-Type: application/json"
+            }
+    )
+    JSONObject deleteFile(@DataVariable("accessToken") String accessToken, @JSONBody String param);
+
+    /**
+     * 鍒嗗潡涓婁紶鍒濆鍖�
+     * @param accessToken
+     * @param param
+     * @return
+     */
+    @Post(
+            url = "https://qyapi.weixin.qq.com/cgi-bin/wedrive/file_upload_init?access_token=${accessToken}",
+            headers = {
+                    "Content-Type: application/json"
+            }
+    )
+    JSONObject fileUploadInit(@DataVariable("accessToken") String accessToken, @JSONBody String param);
+
+    /**
+     * 鍒嗗潡涓婁紶鏂囦欢
+     * @param accessToken
+     * @param param
+     * @return
+     */
+    @Post(
+            url = "https://qyapi.weixin.qq.com/cgi-bin/wedrive/file_upload_part?access_token=${accessToken}",
+            headers = {
+                    "Content-Type: application/json"
+            }
+    )
+    JSONObject fileUploadPart(@DataVariable("accessToken") String accessToken, @JSONBody String param);
+
+    /**
+     * 鍒嗗潡涓婁紶瀹屾垚
+     * @param accessToken
+     * @param param
+     * @return
+     */
+    @Post(
+            url = "https://qyapi.weixin.qq.com/cgi-bin/wedrive/file_upload_finish?access_token=${accessToken}",
+            headers = {
+                    "Content-Type: application/json"
+            }
+    )
+    JSONObject fileUploadFinish(@DataVariable("accessToken") String accessToken, @JSONBody String param);
+
+    /**
+     * 涓婁紶鏂囦欢
+     * @param accessToken
+     * @param param
+     * @return
+     */
+    @Post(
+            url = "https://qyapi.weixin.qq.com/cgi-bin/wedrive/file_upload?access_token=${accessToken}",
+            headers = {
+                    "Content-Type: application/json"
+            }
+    )
+    JSONObject fileUpload(@DataVariable("accessToken") String accessToken, @JSONBody String param);
+
+    /**
+     * 鍒犻櫎鏂囦欢
+     * @param accessToken
+     * @param param
+     * @return
+     */
+    @Post(
+            url = "https://qyapi.weixin.qq.com/cgi-bin/wedrive/file_delete?access_token=${accessToken}",
+            headers = {
+                    "Content-Type: application/json"
+            }
+    )
+    JSONObject fileDelete(@DataVariable("accessToken") String accessToken, @JSONBody String param);
+}
diff --git a/src/main/java/com/hx/mp/util/CorpMpSpaceUtil.java b/src/main/java/com/hx/mp/util/CorpMpSpaceUtil.java
new file mode 100644
index 0000000..da9f8cf
--- /dev/null
+++ b/src/main/java/com/hx/mp/util/CorpMpSpaceUtil.java
@@ -0,0 +1,223 @@
+package com.hx.mp.util;
+
+import com.alibaba.fastjson.JSONArray;
+import com.alibaba.fastjson.JSONObject;
+import com.hx.api.CorpMpSpaceApi;
+import java.util.List;
+
+/**
+ * 浼佷笟寰俊寰洏鎺ュ彛API
+ * @Author: cmg
+ * @Date: 2023-7-13 11:08
+ */
+public class CorpMpSpaceUtil {
+
+    /**
+     * 澧炲姞绌洪棿
+     * @param corpMpSpaceApi
+     * @param accessToken
+     * @param name 绌洪棿鍚嶇О
+     * @param depId 閮ㄩ棬id
+     * @param adminId 绠$悊鍛樼殑浼佷笟寰俊id
+     * @return
+     */
+    public static JSONObject addSpace(CorpMpSpaceApi corpMpSpaceApi, String accessToken, String name, Integer depId, String adminId)
+    {
+        JSONObject obj = new JSONObject();
+        obj.put("space_name", name);
+        JSONArray arr = new JSONArray();
+
+        //璁剧疆閮ㄩ棬鐨勫彲涓嬭浇鏉冮檺
+        JSONObject temp = new JSONObject();
+        temp.put("type", 2);
+        temp.put("departmentid", depId);
+        temp.put("auth", 1);
+        arr.add(temp);
+
+        //璁剧疆绠$悊鍛�
+        temp = new JSONObject();
+        temp.put("type", 1);
+        temp.put("userid", adminId);
+        temp.put("auth", 7);
+        arr.add(temp);
+
+        obj.put("auth_info", arr);
+
+        return corpMpSpaceApi.addSpace(accessToken, obj.toJSONString());
+    }
+
+    /**
+     * 绌洪棿閲嶅懡鍚�
+     * @param corpMpSpaceApi
+     * @param accessToken
+     * @param spaceId
+     * @param name
+     * @return
+     */
+    public static JSONObject editSpaceName(CorpMpSpaceApi corpMpSpaceApi, String accessToken, String spaceId, String name)
+    {
+        JSONObject obj = new JSONObject();
+        obj.put("space_name", name);
+        obj.put("spaceid", spaceId);
+
+        return corpMpSpaceApi.renameSpace(accessToken, obj.toJSONString());
+    }
+
+    /**
+     * 绌洪棿璁剧疆
+     * @param corpMpSpaceApi
+     * @param accessToken
+     * @param spaceId
+     * @param enableConfidentialMode
+     * @return
+     */
+    public static JSONObject spaceSetting(CorpMpSpaceApi corpMpSpaceApi, String accessToken, String spaceId, boolean enableConfidentialMode)
+    {
+        JSONObject obj = new JSONObject();
+        obj.put("spaceid", spaceId);
+        obj.put("enable_confidential_mode", enableConfidentialMode);
+
+        return corpMpSpaceApi.spaceSetting(accessToken, obj.toJSONString());
+    }
+
+    /**
+     * 鍒涘缓鏂囦欢澶�
+     * @param corpMpSpaceApi
+     * @param accessToken
+     * @param spaceId 绌洪棿id
+     * @param fatherId 涓婄骇鐩綍id,濡傛灉鏄┖闂翠笅绗竴绾э紝鍒欐槸绌洪棿id
+     * @param fileName 鏂囦欢澶瑰悕绉�
+     * @return
+     */
+    public static JSONObject createDir(CorpMpSpaceApi corpMpSpaceApi, String accessToken, String spaceId, String fatherId, String fileName)
+    {
+        JSONObject param = new JSONObject();
+        param.put("spaceid", spaceId);
+        param.put("fatherid", fatherId);
+        param.put("file_type", 1);
+        param.put("file_name", fileName);
+
+
+        return corpMpSpaceApi.createFile(accessToken, param.toJSONString());
+    }
+
+    /**
+     * 鏂囦欢/鏂囦欢澶归噸鍛藉悕
+     * @param corpMpSpaceApi
+     * @param accessToken
+     * @param fileId
+     * @param fileName
+     * @return
+     */
+    public static JSONObject editDirName(CorpMpSpaceApi corpMpSpaceApi, String accessToken, String fileId, String fileName)
+    {
+        JSONObject param = new JSONObject();
+        param.put("fileid", fileId);
+        param.put("new_name", fileName);
+
+        return corpMpSpaceApi.renameFile(accessToken, param.toJSONString());
+    }
+
+    /**
+     * 绉婚櫎鏂囦欢澶�
+     * @param corpMpSpaceApi
+     * @param accessToken
+     * @param fileId
+     * @return
+     */
+    public static JSONObject deleteDir(CorpMpSpaceApi corpMpSpaceApi, String accessToken, String fileId)
+    {
+        JSONObject param = new JSONObject();
+
+        JSONArray arr = new JSONArray();
+        arr.add(fileId);
+
+        param.put("fileid", arr);
+
+        return corpMpSpaceApi.deleteFile(accessToken, param.toJSONString());
+    }
+
+    /**
+     * 浼�10M浠ュ唴鏂囦欢
+     * @param corpMpSpaceApi
+     * @param accessToken
+     * @param name
+     * @param fileBase64Content
+     * @param spaceId
+     * @param fatherId
+     * @return
+     */
+    public static JSONObject uploadFile(CorpMpSpaceApi corpMpSpaceApi, String accessToken, String name, String fileBase64Content, String spaceId, String fatherId) {
+        JSONObject param = new JSONObject();
+        param.put("spaceid", spaceId);
+        param.put("fatherid", fatherId);
+        param.put("file_name", name);
+        param.put("file_base64_content", fileBase64Content);
+
+        return corpMpSpaceApi.fileUpload(accessToken, param.toJSONString());
+    }
+
+    /**
+     * 鍒嗗潡涓婁紶鏂囦欢-鍒濆鍖�
+     * @param corpMpSpaceApi
+     * @param accessToken
+     * @param spaceId
+     * @param fatherId
+     * @param selectTicket
+     * @param fileName
+     * @param size
+     * @param skipPushCard
+     * @param blockSha
+     * @return
+     */
+    public static JSONObject uploadBigFileInit(CorpMpSpaceApi corpMpSpaceApi, String accessToken, String spaceId, String fatherId,
+                                               String selectTicket, String fileName, Long size, boolean skipPushCard, List<String> blockSha) {
+        JSONObject param = new JSONObject();
+        param.put("spaceid", spaceId);
+        param.put("fatherid", fatherId);
+        param.put("selected_ticket", selectTicket);
+        param.put("file_name", fileName);
+        param.put("size", size);
+        param.put("skip_push_card", skipPushCard);
+
+        JSONArray arr = new JSONArray();
+        for(String sha : blockSha)
+        {
+            arr.add(sha);
+        }
+
+        return corpMpSpaceApi.fileUploadInit(accessToken, param.toJSONString());
+    }
+
+    /**
+     * 鍒嗗潡涓婁紶鏂囦欢-閮ㄥ垎涓婁紶
+     * @param corpMpSpaceApi
+     * @param accessToken
+     * @param uploadKey
+     * @param index
+     * @param fileBase64Content
+     * @return
+     */
+    public static JSONObject uploadBigFilePart(CorpMpSpaceApi corpMpSpaceApi, String accessToken, String uploadKey, int index, String fileBase64Content) {
+        JSONObject param = new JSONObject();
+        param.put("upload_key", uploadKey);
+        param.put("index", index);
+        param.put("file_base64_content", fileBase64Content);
+
+        return corpMpSpaceApi.fileUploadPart(accessToken, param.toJSONString());
+    }
+
+    /**
+     * 鍒嗗潡涓婁紶鏂囦欢-涓婁紶瀹屾垚
+     * @param corpMpSpaceApi
+     * @param accessToken
+     * @param uploadKey
+     * @return
+     */
+    public static JSONObject uploadBigFileFin(CorpMpSpaceApi corpMpSpaceApi, String accessToken, String uploadKey) {
+        JSONObject param = new JSONObject();
+        param.put("upload_key", uploadKey);
+
+        return corpMpSpaceApi.fileUploadFinish(accessToken, param.toJSONString());
+    }
+}

--
Gitblit v1.8.0