Skip to content

Commit c994770

Browse files
Hugo-Hoboris.bao
authored and
boris.bao
committed
🆕 binarywang#3226 【企业微信】增加办公-文档管理模块相关接口
1 parent a670e70 commit c994770

File tree

8 files changed

+490
-0
lines changed

8 files changed

+490
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
package me.chanjar.weixin.cp.api;
2+
3+
import lombok.NonNull;
4+
import me.chanjar.weixin.common.error.WxErrorException;
5+
import me.chanjar.weixin.cp.bean.WxCpBaseResp;
6+
import me.chanjar.weixin.cp.bean.oa.doc.*;
7+
8+
/**
9+
* 企业微信文档相关接口.
10+
* https://developer.work.weixin.qq.com/document/path/97392
11+
*
12+
* @author Hugo
13+
*/
14+
public interface WxCpOaWeDocService {
15+
16+
/**
17+
* 新建文档
18+
* 该接口用于新建文档和表格,新建收集表可前往 收集表管理 查看。
19+
* <p>
20+
* 请求方式:POST(HTTPS)
21+
* 请求地址: https://qyapi.weixin.qq.com/cgi-bin/wedoc/create_doc?access_token=ACCESS_TOKEN
22+
*
23+
* @param request 新建文档对应请求参数
24+
* @return url 新建文档的访问链接
25+
* @return docid 新建文档的docid
26+
* @throws WxErrorException the wx error exception
27+
*/
28+
WxCpDocCreateData docCreate(@NonNull WxCpDocCreateRequest request) throws WxErrorException;
29+
30+
/**
31+
* 重命名文档/收集表
32+
* 该接口用于对指定文档/收集表进行重命名。
33+
* <p>
34+
* 请求方式:POST(HTTPS)
35+
* 请求地址: https://qyapi.weixin.qq.com/cgi-bin/wedoc/rename_doc?access_token=ACCESS_TOKEN
36+
*
37+
* @param request 重命名文档/收集表
38+
* @return wx cp base resp
39+
* @throws WxErrorException the wx error exception
40+
*/
41+
WxCpBaseResp docRename(@NonNull WxCpDocRenameRequest request) throws WxErrorException;
42+
43+
/**
44+
* 删除文档/收集表
45+
* 该接口用于删除指定文档/收集表。
46+
* <p>
47+
* 请求方式:POST(HTTPS)
48+
* 请求地址: https://qyapi.weixin.qq.com/cgi-bin/wedoc/del_doc?access_token=ACCESS_TOKEN
49+
*
50+
* @param docId 文档docid(docid、formid只能填其中一个)
51+
* @param formId 收集表id(docid、formid只能填其中一个)
52+
* @return wx cp base resp
53+
* @throws WxErrorException the wx error exception
54+
*/
55+
WxCpBaseResp docDelete(String docId, String formId) throws WxErrorException;
56+
57+
/**
58+
* 获取文档基础信息
59+
* 该接口用于获取指定文档的基础信息。
60+
* <p>
61+
* 请求方式:POST(HTTPS)
62+
* 请求地址: https://qyapi.weixin.qq.com/cgi-bin/wedoc/get_doc_base_info?access_token=ACCESS_TOKEN
63+
*
64+
* @param docId 文档docid
65+
* @return wx cp doc info
66+
* @throws WxErrorException the wx error exception
67+
*/
68+
WxCpDocInfo docInfo(@NonNull String docId) throws WxErrorException;
69+
70+
/**
71+
* 分享文档
72+
* 该接口用于获取文档的分享链接。
73+
* <p>
74+
* 请求方式:POST(HTTPS)
75+
* 请求地址: https://qyapi.weixin.qq.com/cgi-bin/wedoc/doc_share?access_token=ACCESS_TOKEN
76+
*
77+
* @param docId 文档docid
78+
* @return url 文档分享链接
79+
* @throws WxErrorException the wx error exception
80+
*/
81+
WxCpDocShare docShare(@NonNull String docId) throws WxErrorException;
82+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
package me.chanjar.weixin.cp.api.impl;
2+
3+
import com.google.gson.JsonObject;
4+
import lombok.NonNull;
5+
import lombok.RequiredArgsConstructor;
6+
import lombok.extern.slf4j.Slf4j;
7+
import me.chanjar.weixin.common.error.WxErrorException;
8+
import me.chanjar.weixin.cp.api.WxCpOaWeDocService;
9+
import me.chanjar.weixin.cp.api.WxCpService;
10+
import me.chanjar.weixin.cp.bean.WxCpBaseResp;
11+
import me.chanjar.weixin.cp.bean.oa.doc.*;
12+
13+
import static me.chanjar.weixin.cp.constant.WxCpApiPathConsts.Oa.*;
14+
15+
/**
16+
* 企业微信微盘接口实现类.
17+
*
18+
* @author Wang_Wong created on 2022-04-22
19+
*/
20+
@Slf4j
21+
@RequiredArgsConstructor
22+
public class WxCpOaWeDocServiceImpl implements WxCpOaWeDocService {
23+
private final WxCpService cpService;
24+
25+
@Override
26+
public WxCpDocCreateData docCreate(@NonNull WxCpDocCreateRequest request) throws WxErrorException {
27+
String apiUrl = this.cpService.getWxCpConfigStorage().getApiUrl(WEDOC_CREATE_DOC);
28+
String responseContent = this.cpService.post(apiUrl, request.toJson());
29+
return WxCpDocCreateData.fromJson(responseContent);
30+
}
31+
32+
@Override
33+
public WxCpBaseResp docRename(@NonNull WxCpDocRenameRequest request) throws WxErrorException {
34+
String apiUrl = this.cpService.getWxCpConfigStorage().getApiUrl(WEDOC_RENAME_DOC);
35+
String responseContent = this.cpService.post(apiUrl, request.toJson());
36+
return WxCpBaseResp.fromJson(responseContent);
37+
}
38+
39+
@Override
40+
public WxCpBaseResp docDelete(String docId, String formId) throws WxErrorException {
41+
String apiUrl = this.cpService.getWxCpConfigStorage().getApiUrl(WEDOC_DEL_DOC);
42+
JsonObject jsonObject = new JsonObject();
43+
jsonObject.addProperty("docid", docId);
44+
jsonObject.addProperty("formid", formId);
45+
String responseContent = this.cpService.post(apiUrl, jsonObject.toString());
46+
return WxCpBaseResp.fromJson(responseContent);
47+
}
48+
49+
@Override
50+
public WxCpDocInfo docInfo(@NonNull String docId) throws WxErrorException {
51+
String apiUrl = this.cpService.getWxCpConfigStorage().getApiUrl(WEDOC_GET_DOC_BASE_INFO);
52+
JsonObject jsonObject = new JsonObject();
53+
jsonObject.addProperty("docid", docId);
54+
String responseContent = this.cpService.post(apiUrl, jsonObject.toString());
55+
return WxCpDocInfo.fromJson(responseContent);
56+
}
57+
58+
@Override
59+
public WxCpDocShare docShare(@NonNull String docId) throws WxErrorException {
60+
String apiUrl = this.cpService.getWxCpConfigStorage().getApiUrl(WEDOC_DOC_SHARE);
61+
JsonObject jsonObject = new JsonObject();
62+
jsonObject.addProperty("docid", docId);
63+
String responseContent = this.cpService.post(apiUrl, jsonObject.toString());
64+
return WxCpDocShare.fromJson(responseContent);
65+
}
66+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
package me.chanjar.weixin.cp.bean.oa.doc;
2+
3+
import com.google.gson.annotations.SerializedName;
4+
import lombok.Data;
5+
import me.chanjar.weixin.cp.bean.WxCpBaseResp;
6+
import me.chanjar.weixin.cp.util.json.WxCpGsonBuilder;
7+
8+
import java.io.Serializable;
9+
10+
/**
11+
* 新建空间信息.
12+
*
13+
* @author Wang_Wong
14+
*/
15+
@Data
16+
public class WxCpDocCreateData extends WxCpBaseResp implements Serializable {
17+
private static final long serialVersionUID = -5028321625242879581L;
18+
19+
/**
20+
* 新建文档的访问链接
21+
*/
22+
@SerializedName("url")
23+
private String url;
24+
25+
/**
26+
* 新建文档的docid
27+
*/
28+
@SerializedName("docid")
29+
private String docId;
30+
31+
/**
32+
* From json wx cp space create data.
33+
*
34+
* @param json the json
35+
* @return the wx cp space create data
36+
*/
37+
public static WxCpDocCreateData fromJson(String json) {
38+
return WxCpGsonBuilder.create().fromJson(json, WxCpDocCreateData.class);
39+
}
40+
41+
public String toJson() {
42+
return WxCpGsonBuilder.create().toJson(this);
43+
}
44+
45+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
package me.chanjar.weixin.cp.bean.oa.doc;
2+
3+
import com.google.gson.annotations.SerializedName;
4+
import lombok.*;
5+
import lombok.experimental.Accessors;
6+
import me.chanjar.weixin.cp.util.json.WxCpGsonBuilder;
7+
8+
import java.io.Serializable;
9+
import java.util.List;
10+
11+
/**
12+
* 新建文档请求.
13+
*/
14+
@Data
15+
@Builder
16+
@NoArgsConstructor
17+
@AllArgsConstructor
18+
@Accessors(chain = true)
19+
public class WxCpDocCreateRequest implements Serializable {
20+
private static final long serialVersionUID = -4960239393895454138L;
21+
22+
/**
23+
* 空间spaceid。若指定spaceid,则fatherid也要同时指定
24+
*/
25+
@SerializedName("spaceid")
26+
private String spaceId;
27+
28+
/**
29+
* 父目录fileid, 在根目录时为空间spaceid
30+
*/
31+
@SerializedName("fatherid")
32+
private String fatherId;
33+
34+
/**
35+
* 文档类型, 3:文档 4:表格
36+
*/
37+
@SerializedName("doc_type")
38+
private Integer docType;
39+
40+
/**
41+
* 文档名字(注意:文件名最多填255个字符, 超过255个字符会被截断)
42+
*/
43+
@SerializedName("doc_name")
44+
private String docName;
45+
46+
/**
47+
* 文档管理员userid
48+
*/
49+
@SerializedName("admin_users")
50+
private List<String> adminUsers;
51+
52+
/**
53+
* From json wx cp space create request.
54+
*
55+
* @param json the json
56+
* @return the wx cp space create request
57+
*/
58+
public static WxCpDocCreateRequest fromJson(String json) {
59+
return WxCpGsonBuilder.create().fromJson(json, WxCpDocCreateRequest.class);
60+
}
61+
62+
/**
63+
* To json string.
64+
*
65+
* @return the string
66+
*/
67+
public String toJson() {
68+
return WxCpGsonBuilder.create().toJson(this);
69+
}
70+
71+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
package me.chanjar.weixin.cp.bean.oa.doc;
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 WxCpDocInfo extends WxCpBaseResp implements Serializable {
19+
private static final long serialVersionUID = -5028321623142879581L;
20+
21+
@SerializedName("doc_base_info")
22+
private DocInfo docBaseInfo;
23+
24+
/**
25+
* The type Space info.
26+
*/
27+
@Getter
28+
@Setter
29+
public static class DocInfo implements Serializable {
30+
private static final long serialVersionUID = -4860239393895754598L;
31+
32+
/**
33+
* 文档docid
34+
*/
35+
@SerializedName("docid")
36+
private String docId;
37+
38+
/**
39+
* 文档名字
40+
*/
41+
@SerializedName("doc_name")
42+
private String docName;
43+
44+
/**
45+
* 文档创建时间
46+
*/
47+
@SerializedName("create_time")
48+
private Long createTime;
49+
50+
/**
51+
* 文档最后修改时间
52+
*/
53+
@SerializedName("modify_time")
54+
private Long modifyTime;
55+
56+
/**
57+
* 3: 文档 4: 表格
58+
*/
59+
@SerializedName("doc_type")
60+
private Integer docType;
61+
62+
/**
63+
* From json space info.
64+
*
65+
* @param json the json
66+
* @return the space info
67+
*/
68+
public static DocInfo fromJson(String json) {
69+
return WxCpGsonBuilder.create().fromJson(json, DocInfo.class);
70+
}
71+
72+
/**
73+
* To json string.
74+
*
75+
* @return the string
76+
*/
77+
public String toJson() {
78+
return WxCpGsonBuilder.create().toJson(this);
79+
}
80+
81+
}
82+
83+
84+
/**
85+
* From json wx cp space info.
86+
*
87+
* @param json the json
88+
* @return the wx cp space info
89+
*/
90+
public static WxCpDocInfo fromJson(String json) {
91+
return WxCpGsonBuilder.create().fromJson(json, WxCpDocInfo.class);
92+
}
93+
94+
public String toJson() {
95+
return WxCpGsonBuilder.create().toJson(this);
96+
}
97+
98+
}

0 commit comments

Comments
 (0)