提交 | 用户 | age
|
826b66
|
1 |
package com.hx.mp.util; |
C |
2 |
|
|
3 |
import com.alibaba.fastjson.JSONArray; |
|
4 |
import com.alibaba.fastjson.JSONObject; |
|
5 |
import com.hx.api.CorpMpSpaceApi; |
|
6 |
import java.util.List; |
|
7 |
|
|
8 |
/** |
|
9 |
* 企业微信微盘接口API |
|
10 |
* @Author: cmg |
|
11 |
* @Date: 2023-7-13 11:08 |
|
12 |
*/ |
|
13 |
public class CorpMpSpaceUtil { |
|
14 |
|
|
15 |
/** |
|
16 |
* 增加空间 |
|
17 |
* @param corpMpSpaceApi |
|
18 |
* @param accessToken |
|
19 |
* @param name 空间名称 |
|
20 |
* @param depId 部门id |
|
21 |
* @param adminId 管理员的企业微信id |
|
22 |
* @return |
|
23 |
*/ |
|
24 |
public static JSONObject addSpace(CorpMpSpaceApi corpMpSpaceApi, String accessToken, String name, Integer depId, String adminId) |
|
25 |
{ |
|
26 |
JSONObject obj = new JSONObject(); |
|
27 |
obj.put("space_name", name); |
|
28 |
JSONArray arr = new JSONArray(); |
|
29 |
|
|
30 |
//设置部门的可下载权限 |
|
31 |
JSONObject temp = new JSONObject(); |
|
32 |
temp.put("type", 2); |
|
33 |
temp.put("departmentid", depId); |
|
34 |
temp.put("auth", 1); |
|
35 |
arr.add(temp); |
|
36 |
|
|
37 |
//设置管理员 |
|
38 |
temp = new JSONObject(); |
|
39 |
temp.put("type", 1); |
|
40 |
temp.put("userid", adminId); |
|
41 |
temp.put("auth", 7); |
|
42 |
arr.add(temp); |
|
43 |
|
|
44 |
obj.put("auth_info", arr); |
|
45 |
|
|
46 |
return corpMpSpaceApi.addSpace(accessToken, obj.toJSONString()); |
|
47 |
} |
|
48 |
|
|
49 |
/** |
|
50 |
* 空间重命名 |
|
51 |
* @param corpMpSpaceApi |
|
52 |
* @param accessToken |
|
53 |
* @param spaceId |
|
54 |
* @param name |
|
55 |
* @return |
|
56 |
*/ |
|
57 |
public static JSONObject editSpaceName(CorpMpSpaceApi corpMpSpaceApi, String accessToken, String spaceId, String name) |
|
58 |
{ |
|
59 |
JSONObject obj = new JSONObject(); |
|
60 |
obj.put("space_name", name); |
|
61 |
obj.put("spaceid", spaceId); |
|
62 |
|
|
63 |
return corpMpSpaceApi.renameSpace(accessToken, obj.toJSONString()); |
|
64 |
} |
|
65 |
|
|
66 |
/** |
|
67 |
* 空间设置 |
|
68 |
* @param corpMpSpaceApi |
|
69 |
* @param accessToken |
|
70 |
* @param spaceId |
|
71 |
* @param enableConfidentialMode |
|
72 |
* @return |
|
73 |
*/ |
|
74 |
public static JSONObject spaceSetting(CorpMpSpaceApi corpMpSpaceApi, String accessToken, String spaceId, boolean enableConfidentialMode) |
|
75 |
{ |
|
76 |
JSONObject obj = new JSONObject(); |
|
77 |
obj.put("spaceid", spaceId); |
|
78 |
obj.put("enable_confidential_mode", enableConfidentialMode); |
|
79 |
|
|
80 |
return corpMpSpaceApi.spaceSetting(accessToken, obj.toJSONString()); |
|
81 |
} |
|
82 |
|
|
83 |
/** |
|
84 |
* 创建文件夹 |
|
85 |
* @param corpMpSpaceApi |
|
86 |
* @param accessToken |
|
87 |
* @param spaceId 空间id |
|
88 |
* @param fatherId 上级目录id,如果是空间下第一级,则是空间id |
|
89 |
* @param fileName 文件夹名称 |
|
90 |
* @return |
|
91 |
*/ |
|
92 |
public static JSONObject createDir(CorpMpSpaceApi corpMpSpaceApi, String accessToken, String spaceId, String fatherId, String fileName) |
|
93 |
{ |
|
94 |
JSONObject param = new JSONObject(); |
|
95 |
param.put("spaceid", spaceId); |
|
96 |
param.put("fatherid", fatherId); |
|
97 |
param.put("file_type", 1); |
|
98 |
param.put("file_name", fileName); |
|
99 |
|
|
100 |
|
|
101 |
return corpMpSpaceApi.createFile(accessToken, param.toJSONString()); |
|
102 |
} |
|
103 |
|
|
104 |
/** |
|
105 |
* 文件/文件夹重命名 |
|
106 |
* @param corpMpSpaceApi |
|
107 |
* @param accessToken |
|
108 |
* @param fileId |
|
109 |
* @param fileName |
|
110 |
* @return |
|
111 |
*/ |
|
112 |
public static JSONObject editDirName(CorpMpSpaceApi corpMpSpaceApi, String accessToken, String fileId, String fileName) |
|
113 |
{ |
|
114 |
JSONObject param = new JSONObject(); |
|
115 |
param.put("fileid", fileId); |
|
116 |
param.put("new_name", fileName); |
|
117 |
|
|
118 |
return corpMpSpaceApi.renameFile(accessToken, param.toJSONString()); |
|
119 |
} |
|
120 |
|
|
121 |
/** |
|
122 |
* 移除文件夹 |
|
123 |
* @param corpMpSpaceApi |
|
124 |
* @param accessToken |
|
125 |
* @param fileId |
|
126 |
* @return |
|
127 |
*/ |
|
128 |
public static JSONObject deleteDir(CorpMpSpaceApi corpMpSpaceApi, String accessToken, String fileId) |
|
129 |
{ |
|
130 |
JSONObject param = new JSONObject(); |
|
131 |
|
|
132 |
JSONArray arr = new JSONArray(); |
|
133 |
arr.add(fileId); |
|
134 |
|
|
135 |
param.put("fileid", arr); |
|
136 |
|
|
137 |
return corpMpSpaceApi.deleteFile(accessToken, param.toJSONString()); |
|
138 |
} |
|
139 |
|
|
140 |
/** |
|
141 |
* 传10M以内文件 |
|
142 |
* @param corpMpSpaceApi |
|
143 |
* @param accessToken |
|
144 |
* @param name |
|
145 |
* @param fileBase64Content |
|
146 |
* @param spaceId |
|
147 |
* @param fatherId |
|
148 |
* @return |
|
149 |
*/ |
|
150 |
public static JSONObject uploadFile(CorpMpSpaceApi corpMpSpaceApi, String accessToken, String name, String fileBase64Content, String spaceId, String fatherId) { |
|
151 |
JSONObject param = new JSONObject(); |
|
152 |
param.put("spaceid", spaceId); |
|
153 |
param.put("fatherid", fatherId); |
|
154 |
param.put("file_name", name); |
|
155 |
param.put("file_base64_content", fileBase64Content); |
|
156 |
|
|
157 |
return corpMpSpaceApi.fileUpload(accessToken, param.toJSONString()); |
|
158 |
} |
|
159 |
|
|
160 |
/** |
|
161 |
* 分块上传文件-初始化 |
|
162 |
* @param corpMpSpaceApi |
|
163 |
* @param accessToken |
|
164 |
* @param spaceId |
|
165 |
* @param fatherId |
|
166 |
* @param selectTicket |
|
167 |
* @param fileName |
|
168 |
* @param size |
|
169 |
* @param skipPushCard |
|
170 |
* @param blockSha |
|
171 |
* @return |
|
172 |
*/ |
|
173 |
public static JSONObject uploadBigFileInit(CorpMpSpaceApi corpMpSpaceApi, String accessToken, String spaceId, String fatherId, |
|
174 |
String selectTicket, String fileName, Long size, boolean skipPushCard, List<String> blockSha) { |
|
175 |
JSONObject param = new JSONObject(); |
|
176 |
param.put("spaceid", spaceId); |
|
177 |
param.put("fatherid", fatherId); |
|
178 |
param.put("selected_ticket", selectTicket); |
|
179 |
param.put("file_name", fileName); |
|
180 |
param.put("size", size); |
|
181 |
param.put("skip_push_card", skipPushCard); |
|
182 |
|
|
183 |
JSONArray arr = new JSONArray(); |
|
184 |
for(String sha : blockSha) |
|
185 |
{ |
|
186 |
arr.add(sha); |
|
187 |
} |
|
188 |
param.put("block_sha", arr); |
|
189 |
|
|
190 |
return corpMpSpaceApi.fileUploadInit(accessToken, param.toJSONString()); |
|
191 |
} |
|
192 |
|
|
193 |
/** |
|
194 |
* 分块上传文件-部分上传 |
|
195 |
* @param corpMpSpaceApi |
|
196 |
* @param accessToken |
|
197 |
* @param uploadKey |
|
198 |
* @param index |
|
199 |
* @param fileBase64Content |
|
200 |
* @return |
|
201 |
*/ |
|
202 |
public static JSONObject uploadBigFilePart(CorpMpSpaceApi corpMpSpaceApi, String accessToken, String uploadKey, int index, String fileBase64Content) { |
|
203 |
JSONObject param = new JSONObject(); |
|
204 |
param.put("upload_key", uploadKey); |
|
205 |
param.put("index", index); |
|
206 |
param.put("file_base64_content", fileBase64Content); |
|
207 |
|
|
208 |
return corpMpSpaceApi.fileUploadPart(accessToken, param.toJSONString()); |
|
209 |
} |
|
210 |
|
|
211 |
/** |
|
212 |
* 分块上传文件-上传完成 |
|
213 |
* @param corpMpSpaceApi |
|
214 |
* @param accessToken |
|
215 |
* @param uploadKey |
|
216 |
* @return |
|
217 |
*/ |
|
218 |
public static JSONObject uploadBigFileFin(CorpMpSpaceApi corpMpSpaceApi, String accessToken, String uploadKey) { |
|
219 |
JSONObject param = new JSONObject(); |
|
220 |
param.put("upload_key", uploadKey); |
|
221 |
|
|
222 |
return corpMpSpaceApi.fileUploadFinish(accessToken, param.toJSONString()); |
|
223 |
} |
|
224 |
|
|
225 |
/** |
|
226 |
* 获取下载路径 |
|
227 |
* @param corpMpSpaceApi |
|
228 |
* @param accessToken |
|
229 |
* @param fileId |
|
230 |
* @return |
|
231 |
*/ |
|
232 |
public static JSONObject getDownloadUrl(CorpMpSpaceApi corpMpSpaceApi, String accessToken, String fileId){ |
|
233 |
JSONObject param = new JSONObject(); |
|
234 |
param.put("fileid", fileId); |
|
235 |
|
|
236 |
return corpMpSpaceApi.getDownloadUrl(accessToken, param.toJSONString()); |
|
237 |
} |
|
238 |
} |