package com.hx.mp.util;
|
|
import com.alibaba.fastjson.JSONArray;
|
import com.alibaba.fastjson.JSONObject;
|
import com.hx.api.CorpMpSpaceApi;
|
import java.util.List;
|
|
/**
|
* 企业微信微盘接口API
|
* @Author: cmg
|
* @Date: 2023-7-13 11:08
|
*/
|
public class CorpMpSpaceUtil {
|
|
/**
|
* 增加空间
|
* @param corpMpSpaceApi
|
* @param accessToken
|
* @param name 空间名称
|
* @param depId 部门id
|
* @param adminId 管理员的企业微信id
|
* @return
|
*/
|
public static JSONObject addSpace(CorpMpSpaceApi corpMpSpaceApi, String accessToken, String name, Integer depId, String adminId)
|
{
|
JSONObject obj = new JSONObject();
|
obj.put("space_name", name);
|
JSONArray arr = new JSONArray();
|
|
//设置部门的可下载权限
|
JSONObject temp = new JSONObject();
|
temp.put("type", 2);
|
temp.put("departmentid", depId);
|
temp.put("auth", 1);
|
arr.add(temp);
|
|
//设置管理员
|
temp = new JSONObject();
|
temp.put("type", 1);
|
temp.put("userid", adminId);
|
temp.put("auth", 7);
|
arr.add(temp);
|
|
obj.put("auth_info", arr);
|
|
return corpMpSpaceApi.addSpace(accessToken, obj.toJSONString());
|
}
|
|
/**
|
* 空间重命名
|
* @param corpMpSpaceApi
|
* @param accessToken
|
* @param spaceId
|
* @param name
|
* @return
|
*/
|
public static JSONObject editSpaceName(CorpMpSpaceApi corpMpSpaceApi, String accessToken, String spaceId, String name)
|
{
|
JSONObject obj = new JSONObject();
|
obj.put("space_name", name);
|
obj.put("spaceid", spaceId);
|
|
return corpMpSpaceApi.renameSpace(accessToken, obj.toJSONString());
|
}
|
|
/**
|
* 空间设置
|
* @param corpMpSpaceApi
|
* @param accessToken
|
* @param spaceId
|
* @param enableConfidentialMode
|
* @return
|
*/
|
public static JSONObject spaceSetting(CorpMpSpaceApi corpMpSpaceApi, String accessToken, String spaceId, boolean enableConfidentialMode)
|
{
|
JSONObject obj = new JSONObject();
|
obj.put("spaceid", spaceId);
|
obj.put("enable_confidential_mode", enableConfidentialMode);
|
|
return corpMpSpaceApi.spaceSetting(accessToken, obj.toJSONString());
|
}
|
|
/**
|
* 创建文件夹
|
* @param corpMpSpaceApi
|
* @param accessToken
|
* @param spaceId 空间id
|
* @param fatherId 上级目录id,如果是空间下第一级,则是空间id
|
* @param fileName 文件夹名称
|
* @return
|
*/
|
public static JSONObject createDir(CorpMpSpaceApi corpMpSpaceApi, String accessToken, String spaceId, String fatherId, String fileName)
|
{
|
JSONObject param = new JSONObject();
|
param.put("spaceid", spaceId);
|
param.put("fatherid", fatherId);
|
param.put("file_type", 1);
|
param.put("file_name", fileName);
|
|
|
return corpMpSpaceApi.createFile(accessToken, param.toJSONString());
|
}
|
|
/**
|
* 文件/文件夹重命名
|
* @param corpMpSpaceApi
|
* @param accessToken
|
* @param fileId
|
* @param fileName
|
* @return
|
*/
|
public static JSONObject editDirName(CorpMpSpaceApi corpMpSpaceApi, String accessToken, String fileId, String fileName)
|
{
|
JSONObject param = new JSONObject();
|
param.put("fileid", fileId);
|
param.put("new_name", fileName);
|
|
return corpMpSpaceApi.renameFile(accessToken, param.toJSONString());
|
}
|
|
/**
|
* 移除文件夹
|
* @param corpMpSpaceApi
|
* @param accessToken
|
* @param fileId
|
* @return
|
*/
|
public static JSONObject deleteDir(CorpMpSpaceApi corpMpSpaceApi, String accessToken, String fileId)
|
{
|
JSONObject param = new JSONObject();
|
|
JSONArray arr = new JSONArray();
|
arr.add(fileId);
|
|
param.put("fileid", arr);
|
|
return corpMpSpaceApi.deleteFile(accessToken, param.toJSONString());
|
}
|
|
/**
|
* 传10M以内文件
|
* @param corpMpSpaceApi
|
* @param accessToken
|
* @param name
|
* @param fileBase64Content
|
* @param spaceId
|
* @param fatherId
|
* @return
|
*/
|
public static JSONObject uploadFile(CorpMpSpaceApi corpMpSpaceApi, String accessToken, String name, String fileBase64Content, String spaceId, String fatherId) {
|
JSONObject param = new JSONObject();
|
param.put("spaceid", spaceId);
|
param.put("fatherid", fatherId);
|
param.put("file_name", name);
|
param.put("file_base64_content", fileBase64Content);
|
|
return corpMpSpaceApi.fileUpload(accessToken, param.toJSONString());
|
}
|
|
/**
|
* 分块上传文件-初始化
|
* @param corpMpSpaceApi
|
* @param accessToken
|
* @param spaceId
|
* @param fatherId
|
* @param selectTicket
|
* @param fileName
|
* @param size
|
* @param skipPushCard
|
* @param blockSha
|
* @return
|
*/
|
public static JSONObject uploadBigFileInit(CorpMpSpaceApi corpMpSpaceApi, String accessToken, String spaceId, String fatherId,
|
String selectTicket, String fileName, Long size, boolean skipPushCard, List<String> blockSha) {
|
JSONObject param = new JSONObject();
|
param.put("spaceid", spaceId);
|
param.put("fatherid", fatherId);
|
param.put("selected_ticket", selectTicket);
|
param.put("file_name", fileName);
|
param.put("size", size);
|
param.put("skip_push_card", skipPushCard);
|
|
JSONArray arr = new JSONArray();
|
for(String sha : blockSha)
|
{
|
arr.add(sha);
|
}
|
param.put("block_sha", arr);
|
|
return corpMpSpaceApi.fileUploadInit(accessToken, param.toJSONString());
|
}
|
|
/**
|
* 分块上传文件-部分上传
|
* @param corpMpSpaceApi
|
* @param accessToken
|
* @param uploadKey
|
* @param index
|
* @param fileBase64Content
|
* @return
|
*/
|
public static JSONObject uploadBigFilePart(CorpMpSpaceApi corpMpSpaceApi, String accessToken, String uploadKey, int index, String fileBase64Content) {
|
JSONObject param = new JSONObject();
|
param.put("upload_key", uploadKey);
|
param.put("index", index);
|
param.put("file_base64_content", fileBase64Content);
|
|
return corpMpSpaceApi.fileUploadPart(accessToken, param.toJSONString());
|
}
|
|
/**
|
* 分块上传文件-上传完成
|
* @param corpMpSpaceApi
|
* @param accessToken
|
* @param uploadKey
|
* @return
|
*/
|
public static JSONObject uploadBigFileFin(CorpMpSpaceApi corpMpSpaceApi, String accessToken, String uploadKey) {
|
JSONObject param = new JSONObject();
|
param.put("upload_key", uploadKey);
|
|
return corpMpSpaceApi.fileUploadFinish(accessToken, param.toJSONString());
|
}
|
|
/**
|
* 获取下载路径
|
* @param corpMpSpaceApi
|
* @param accessToken
|
* @param fileId
|
* @return
|
*/
|
public static JSONObject getDownloadUrl(CorpMpSpaceApi corpMpSpaceApi, String accessToken, String fileId){
|
JSONObject param = new JSONObject();
|
param.put("fileid", fileId);
|
|
return corpMpSpaceApi.getDownloadUrl(accessToken, param.toJSONString());
|
}
|
}
|