8000 :new: #2651【企业微信】新增微盘文件管理接口 · binarywang/WxJava@a6d4b6e · GitHub
[go: up one dir, main page]

Skip to content
8000

Commit a6d4b6e

Browse files
authored
🆕 #2651【企业微信】新增微盘文件管理接口
1 parent 5da9fb3 commit a6d4b6e

File tree

8 files changed

+393
-1
lines changed

8 files changed

+393
-1
lines changed

weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/WxCpOaWeDriveService.java

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
import me.chanjar.weixin.cp.bean.WxCpBaseResp;
66
import me.chanjar.weixin.cp.bean.oa.wedrive.*;
77

8+
import java.util.List;
9+
810
/**
911
* 企业微信微盘相关接口.
1012
* https://developer.work.weixin.qq.com/document/path/93654
@@ -194,4 +196,45 @@ public interface WxCpOaWeDriveService {
194196
WxCpFileCreate fileCreate(@NonNull String userId, @NonNull String spaceId,
195197
@NonNull String fatherId, @NonNull Integer fileType, @NonNull String fileName) throws WxErrorException;
196198

199+
/**
200+
* 移动文件
201+
* 该接口用于将文件移动到指定位置。
202+
* <p>
203+
* 请求方式:POST(HTTPS)
204+
* 请求地址: https://qyapi.weixin.qq.com/cgi-bin/wedrive/file_move?access_token=ACCESS_TOKEN
205+
*
206+
* @param request 移动文件的请求参数
207+
* @return
208+
* @throws WxErrorException
209+
*/
210+
WxCpFileMove fileMove(@NonNull WxCpFileMoveRequest request) throws WxErrorException;
211+
212+
/**
213+
* 删除文件
214+
* 该接口用于删除指定文件。
215+
* <p>
216+
* 请求方式:POST(HTTPS)
217+
* 请求地址: https://qyapi.weixin.qq.com/cgi-bin/wedrive/file_delete?access_token=ACCESS_TOKEN
218+
*
219+
* @param userId 操作者userid
220+
* @param fileId 文件fileid列表
221+
* @return
222+
* @throws WxErrorException
223+
*/
224+
WxCpBaseResp fileDelete(@NonNull String userId, @NonNull List<String> fileId) throws WxErrorException;
225+
226+
/**
227+
* 文件信息
228+
* 该接口用于获取指定文件的信息。
229+
* <p>
230+
* 请求方式:POST(HTTPS)
231+
* 请求地址: https://qyapi.weixin.qq.com/cgi-bin/wedrive/file_info?access_token=ACCESS_TOKEN
232+
*
233+
* @param userId
234+
* @param fileId
235+
* @return
236+
* @throws WxErrorException
237+
*/
238+
WxCpFileInfo fileInfo(@NonNull String userId, @NonNull String fileId) throws WxErrorException;
239+
197240
}

weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/impl/WxCpOaWeDriveServiceImpl.java

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@
1010
import me.chanjar.weixin.cp.bean.WxCpBaseResp;
1111
import me.chanjar.weixin.cp.bean.oa.wedrive.*;
1212

13+
import java.util.List;
14+
1315
import static me.chanjar.weixin.cp.constant.WxCpApiPathConsts.Oa.*;
1416

