🆕 #2637【企业微信】新增微盘获取空间信息的接口

This commit is contained in:
0katekate0 2022-05-10 22:19:12 +08:00 committed by GitHub
parent d6301d3c2e
commit 7e96d6ab0f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 363 additions and 13 deletions

View File

@ -3,9 +3,7 @@ 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.wedrive.WxCpSpaceCreateData;
import me.chanjar.weixin.cp.bean.oa.wedrive.WxCpSpaceCreateRequest;
import me.chanjar.weixin.cp.bean.oa.wedrive.WxCpSpaceRenameRequest;
import me.chanjar.weixin.cp.bean.oa.wedrive.*;
/**
* 企业微信微盘相关接口.
@ -25,7 +23,6 @@ public interface WxCpOaWeDriveService {
*
* @param request 新建空间对应请求参数
* @return spaceid空间id
*
* @throws WxErrorException
*/
WxCpSpaceCreateData spaceCreate(@NonNull WxCpSpaceCreateRequest request) throws WxErrorException;
@ -33,7 +30,7 @@ public interface WxCpOaWeDriveService {
/**
* 重命名空间
* 该接口用于重命名已有空间接收userid参数以空间管理员身份来重命名
*
* <p>
* 请求方式POSTHTTPS
* 请求地址: https://qyapi.weixin.qq.com/cgi-bin/wedrive/space_rename?access_token=ACCESS_TOKEN
*
@ -46,7 +43,7 @@ public interface WxCpOaWeDriveService {
/**
* 解散空间
* 该接口用于解散已有空间需要以空间管理员身份来解散
*
* <p>
* 请求方式POSTHTTPS
* 请求地址: https://qyapi.weixin.qq.com/cgi-bin/wedrive/space_dismiss?access_token=ACCESS_TOKEN
*
@ -57,4 +54,44 @@ public interface WxCpOaWeDriveService {
*/
WxCpBaseResp spaceDismiss(@NonNull String userId, @NonNull String spaceId) throws WxErrorException;
/**
* 获取空间信息
* 该接口用于获取空间成员列表信息权限等信息
* <p>
* 请求方式POSTHTTPS
* 请求地址: https://qyapi.weixin.qq.com/cgi-bin/wedrive/space_info?access_token=ACCESS_TOKEN
*
* @param userId
* @param spaceId
* @return
* @throws WxErrorException
*/
WxCpSpaceInfo spaceInfo(@NonNull String userId, @NonNull String spaceId) throws WxErrorException;
/**
* 添加成员/部门
* 该接口用于对指定空间添加成员/部门可一次性添加多个
* <p>
* 请求方式POSTHTTPS
* 请求地址: https://qyapi.weixin.qq.com/cgi-bin/wedrive/space_acl_add?access_token=ACCESS_TOKEN
*
* @param request 添加成员/部门请求参数
* @return
* @throws WxErrorException
*/
WxCpBaseResp spaceAclAdd(@NonNull WxCpSpaceAclAddRequest request) throws WxErrorException;
/**
* 移除成员/部门
* 该接口用于对指定空间移除成员/部门操作者需要有移除权限
* <p>
* 请求方式POSTHTTPS
* 请求地址: https://qyapi.weixin.qq.com/cgi-bin/wedrive/space_acl_del?access_token=ACCESS_TOKEN
*
* @param request 移除成员/部门请求参数
* @return
* @throws WxErrorException
*/
WxCpBaseResp spaceAclDel(@NonNull WxCpSpaceAclDelRequest request) throws WxErrorException;
}

View File

@ -8,9 +8,7 @@ import me.chanjar.weixin.common.error.WxErrorException;
import me.chanjar.weixin.cp.api.WxCpOaWeDriveService;
import me.chanjar.weixin.cp.api.WxCpService;
import me.chanjar.weixin.cp.bean.WxCpBaseResp;
import me.chanjar.weixin.cp.bean.oa.wedrive.WxCpSpaceCreateData;
import me.chanjar.weixin.cp.bean.oa.wedrive.WxCpSpaceCreateRequest;
import me.chanjar.weixin.cp.bean.oa.wedrive.WxCpSpaceRenameRequest;
import me.chanjar.weixin.cp.bean.oa.wedrive.*;
import static me.chanjar.weixin.cp.constant.WxCpApiPathConsts.Oa.*;
@ -49,4 +47,28 @@ public class WxCpOaWeDriveServiceImpl implements WxCpOaWeDriveService {
return WxCpBaseResp.fromJson(responseContent);
}
@Override
public WxCpSpaceInfo spaceInfo(@NonNull String userId, @NonNull String spaceId) throws WxErrorException {
String apiUrl = this.cpService.getWxCpConfigStorage().getApiUrl(SPACE_INFO);
JsonObject jsonObject = new JsonObject();
jsonObject.addProperty("userid", userId);
jsonObject.addProperty("spaceid", spaceId);
String responseContent = this.cpService.post(apiUrl, jsonObject.toString());
return WxCpSpaceInfo.fromJson(responseContent);
}
@Override
public WxCpBaseResp spaceAclAdd(@NonNull WxCpSpaceAclAddRequest request) throws WxErrorException {
String apiUrl = this.cpService.getWxCpConfigStorage().getApiUrl(SPACE_ACL_ADD);
String responseContent = this.cpService.post(apiUrl, request.toJson());
return WxCpBaseResp.fromJson(responseContent);
}
@Override
public WxCpBaseResp spaceAclDel(@NonNull WxCpSpaceAclDelRequest request) throws WxErrorException {
String apiUrl = this.cpService.getWxCpConfigStorage().getApiUrl(SPACE_ACL_DEL);
String responseContent = this.cpService.post(apiUrl, request.toJson());
return WxCpBaseResp.fromJson(responseContent);
}
}

