From 7e96d6ab0f00240b962c01403c9b08b04a978d13 Mon Sep 17 00:00:00 2001 From: 0katekate0 <32161300+0katekate0@users.noreply.github.com> Date: Tue, 10 May 2022 22:19:12 +0800 Subject: [PATCH] =?UTF-8?q?:new:=20#2637=E3=80=90=E4=BC=81=E4=B8=9A?= =?UTF-8?q?=E5=BE=AE=E4=BF=A1=E3=80=91=E6=96=B0=E5=A2=9E=E5=BE=AE=E7=9B=98?= =?UTF-8?q?=E8=8E=B7=E5=8F=96=E7=A9=BA=E9=97=B4=E4=BF=A1=E6=81=AF=E7=9A=84?= =?UTF-8?q?=E6=8E=A5=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../weixin/cp/api/WxCpOaWeDriveService.java | 49 +++++++- .../cp/api/impl/WxCpOaWeDriveServiceImpl.java | 28 ++++- .../oa/wedrive/WxCpSpaceAclAddRequest.java | 66 +++++++++++ .../oa/wedrive/WxCpSpaceAclDelRequest.java | 63 +++++++++++ .../cp/bean/oa/wedrive/WxCpSpaceInfo.java | 105 ++++++++++++++++++ .../weixin/cp/constant/WxCpApiPathConsts.java | 3 + .../cp/api/WxCpOaWeDriveServiceTest.java | 62 ++++++++++- 7 files changed, 363 insertions(+), 13 deletions(-) create mode 100644 weixin-java-cp/src/main/java/me/chanjar/weixin/cp/bean/oa/wedrive/WxCpSpaceAclAddRequest.java create mode 100644 weixin-java-cp/src/main/java/me/chanjar/weixin/cp/bean/oa/wedrive/WxCpSpaceAclDelRequest.java create mode 100644 weixin-java-cp/src/main/java/me/chanjar/weixin/cp/bean/oa/wedrive/WxCpSpaceInfo.java diff --git a/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/WxCpOaWeDriveService.java b/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/WxCpOaWeDriveService.java index 228b6920a..05b99bde8 100644 --- a/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/WxCpOaWeDriveService.java +++ b/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/WxCpOaWeDriveService.java @@ -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参数,以空间管理员身份来重命名。 - * + *

* 请求方式:POST(HTTPS) * 请求地址: https://qyapi.weixin.qq.com/cgi-bin/wedrive/space_rename?access_token=ACCESS_TOKEN * @@ -46,7 +43,7 @@ public interface WxCpOaWeDriveService { /** * 解散空间 * 该接口用于解散已有空间,需要以空间管理员身份来解散。 - * + *

* 请求方式:POST(HTTPS) * 请求地址: 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; + /** + * 获取空间信息 + * 该接口用于获取空间成员列表、信息、权限等信息。 + *

+ * 请求方式:POST(HTTPS) + * 请求地址: 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; + + /** + * 添加成员/部门 + * 该接口用于对指定空间添加成员/部门,可一次性添加多个。 + *

+ * 请求方式:POST(HTTPS) + * 请求地址: 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; + + /** + * 移除成员/部门 + * 该接口用于对指定空间移除成员/部门,操作者需要有移除权限。 + *

+ * 请求方式:POST(HTTPS) + * 请求地址: 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; + } diff --git a/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/impl/WxCpOaWeDriveServiceImpl.java b/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/impl/WxCpOaWeDriveServiceImpl.java index eace47a91..cc5d53111 100644 --- a/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/impl/WxCpOaWeDriveServiceImpl.java +++ b/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/impl/WxCpOaWeDriveServiceImpl.java @@ -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); + } + } diff --git a/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/bean/oa/wedrive/WxCpSpaceAclAddRequest.java b/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/bean/oa/wedrive/WxCpSpaceAclAddRequest.java new file mode 100644 index 000000000..94d65b43f --- /dev/null +++ b/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/bean/oa/wedrive/WxCpSpaceAclAddRequest.java @@ -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; + + @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); + } + +} diff --git a/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/bean/oa/wedrive/WxCpSpaceAclDelRequest.java b/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/bean/oa/wedrive/WxCpSpaceAclDelRequest.java new file mode 100644 index 000000000..272d9a57b --- /dev/null +++ b/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/bean/oa/wedrive/WxCpSpaceAclDelRequest.java @@ -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; + + @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); + } + +} diff --git a/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/bean/oa/wedrive/WxCpSpaceInfo.java b/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/bean/oa/wedrive/WxCpSpaceInfo.java new file mode 100644 index 000000000..821b7ef5e --- /dev/null +++ b/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/bean/oa/wedrive/WxCpSpaceInfo.java @@ -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; + + @SerializedName("quit_userid") + private List 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); + } + +} diff --git a/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/constant/WxCpApiPathConsts.java b/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/constant/WxCpApiPathConsts.java index dbf78fe73..beabef410 100644 --- a/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/constant/WxCpApiPathConsts.java +++ b/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/constant/WxCpApiPathConsts.java @@ -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"; /** * 审批流程引擎 diff --git a/weixin-java-cp/src/test/java/me/chanjar/weixin/cp/api/WxCpOaWeDriveServiceTest.java b/weixin-java-cp/src/test/java/me/chanjar/weixin/cp/api/WxCpOaWeDriveServiceTest.java index f212ce02b..93b69e167 100644 --- a/weixin-java-cp/src/test/java/me/chanjar/weixin/cp/api/WxCpOaWeDriveServiceTest.java +++ b/weixin-java-cp/src/test/java/me/chanjar/weixin/cp/api/WxCpOaWeDriveServiceTest.java @@ -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 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 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()); /** * 新建空间