1517
/**
@@ -117,7 +119,7 @@ public WxCpFileRename fileRename(@NonNull String userId, @NonNull String fileId,
117119
String apiUrl = this.cpService.getWxCpConfigStorage().getApiUrl(FILE_RENAME);
118120
JsonObject jsonObject = new JsonObject();
119121
jsonObject.addProperty("userid", userId);
120-
jsonObject.addProperty("fileiid", fileId);
122+
jsonObject.addProperty("fileid", fileId);
121123
jsonObject.addProperty("new_name", newName);
122124
String responseContent = this.cpService.post(apiUrl, jsonObject.toString());
123125
return WxCpFileRename.fromJson(responseContent);
@@ -136,4 +138,29 @@ public WxCpFileCreate fileCreate(@NonNull String userId, @NonNull String spaceId
136138
return WxCpFileCreate.fromJson(responseContent);
137139
}
138140

141+
@Override
142+
public WxCpFileMove fileMove(@NonNull WxCpFileMoveRequest request) throws WxErrorException {
143+
String apiUrl = this.cpService.getWxCpConfigStorage().getApiUrl(FILE_MOVE);
144+
String responseContent = this.cpService.post(apiUrl, request.toJson());
145+
return WxCpFileMove.fromJson(responseContent);
146+
}
147+
148+
@Override
149+
public WxCpBaseResp fileDelete(@NonNull String userId, @NonNull List<String> fileId) throws WxErrorException {
150+
String apiUrl = this.cpService.getWxCpConfigStorage().getApiUrl(FILE_DELETE);
151+
WxCpFileDeleteRequest request = new WxCpFileDeleteRequest(userId, fileId);
152+
String responseContent = this.cpService.post(apiUrl, request.toJson());
153+
return WxCpBaseResp.fromJson(responseContent);
154+
}
155+
156+
@Override
157+
public WxCpFileInfo fileInfo(@NonNull String userId, @NonNull String fileId) throws WxErrorException {
158+
String apiUrl = this.cpService.getWxCpConfigStorage().getApiUrl(FILE_INFO);
159+
JsonObject jsonObject = new JsonObject();
160+
jsonObject.addProperty("userid", userId);
161+
jsonObject.addProperty("fileid", fileId);
162+
String responseContent = this.cpService.post(apiUrl, jsonObject.toString());
163+
return WxCpFileInfo.fromJson(responseContent);
164+
}
165+
139166
}
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
package me.chanjar.weixin.cp.bean.oa.wedrive;
2+
3+
import com.google.gson.annotations.SerializedName;
4+
import lombok.AllArgsConstructor;
5+
import lombok.Builder;
6+
import lombok.Data;
7+
import lombok.NoArgsConstructor;
8+
import lombok.experimental.Accessors;
9+
import me.chanjar.weixin.cp.util.json.WxCpGsonBuilder;
10+
11+
import java.io.Serializable;
12+
import java.util.List;
13+
14+
/**
15+
* 删除文件请求.
16+
*/
17+
@Data
18+
@Builder
19+
@NoArgsConstructor
20+
@AllArgsConstructor
21+
@Accessors(chain = true)
22+
public class WxCpFileDeleteRequest implements Serializable {
23+
private static final long serialVersionUID = -4960239393895754138L;
24+
25+
@SerializedName("userid")
26+
private String userId;
27+
28+
@SerializedName("fileid")
29+
private List<String> fileId;
30+
31+
public static WxCpFileDeleteRequest fromJson(String json) {
32+
return WxCpGsonBuilder.create().fromJson(json, WxCpFileDeleteRequest.class);
33+
}
34+
35+
public String toJson() {
36+
return WxCpGsonBuilder.create().toJson(this);
37+
}
38+
39+
}
Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
package me.chanjar.weixin.cp.bean.oa.wedrive;
2+
3+
import com.google.gson.annotations.SerializedName;
4+
import lombok.Data;
5+
import lombok.Getter;
6+
import lombok.Setter;
7+
import me.chanjar.weixin.cp.bean.WxCpBaseResp;
8+
import me.chanjar.weixin.cp.util.json.WxCpGsonBuilder;
9+
10+
import java.io.Serializable;
11+
12+
/**
13+
* 文件信息.
14+
*
15+
* @author Wang_Wong
16+
*/
17+
@Data
18+
public class WxCpFileInfo extends WxCpBaseResp implements Serializable {
19+
private static final long serialVersionUID = -5028321625142879581L;
20+
21+
@SerializedName("file_info")
22+
private FileInfo fileInfo;
23+
24+
@Getter
25+
@Setter
26+
public static class FileInfo implements Serializable {
27+
private static final long serialVersionUID = -4960239393895754598L;
28+
29+
@SerializedName("fileid")
30+
private String fileId;
31+
32+
@SerializedName("file_name")
33+
private String fileName;
34+
35+
@SerializedName("spaceid")
36+
private String spaceId;
37+
38+
@SerializedName("fatherid")
39+
private String fatherId;
40+
41+
@SerializedName("file_size")
42+
private Long fileSize;
43+
44+
@SerializedName("ctime")
45+
private Long cTime;
46+
47+
@SerializedName("mtime")
48+
private Long mTime;
49+
50+
@SerializedName("file_type")
51+
private Integer fileType;
52+
53+
@SerializedName("file_status")
54+
private Integer fileStatus;
55+
56+
@SerializedName("create_userid")
57+
private String createUserId;
58+
59+
@SerializedName("update_userid")
60+
private String updateUserId;
61+
62+
@SerializedName("sha")
63+
private String sha;
64+
65+
@SerializedName("md5")
66+
private String md5;
67+
68+
@SerializedName("url")
69+
private String url;
70+
71+
public static FileInfo fromJson(String json) {
72+
return WxCpGsonBuilder.create().fromJson(json, FileInfo.class);
73+
}
74+
75+
public String toJson() {
76+
return WxCpGsonBuilder.create().toJson(this);
77+
}
78+
79+
}
80+
81+
public static WxCpFileInfo fromJson(String json) {
82+
return WxCpGsonBuilder.create().fromJson(json, WxCpFileInfo.class);
83+
}
84+
85+
public String toJson() {
86+
return WxCpGsonBuilder.create().toJson(this);
87+
}
88+
89+
}
Lines changed: 105 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,105 @@
1+
package me.chanjar.weixin.cp.bean.oa.wedrive;
2+
3+
import com.google.gson.annotations.SerializedName;
4+
import lombok.Data;
5+
import lombok.Getter;
6+
import lombok.Setter;
7+
import me.chanjar.weixin.cp.bean.WxCpBaseResp;
8+
import me.chanjar.weixin.cp.util.json.WxCpGsonBuilder;
9+
10+
import java.io.Serializable;
11+
import java.util.List;
12+
13+
/**
14+
* 移动文件返回信息.
15+
*
16+
* @author Wang_Wong
17+
*/
18+
@Data
19+
public class WxCpFileMove extends WxCpBaseResp implements Serializable {
20+
private static final long serialVersionUID = -5028321625142879581L;
21+
22+
@SerializedName("file_list")
23+
private FileList fileList;
24+
25+
@Getter
26+
@Setter
27+
public static class FileList implements Serializable {
28+
private static final long serialVersionUID = -4960239393895754598L;
29+
30+
@SerializedName("item")
31+
private List<Item> item;
32+
33+
public static FileList fromJson(String json) {
34+
return WxCpGsonBuilder.create().fromJson(json, FileList.class);
35+
}
36+
37+
public String toJson() {
38+
return WxCpGsonBuilder.create().toJson(this);
39+
}
40+
41+
}
42+
43+
@Getter
44+
@Setter
45+
public static class Item implements Serializable {
46+
private static final long serialVersionUID = -4960239393895754598L;
47+
48+
@SerializedName("fileid")
49+
private String fileId;
50+
51+
@SerializedName("file_name")
52+
private String fileName;
53+
54+
@SerializedName("spaceid")
55+
private String spaceId;
56+
57+
@SerializedName("fatherid")
58+
private String fatherId;
59+
60+
@SerializedName("file_size")
61+
private Long fileSize;
62+
63+
@SerializedName("ctime")
64+
private Long cTime;
65+
66+
@SerializedName("mtime")
67+
private Long mTime;
68+
69+
@SerializedName("file_type")
70+
private Integer fileType;
71+
72+
@SerializedName("file_status")
73+
private Integer fileStatus;
74+
75+
@SerializedName("create_userid")
76+
private String createUserId;
77+
78+
@SerializedName("update_userid")
79+
private String updateUserId;
80+
81+
@SerializedName("sha")
82+
private String sha;
83+
84+
@SerializedName("md5")
85+
private String md5;
86+
87+
public static Item fromJson(String json) {
88+
return WxCpGsonBuilder.create().fromJson(json, Item.class);
89+
}
90+
91+
public String toJson() {
92+
return WxCpGsonBuilder.create().toJson(this);
93+
}
94+
95+
}
96+
97+
public static WxCpFileMove fromJson(String json) {
98+
return WxCpGsonBuilder.create().fromJson(json, WxCpFileMove.class);
99+
}
100+
101+
public String toJson() {
102+
return WxCpGsonBuilder.create().toJson(this);
103+
}
104+
105+
}
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
package me.chanjar.weixin.cp.bean.oa.wedrive;
2+
3+
import com.google.gson.annotations.SerializedName;
4+
import lombok.AllArgsConstructor;
5+
import lombok.Builder;
6+
import lombok.Data;
7+
import lombok.NoArgsConstructor;
8+
import lombok.experimental.Accessors;
9+
import me.chanjar.weixin.cp.util.json.WxCpGsonBuilder;
10+
11+
import java.io.Serializable;
12+
13+
/**
14+
* 移动文件请求.
15+
*/
16+
@Data
17+
@Builder
18+
@NoArgsConstructor
19+
@AllArgsConstructor
20+
@Accessors(chain = true)
21+
public class WxCpFileMoveRequest implements Serializable {
22+
private static final long serialVersionUID = -4960239393895754138L;
23+
24+
/**
25+
* 操作者userid
26+
*/
27+
@SerializedName("userid")
28+
private String userId;
29+
30+
/**
31+
* 如果移动到的目标目录与需要移动的文件重名时,是否覆盖。
32+
* true:重名文件覆盖
33+
* false:重名文件进行冲突重命名处理(移动后文件名格式如xxx(1).txt xxx(1).doc等)
34+
*/
35+
@SerializedName("replace")
36+
private Boolean replace;
37+
38+
/**
39+
* 当前目录的fileid,根目录时为空间spaceid
40+
*/
41+
@SerializedName("fatherid")
42+
private String fatherId;
43+
44+
/**
45+
* 文件fileid
46+
*/
47+
@SerializedName("fileid")
48+
private String[] fileId;
49+
50+
public static WxCpFileMoveRequest fromJson(String json) {
51+
59AB return WxCpGsonBuilder.create().fromJson(json, WxCpFileMoveRequest.class);
52+
}
53+
54+
public String toJson() {
55+
return WxCpGsonBuilder.create().toJson(this);
56+
}
57+
58+
}

0 commit comments

Comments
 (0)
0