Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
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
Expand Down Expand Up @@ -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;

}
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
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.*;

/**
Expand Down Expand Up @@ -117,7 +119,7 @@ public WxCpFileRename fileRename(@NonNull String userId, @NonNull String fileId,
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);
Expand All @@ -136,4 +138,29 @@ public WxCpFileCreate fileCreate(@NonNull String userId, @NonNull String spaceId
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);
}

}
Original file line number Diff line number Diff line change
@@ -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);
}

}
Original file line number Diff line number Diff line change
@@ -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);
}

}
Original file line number Diff line number Diff line change
@@ -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);
}

}
Original file line number Diff line number Diff line change
@@ -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);
}

}
Loading