mirror of
https://gitee.com/binary/weixin-java-tools.git
synced 2025-04-05 17:38:05 +08:00
🆕 #2651【企业微信】新增微盘文件管理接口
This commit is contained in:
parent
5da9fb30aa
commit
a6d4b6e6ab
@ -5,6 +5,8 @@ import me.chanjar.weixin.common.error.WxErrorException;
|
||||
import me.chanjar.weixin.cp.bean.WxCpBaseResp;
|
||||
import me.chanjar.weixin.cp.bean.oa.wedrive.*;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 企业微信微盘相关接口.
|
||||
* https://developer.work.weixin.qq.com/document/path/93654
|
||||
@ -194,4 +196,45 @@ public interface WxCpOaWeDriveService {
|
||||
WxCpFileCreate fileCreate(@NonNull String userId, @NonNull String spaceId,
|
||||
@NonNull String fatherId, @NonNull Integer fileType, @NonNull String fileName) throws WxErrorException;
|
||||
|
||||
/**
|
||||
* 移动文件
|
||||
* 该接口用于将文件移动到指定位置。
|
||||
* <p>
|
||||
* 请求方式:POST(HTTPS)
|
||||
* 请求地址: https://qyapi.weixin.qq.com/cgi-bin/wedrive/file_move?access_token=ACCESS_TOKEN
|
||||
*
|
||||
* @param request 移动文件的请求参数
|
||||
* @return
|
||||
* @throws WxErrorException
|
||||
*/
|
||||
WxCpFileMove fileMove(@NonNull WxCpFileMoveRequest request) throws WxErrorException;
|
||||
|
||||
/**
|
||||
* 删除文件
|
||||
* 该接口用于删除指定文件。
|
||||
* <p>
|
||||
* 请求方式:POST(HTTPS)
|
||||
* 请求地址: https://qyapi.weixin.qq.com/cgi-bin/wedrive/file_delete?access_token=ACCESS_TOKEN
|
||||
*
|
||||
* @param userId 操作者userid
|
||||
* @param fileId 文件fileid列表
|
||||
* @return
|
||||
* @throws WxErrorException
|
||||
*/
|
||||
WxCpBaseResp fileDelete(@NonNull String userId, @NonNull List<String> fileId) throws WxErrorException;
|
||||
|
||||
/**
|
||||
* 文件信息
|
||||
* 该接口用于获取指定文件的信息。
|
||||
* <p>
|
||||
* 请求方式:POST(HTTPS)
|
||||
* 请求地址: https://qyapi.weixin.qq.com/cgi-bin/wedrive/file_info?access_token=ACCESS_TOKEN
|
||||
*
|
||||
* @param userId
|
||||
* @param fileId
|
||||
* @return
|
||||
* @throws WxErrorException
|
||||
*/
|
||||
WxCpFileInfo fileInfo(@NonNull String userId, @NonNull String fileId) throws WxErrorException;
|
||||
|
||||
}
|
||||
|
@ -10,6 +10,8 @@ import me.chanjar.weixin.cp.api.WxCpService;
|
||||
import me.chanjar.weixin.cp.bean.WxCpBaseResp;
|
||||
import me.chanjar.weixin.cp.bean.oa.wedrive.*;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import static me.chanjar.weixin.cp.constant.WxCpApiPathConsts.Oa.*;
|
||||
|
||||
/**
|
||||
@ -117,7 +119,7 @@ public class WxCpOaWeDriveServiceImpl implements WxCpOaWeDriveService {
|
||||
String apiUrl = this.cpService.getWxCpConfigStorage().getApiUrl(FILE_RENAME);
|
||||
JsonObject jsonObject = new JsonObject();
|
||||
jsonObject.addProperty("userid", userId);
|
||||
jsonObject.addProperty("fileiid", fileId);
|
||||
jsonObject.addProperty("fileid", fileId);
|
||||
jsonObject.addProperty("new_name", newName);
|
||||
String responseContent = this.cpService.post(apiUrl, jsonObject.toString());
|
||||
return WxCpFileRename.fromJson(responseContent);
|
||||
@ -136,4 +138,29 @@ public class WxCpOaWeDriveServiceImpl implements WxCpOaWeDriveService {
|
||||
return WxCpFileCreate.fromJson(responseContent);
|
||||
}
|
||||
|
||||
@Override
|
||||
public WxCpFileMove fileMove(@NonNull WxCpFileMoveRequest request) throws WxErrorException {
|
||||
String apiUrl = this.cpService.getWxCpConfigStorage().getApiUrl(FILE_MOVE);
|
||||
String responseContent = this.cpService.post(apiUrl, request.toJson());
|
||||
return WxCpFileMove.fromJson(responseContent);
|
||||
}
|
||||
|
||||
@Override
|
||||
public WxCpBaseResp fileDelete(@NonNull String userId, @NonNull List<String> fileId) throws WxErrorException {
|
||||
String apiUrl = this.cpService.getWxCpConfigStorage().getApiUrl(FILE_DELETE);
|
||||
WxCpFileDeleteRequest request = new WxCpFileDeleteRequest(userId, fileId);
|
||||
String responseContent = this.cpService.post(apiUrl, request.toJson());
|
||||
return WxCpBaseResp.fromJson(responseContent);
|
||||
}
|
||||
|
||||
@Override
|
||||
public WxCpFileInfo fileInfo(@NonNull String userId, @NonNull String fileId) throws WxErrorException {
|
||||
String apiUrl = this.cpService.getWxCpConfigStorage().getApiUrl(FILE_INFO);
|
||||
JsonObject jsonObject = new JsonObject();
|
||||
jsonObject.addProperty("userid", userId);
|
||||
jsonObject.addProperty("fileid", fileId);
|
||||
String responseContent = this.cpService.post(apiUrl, jsonObject.toString());
|
||||
return WxCpFileInfo.fromJson(responseContent);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -0,0 +1,39 @@
|
||||
package me.chanjar.weixin.cp.bean.oa.wedrive;
|
||||
|
||||
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;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 删除文件请求.
|
||||
*/
|
||||
@Data
|
||||
@Builder
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
@Accessors(chain = true)
|
||||
public class WxCpFileDeleteRequest implements Serializable {
|
||||
private static final long serialVersionUID = -4960239393895754138L;
|
||||
|
||||
@SerializedName("userid")
|
||||
private String userId;
|
||||
|
||||
@SerializedName("fileid")
|
||||
private List<String> fileId;
|
||||
|
||||
public static WxCpFileDeleteRequest fromJson(String json) {
|
||||
return WxCpGsonBuilder.create().fromJson(json, WxCpFileDeleteRequest.class);
|
||||
}
|
||||
|
||||
public String toJson() {
|
||||
return WxCpGsonBuilder.create().toJson(this);
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,89 @@
|
||||
package me.chanjar.weixin.cp.bean.oa.wedrive;
|
||||
|
||||
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 WxCpFileInfo extends WxCpBaseResp implements Serializable {
|
||||
private static final long serialVersionUID = -5028321625142879581L;
|
||||
|
||||
@SerializedName("file_info")
|
||||
private FileInfo fileInfo;
|
||||
|
||||
@Getter
|
||||
@Setter
|
||||
public static class FileInfo implements Serializable {
|
||||
private static final long serialVersionUID = -4960239393895754598L;
|
||||
|
||||
@SerializedName("fileid")
|
||||
private String fileId;
|
||||
|
||||
@SerializedName("file_name")
|
||||
private String fileName;
|
||||
|
||||
@SerializedName("spaceid")
|
||||
private String spaceId;
|
||||
|
||||
@SerializedName("fatherid")
|
||||
private String fatherId;
|
||||
|
||||
@SerializedName("file_size")
|
||||
private Long fileSize;
|
||||
|
||||
@SerializedName("ctime")
|
||||
private Long cTime;
|
||||
|
||||
@SerializedName("mtime")
|
||||
private Long mTime;
|
||||
|
||||
@SerializedName("file_type")
|
||||
private Integer fileType;
|
||||
|
||||
@SerializedName("file_status")
|
||||
private Integer fileStatus;
|
||||
|
||||
@SerializedName("create_userid")
|
||||
private String createUserId;
|
||||
|
||||
@SerializedName("update_userid")
|
||||
private String updateUserId;
|
||||
|
||||
@SerializedName("sha")
|
||||
private String sha;
|
||||
|
||||
@SerializedName("md5")
|
||||
private String md5;
|
||||
|
||||
@SerializedName("url")
|
||||
private String url;
|
||||
|
||||
public static FileInfo fromJson(String json) {
|
||||
return WxCpGsonBuilder.create().fromJson(json, FileInfo.class);
|
||||
}
|
||||
|
||||
public String toJson() {
|
||||
return WxCpGsonBuilder.create().toJson(this);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public static WxCpFileInfo fromJson(String json) {
|
||||
return WxCpGsonBuilder.create().fromJson(json, WxCpFileInfo.class);
|
||||
}
|
||||
|
||||
public String toJson() {
|
||||
return WxCpGsonBuilder.create().toJson(this);
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,105 @@
|
||||
package me.chanjar.weixin.cp.bean.oa.wedrive;
|
||||
|
||||
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;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 移动文件返回信息.
|
||||
*
|
||||
* @author Wang_Wong
|
||||
*/
|
||||
@Data
|
||||
public class WxCpFileMove extends WxCpBaseResp implements Serializable {
|
||||
private static final long serialVersionUID = -5028321625142879581L;
|
||||
|
||||
@SerializedName("file_list")
|
||||
private FileList fileList;
|
||||
|
||||
@Getter
|
||||
@Setter
|
||||
public static class FileList implements Serializable {
|
||||
private static final long serialVersionUID = -4960239393895754598L;
|
||||
|
||||
@SerializedName("item")
|
||||
private List<Item> item;
|
||||
|
||||
public static FileList fromJson(String json) {
|
||||
return WxCpGsonBuilder.create().fromJson(json, FileList.class);
|
||||
}
|
||||
|
||||
public String toJson() {
|
||||
return WxCpGsonBuilder.create().toJson(this);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Getter
|
||||
@Setter
|
||||
public static class Item implements Serializable {
|
||||
private static final long serialVersionUID = -4960239393895754598L;
|
||||
|
||||
@SerializedName("fileid")
|
||||
private String fileId;
|
||||
|
||||
@SerializedName("file_name")
|
||||
private String fileName;
|
||||
|
||||
@SerializedName("spaceid")
|
||||
private String spaceId;
|
||||
|
||||
@SerializedName("fatherid")
|
||||
private String fatherId;
|
||||
|
||||
@SerializedName("file_size")
|
||||
private Long fileSize;
|
||||
|
||||
@SerializedName("ctime")
|
||||
private Long cTime;
|
||||
|
||||
@SerializedName("mtime")
|
||||
private Long mTime;
|
||||
|
||||
@SerializedName("file_type")
|
||||
private Integer fileType;
|
||||
|
||||
@SerializedName("file_status")
|
||||
private Integer fileStatus;
|
||||
|
||||
@SerializedName("create_userid")
|
||||
private String createUserId;
|
||||
|
||||
@SerializedName("update_userid")
|
||||
private String updateUserId;
|
||||
|
||||
@SerializedName("sha")
|
||||
private String sha;
|
||||
|
||||
@SerializedName("md5")
|
||||
private String md5;
|
||||
|
||||
public static Item fromJson(String json) {
|
||||
return WxCpGsonBuilder.create().fromJson(json, Item.class);
|
||||
}
|
||||
|
||||
public String toJson() {
|
||||
return WxCpGsonBuilder.create().toJson(this);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public static WxCpFileMove fromJson(String json) {
|
||||
return WxCpGsonBuilder.create().fromJson(json, WxCpFileMove.class);
|
||||
}
|
||||
|
||||
public String toJson() {
|
||||
return WxCpGsonBuilder.create().toJson(this);
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,58 @@
|
||||
package me.chanjar.weixin.cp.bean.oa.wedrive;
|
||||
|
||||
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;
|
||||
|
||||
/**
|
||||
* 移动文件请求.
|
||||
*/
|
||||
@Data
|
||||
@Builder
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
@Accessors(chain = true)
|
||||
public class WxCpFileMoveRequest implements Serializable {
|
||||
private static final long serialVersionUID = -4960239393895754138L;
|
||||
|
||||
/**
|
||||
* 操作者userid
|
||||
*/
|
||||
@SerializedName("userid")
|
||||
private String userId;
|
||||
|
||||
/**
|
||||
* 如果移动到的目标目录与需要移动的文件重名时,是否覆盖。
|
||||
* true:重名文件覆盖
|
||||
* false:重名文件进行冲突重命名处理(移动后文件名格式如xxx(1).txt xxx(1).doc等)
|
||||
*/
|
||||
@SerializedName("replace")
|
||||
private Boolean replace;
|
||||
|
||||
/**
|
||||
* 当前目录的fileid,根目录时为空间spaceid
|
||||
*/
|
||||
@SerializedName("fatherid")
|
||||
private String fatherId;
|
||||
|
||||
/**
|
||||
* 文件fileid
|
||||
*/
|
||||
@SerializedName("fileid")
|
||||
private String[] fileId;
|
||||
|
||||
public static WxCpFileMoveRequest fromJson(String json) {
|
||||
return WxCpGsonBuilder.create().fromJson(json, WxCpFileMoveRequest.class);
|
||||
}
|
||||
|
||||
public String toJson() {
|
||||
return WxCpGsonBuilder.create().toJson(this);
|
||||
}
|
||||
|
||||
}
|
@ -158,6 +158,9 @@ public interface WxCpApiPathConsts {
|
||||
String FILE_DOWNLOAD = "/cgi-bin/wedrive/file_download";
|
||||
String FILE_RENAME = "/cgi-bin/wedrive/file_rename";
|
||||
String FILE_CREATE = "/cgi-bin/wedrive/file_create";
|
||||
String FILE_MOVE = "/cgi-bin/wedrive/file_move";
|
||||
String FILE_DELETE = "/cgi-bin/wedrive/file_delete";
|
||||
String FILE_INFO = "/cgi-bin/wedrive/file_info";
|
||||
|
||||
/**
|
||||
* 审批流程引擎
|
||||
|
@ -1,5 +1,6 @@
|
||||
package me.chanjar.weixin.cp.api;
|
||||
|
||||
import com.google.common.collect.Lists;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import me.chanjar.weixin.cp.api.impl.WxCpServiceImpl;
|
||||
import me.chanjar.weixin.cp.bean.WxCpBaseResp;
|
||||
@ -47,6 +48,33 @@ public class WxCpOaWeDriveServiceTest {
|
||||
String fileId = "s.ww45d3e188865aca30.652091685u4h_f.652344507ysDL";
|
||||
String fileId2 = "s.ww45d3e188865aca30.652091685u4h_f.652696024TU4P";
|
||||
|
||||
|
||||
/**
|
||||
* 删除文件
|
||||
*/
|
||||
ArrayList<String> fileIds = Lists.newArrayList();
|
||||
fileIds.add(fileId);
|
||||
WxCpBaseResp fileDelete = cpService.getOaWeDriveService().fileDelete(uId, fileIds);
|
||||
log.info("删除文件数据为:{}", fileDelete.toJson());
|
||||
|
||||
/**
|
||||
* 文件信息
|
||||
*/
|
||||
WxCpFileInfo fileInfo = cpService.getOaWeDriveService().fileInfo(uId, fileId);
|
||||
log.info("fileInfo数据为:{}", fileInfo.toJson());
|
||||
|
||||
/**
|
||||
* 移动文件
|
||||
*/
|
||||
WxCpFileMoveRequest fileMoveRequest = new WxCpFileMoveRequest();
|
||||
fileMoveRequest.setUserId(uId);
|
||||
fileMoveRequest.setFatherId(spId);
|
||||
fileMoveRequest.setReplace(true);
|
||||
fileMoveRequest.setFileId(new String[]{fileId});
|
||||
|
||||
WxCpFileMove fileMove = cpService.getOaWeDriveService().fileMove(fileMoveRequest);
|
||||
log.info("fileMove数据为:{}", fileMove.toJson());
|
||||
|
||||
/**
|
||||
* 新建文件/微文档
|
||||
*/
|
||||
|
Loading…
Reference in New Issue
Block a user