View File

@ -0,0 +1,66 @@
package me.chanjar.weixin.cp.bean.oa.wedrive;
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 WxCpSpaceAclAddRequest implements Serializable {
private static final long serialVersionUID = -4960239393895754138L;
@SerializedName("userid")
private String userId;
@SerializedName("spaceid")
private String spaceId;
@SerializedName("auth_info")
private List<AuthInfo> authInfo;
@Getter
@Setter
public static class AuthInfo implements Serializable {
private static final long serialVersionUID = -4960239393895754598L;
@SerializedName("type")
private Integer type;
@SerializedName("departmentid")
private Integer departmentId;
@SerializedName("auth")
private Integer auth;
@SerializedName("userid")
private String userId;
public static AuthInfo fromJson(String json) {
return WxCpGsonBuilder.create().fromJson(json, AuthInfo.class);
}
public String toJson() {
return WxCpGsonBuilder.create().toJson(this);
}
}
public static WxCpSpaceAclAddRequest fromJson(String json) {
return WxCpGsonBuilder.create().fromJson(json, WxCpSpaceAclAddRequest.class);
}
public String toJson() {
return WxCpGsonBuilder.create().toJson(this);
}
}

View File

@ -0,0 +1,63 @@
package me.chanjar.weixin.cp.bean.oa.wedrive;
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 WxCpSpaceAclDelRequest implements Serializable {
private static final long serialVersionUID = -4960239393895754138L;
@SerializedName("userid")
private String userId;
@SerializedName("spaceid")
private String spaceId;
@SerializedName("auth_info")
private List<AuthInfo> authInfo;
@Getter
@Setter
public static class AuthInfo implements Serializable {
private static final long serialVersionUID = -4960239393895754598L;
@SerializedName("type")
private Integer type;
@SerializedName("departmentid")
private Integer departmentId;
@SerializedName("userid")
private String userId;
public static AuthInfo fromJson(String json) {
return WxCpGsonBuilder.create().fromJson(json, AuthInfo.class);
}
public String toJson() {
return WxCpGsonBuilder.create().toJson(this);
}
}
public static WxCpSpaceAclDelRequest fromJson(String json) {
return WxCpGsonBuilder.create().fromJson(json, WxCpSpaceAclDelRequest.class);
}
public String toJson() {
return WxCpGsonBuilder.create().toJson(this);
}
}

View File

@ -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 WxCpSpaceInfo extends WxCpBaseResp implements Serializable {
private static final long serialVersionUID = -5028321625142879581L;
@SerializedName("space_info")
private SpaceInfo spaceInfo;
@Getter
@Setter
public static class SpaceInfo implements Serializable {
private static final long serialVersionUID = -4960239393895754598L;
@SerializedName("spaceid")
private String spaceId;
@SerializedName("space_name")
private String spaceName;
@SerializedName("auth_list")
private AuthList authList;
public static SpaceInfo fromJson(String json) {
return WxCpGsonBuilder.create().fromJson(json, SpaceInfo.class);
}
public String toJson() {
return WxCpGsonBuilder.create().toJson(this);
}
}
@Getter
@Setter
public static class AuthList implements Serializable {
private static final long serialVersionUID = -4960239393895754598L;
@SerializedName("auth_info")
private List<AuthInfo> authInfo;
@SerializedName("quit_userid")
private List<String> quitUserId;
public static AuthList fromJson(String json) {
return WxCpGsonBuilder.create().fromJson(json, AuthList.class);
}
public String toJson() {
return WxCpGsonBuilder.create().toJson(this);
}
}
@Getter
@Setter
public static class AuthInfo implements Serializable {
private static final long serialVersionUID = -4960239393895754598L;
@SerializedName("type")
private Integer type;
@SerializedName("departmentid")
private Integer departmentId;
@SerializedName("auth")
private Integer auth;
@SerializedName("userid")
private String userId;
public static AuthInfo fromJson(String json) {
return WxCpGsonBuilder.create().fromJson(json, AuthInfo.class);
}
public String toJson() {
return WxCpGsonBuilder.create().toJson(this);
}
}
public static WxCpSpaceInfo fromJson(String json) {
return WxCpGsonBuilder.create().fromJson(json, WxCpSpaceInfo.class);
}
public String toJson() {
return WxCpGsonBuilder.create().toJson(this);
}
}

