🆕 #3226 【企业微信】增加办公-文档管理模块相关接口
This commit is contained in:
@@ -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 {
|
||||
|
||||
/**
|
||||
* 新建文档
|
||||
* 该接口用于新建文档和表格,新建收集表可前往 收集表管理 查看。
|
||||
* <p>
|
||||
* 请求方式: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;
|
||||
|
||||
/**
|
||||
* 重命名文档/收集表
|
||||
* 该接口用于对指定文档/收集表进行重命名。
|
||||
* <p>
|
||||
* 请求方式: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;
|
||||
|
||||
/**
|
||||
* 删除文档/收集表
|
||||
* 该接口用于删除指定文档/收集表。
|
||||
* <p>
|
||||
* 请求方式: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;
|
||||
|
||||
/**
|
||||
* 获取文档基础信息
|
||||
* 该接口用于获取指定文档的基础信息。
|
||||
* <p>
|
||||
* 请求方式: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;
|
||||
|
||||
/**
|
||||
* 分享文档
|
||||
* 该接口用于获取文档的分享链接。
|
||||
* <p>
|
||||
* 请求方式: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;
|
||||
}
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -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<String> adminUsers;
|
||||
|
||||
/**
|
||||
* From json wx cp space create request.
|
||||
*
|
||||
* @param json the json
|
||||
* @return the wx cp space create request
|
||||
*/
|
||||
public static WxCpDocCreateRequest fromJson(String json) {
|
||||
return WxCpGsonBuilder.create().fromJson(json, WxCpDocCreateRequest.class);
|
||||
}
|
||||
|
||||
/**
|
||||
* To json string.
|
||||
*
|
||||
* @return the string
|
||||
*/
|
||||
public String toJson() {
|
||||
return WxCpGsonBuilder.create().toJson(this);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,98 @@
|
||||
package me.chanjar.weixin.cp.bean.oa.doc;
|
||||
|
||||
import com.google.gson.annotations.SerializedName;
|
||||
import lombok.Data;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
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 WxCpDocInfo extends WxCpBaseResp implements Serializable {
|
||||
private static final long serialVersionUID = -5028321623142879581L;
|
||||
|
||||
@SerializedName("doc_base_info")
|
||||
private DocInfo docBaseInfo;
|
||||
|
||||
/**
|
||||
* The type Space info.
|
||||
*/
|
||||
@Getter
|
||||
@Setter
|
||||
public static class DocInfo implements Serializable {
|
||||
private static final long serialVersionUID = -4860239393895754598L;
|
||||
|
||||
/**
|
||||
* 文档docid
|
||||
*/
|
||||
@SerializedName("docid")
|
||||
private String docId;
|
||||
|
||||
/**
|
||||
* 文档名字
|
||||
*/
|
||||
@SerializedName("doc_name")
|
||||
private String docName;
|
||||
|
||||
/**
|
||||
* 文档创建时间
|
||||
*/
|
||||
@SerializedName("create_time")
|
||||
private Long createTime;
|
||||
|
||||
/**
|
||||
* 文档最后修改时间
|
||||
*/
|
||||
@SerializedName("modify_time")
|
||||
private Long modifyTime;
|
||||
|
||||
/**
|
||||
* 3: 文档 4: 表格
|
||||
*/
|
||||
@SerializedName("doc_type")
|
||||
private Integer docType;
|
||||
|
||||
/**
|
||||
* From json space info.
|
||||
*
|
||||
* @param json the json
|
||||
* @return the space info
|
||||
*/
|
||||
public static DocInfo fromJson(String json) {
|
||||
return WxCpGsonBuilder.create().fromJson(json, DocInfo.class);
|
||||
}
|
||||
|
||||
/**
|
||||
* To json string.
|
||||
*
|
||||
* @return the string
|
||||
*/
|
||||
public String toJson() {
|
||||
return WxCpGsonBuilder.create().toJson(this);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* From json wx cp space info.
|
||||
*
|
||||
* @param json the json
|
||||
* @return the wx cp space info
|
||||
*/
|
||||
public static WxCpDocInfo fromJson(String json) {
|
||||
return WxCpGsonBuilder.create().fromJson(json, WxCpDocInfo.class);
|
||||
}
|
||||
|
||||
public String toJson() {
|
||||
return WxCpGsonBuilder.create().toJson(this);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,63 @@
|
||||
package me.chanjar.weixin.cp.bean.oa.doc;
|
||||
|
||||
import com.google.gson.annotations.SerializedName;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Builder;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
import lombok.experimental.Accessors;
|
||||
import me.chanjar.weixin.cp.util.json.WxCpGsonBuilder;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
/**
|
||||
* 重命名空间请求.
|
||||
*
|
||||
* @author Hugo
|
||||
*/
|
||||
@Data
|
||||
@Builder
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
@Accessors(chain = true)
|
||||
public class WxCpDocRenameRequest implements Serializable {
|
||||
private static final long serialVersionUID = -4960339393895754138L;
|
||||
|
||||
/**
|
||||
* 文档docid(docid、formid只能填其中一个)
|
||||
*/
|
||||
@SerializedName("docid")
|
||||
private String docId;
|
||||
|
||||
/**
|
||||
* 收集表id(docid、formid只能填其中一个)
|
||||
*/
|
||||
@SerializedName("formid")
|
||||
private String formId;
|
||||
|
||||
/**
|
||||
* 重命名后的文档名 (注意:文档名最多填255个字符, 英文算1个, 汉字算2个, 超过255个字符会被截断)
|
||||
*/
|
||||
@SerializedName("new_name")
|
||||
private String newName;
|
||||
|
||||
/**
|
||||
* From json wx cp space rename request.
|
||||
*
|
||||
* @param json the json
|
||||
* @return the wx cp space rename request
|
||||
*/
|
||||
public static WxCpDocRenameRequest fromJson(String json) {
|
||||
return WxCpGsonBuilder.create().fromJson(json, WxCpDocRenameRequest.class);
|
||||
}
|
||||
|
||||
/**
|
||||
* To json string.
|
||||
*
|
||||
* @return the string
|
||||
*/
|
||||
public String toJson() {
|
||||
return WxCpGsonBuilder.create().toJson(this);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,39 @@
|
||||
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 WxCpDocShare extends WxCpBaseResp implements Serializable {
|
||||
private static final long serialVersionUID = -5128321625142879581L;
|
||||
|
||||
/**
|
||||
* 文档分享链接
|
||||
*/
|
||||
@SerializedName("share_url")
|
||||
private String shareUrl;
|
||||
|
||||
/**
|
||||
* From json wx cp space share.
|
||||
*
|
||||
* @param json the json
|
||||
* @return the wx cp space share
|
||||
*/
|
||||
public static WxCpDocShare fromJson(String json) {
|
||||
return WxCpGsonBuilder.create().fromJson(json, WxCpDocShare.class);
|
||||
}
|
||||
|
||||
public String toJson() {
|
||||
return WxCpGsonBuilder.create().toJson(this);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -507,6 +507,32 @@ public interface WxCpApiPathConsts {
|
||||
* https://developer.work.weixin.qq.com/document/path/90269
|
||||
*/
|
||||
String GET_OPEN_APPROVAL_DATA = "/cgi-bin/corp/getopenapprovaldata";
|
||||
|
||||
/**
|
||||
* 文档
|
||||
* https://developer.work.weixin.qq.com/document/path/97392
|
||||
*/
|
||||
/**
|
||||
* The constant WEDOC_CREATE_DOC.
|
||||
*/
|
||||
String WEDOC_CREATE_DOC = "/cgi-bin/wedoc/create_doc";
|
||||
/**
|
||||
* The constant WEDOC_RENAME_DOC.
|
||||
*/
|
||||
String WEDOC_RENAME_DOC = "/cgi-bin/wedoc/rename_doc";
|
||||
/**
|
||||
* The constant WEDOC_DEL_DOC.
|
||||
*/
|
||||
String WEDOC_DEL_DOC = "/cgi-bin/wedoc/del_doc";
|
||||
/**
|
||||
* The constant WEDOC_GET_DOC_BASE_INFO.
|
||||
*/
|
||||
String WEDOC_GET_DOC_BASE_INFO = "/cgi-bin/wedoc/get_doc_base_info";
|
||||
/**
|
||||
* The constant WEDOC_DOC_SHARE.
|
||||
*/
|
||||
String WEDOC_DOC_SHARE = "/cgi-bin/wedoc/doc_share";
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user