View File

@ -148,6 +148,9 @@ public interface WxCpApiPathConsts {
String SPACE_CREATE = "/cgi-bin/wedrive/space_create";
String SPACE_RENAME = "/cgi-bin/wedrive/space_rename";
String SPACE_DISMISS = "/cgi-bin/wedrive/space_dismiss";
String SPACE_INFO = "/cgi-bin/wedrive/space_info";
String SPACE_ACL_ADD = "/cgi-bin/wedrive/space_acl_add";
String SPACE_ACL_DEL = "/cgi-bin/wedrive/space_acl_del";
/**
* 审批流程引擎

View File

@ -1,17 +1,16 @@
package me.chanjar.weixin.cp.api;
import lombok.extern.slf4j.Slf4j;
import me.chanjar.weixin.common.error.WxErrorException;
import me.chanjar.weixin.cp.api.impl.WxCpServiceImpl;
import me.chanjar.weixin.cp.bean.WxCpBaseResp;
import me.chanjar.weixin.cp.bean.oa.wedrive.WxCpSpaceCreateData;
import me.chanjar.weixin.cp.bean.oa.wedrive.WxCpSpaceCreateRequest;
import me.chanjar.weixin.cp.bean.oa.wedrive.WxCpSpaceRenameRequest;
import me.chanjar.weixin.cp.bean.oa.wedrive.*;
import me.chanjar.weixin.cp.config.WxCpConfigStorage;
import me.chanjar.weixin.cp.demo.WxCpDemoInMemoryConfigStorage;
import org.testng.annotations.Test;
import java.io.InputStream;
import java.util.ArrayList;
import java.util.List;
/**
* 微盘测试类.
@ -39,6 +38,61 @@ public class WxCpOaWeDriveServiceTest {
WxCpSpaceCreateRequest wxCpSpaceCreateRequest = WxCpSpaceCreateRequest.fromJson(createSpace);
log.info(wxCpSpaceCreateRequest.toJson());
String uId = "WangKai";
String spId = "s.ww45d3e188865aca30.652091685u4h";
/**
* 获取空间信息
*/
WxCpSpaceInfo data = cpService.getOaWeDriveService().spaceInfo(uId, spId);
log.info("获取空间信息为:{}", data.toJson());
/**
* 移除成员/部门
*/
WxCpSpaceAclDelRequest spaceAclDelRequest = new WxCpSpaceAclDelRequest();
spaceAclDelRequest.setUserId(uId);
spaceAclDelRequest.setSpaceId(spId);
// 被移除的空间成员信息
WxCpSpaceAclDelRequest.AuthInfo delAuthInfo = new WxCpSpaceAclDelRequest.AuthInfo();
delAuthInfo.setType(1);
delAuthInfo.setUserId("MiaoMiu99");
List<WxCpSpaceAclDelRequest.AuthInfo> delAuthInfoList = new ArrayList<>();
delAuthInfoList.add(delAuthInfo);
spaceAclDelRequest.setAuthInfo(delAuthInfoList);
WxCpBaseResp spaceAclDel = cpService.getOaWeDriveService().spaceAclDel(spaceAclDelRequest);
log.info("移除成员/部门,返回数据为:{}", spaceAclDel.toJson());
/**
* 添加成员/部门
* https://developer.work.weixin.qq.com/document/path/93656
*/
WxCpSpaceAclAddRequest spaceAclAddRequest = new WxCpSpaceAclAddRequest();
spaceAclAddRequest.setUserId(uId);
spaceAclAddRequest.setSpaceId(spId);
List<WxCpSpaceAclAddRequest.AuthInfo> authInfoList = new ArrayList<>();
// 被添加的空间成员信息
WxCpSpaceAclAddRequest.AuthInfo authInfo = new WxCpSpaceAclAddRequest.AuthInfo();
authInfo.setAuth(2);
authInfo.setType(1);
authInfo.setUserId("MiaoMiu99");
authInfoList.add(authInfo);
spaceAclAddRequest.setAuthInfo(authInfoList);
WxCpBaseResp wxCpBaseResp = cpService.getOaWeDriveService().spaceAclAdd(spaceAclAddRequest);
log.info("添加成员/部门,返回数据为:{}", wxCpBaseResp.toJson());
/**
* 获取空间信息
*/
WxCpSpaceInfo spaceInfo = cpService.getOaWeDriveService().spaceInfo("WangKai", "s.ww45d3e188865aca30.652091685u4h");
log.info("获取空间信息spaceInfo信息为{}", spaceInfo.toJson());
/**
* 新建空间