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 39b6d4d5f5..228b6920ae 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 @@ -2,8 +2,10 @@ 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; /** * 企业微信微盘相关接口. @@ -28,4 +30,31 @@ public interface WxCpOaWeDriveService { */ WxCpSpaceCreateData spaceCreate(@NonNull WxCpSpaceCreateRequest request) throws WxErrorException; + /** + * 重命名空间 + * 该接口用于重命名已有空间,接收userid参数,以空间管理员身份来重命名。 + * + * 请求方式:POST(HTTPS) + * 请求地址: https://qyapi.weixin.qq.com/cgi-bin/wedrive/space_rename?access_token=ACCESS_TOKEN + * + * @param request 重命名空间的请求参数 + * @return + * @throws WxErrorException + */ + WxCpBaseResp spaceRename(@NonNull WxCpSpaceRenameRequest request) throws WxErrorException; + + /** + * 解散空间 + * 该接口用于解散已有空间,需要以空间管理员身份来解散。 + * + * 请求方式:POST(HTTPS) + * 请求地址: https://qyapi.weixin.qq.com/cgi-bin/wedrive/space_dismiss?access_token=ACCESS_TOKEN + * + * @param userId + * @param spaceId + * @return + * @throws WxErrorException + */ + WxCpBaseResp spaceDismiss(@NonNull String userId, @NonNull String spaceId) 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 5f58cbb452..eace47a91e 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 @@ -1,15 +1,18 @@ package me.chanjar.weixin.cp.api.impl; +import com.google.gson.JsonObject; import lombok.NonNull; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; 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 static me.chanjar.weixin.cp.constant.WxCpApiPathConsts.Oa.SPACE_CREATE; +import static me.chanjar.weixin.cp.constant.WxCpApiPathConsts.Oa.*; /** * 企业微信微盘接口实现类. @@ -29,4 +32,21 @@ public WxCpSpaceCreateData spaceCreate(@NonNull WxCpSpaceCreateRequest request) return WxCpSpaceCreateData.fromJson(responseContent); } + @Override + public WxCpBaseResp spaceRename(@NonNull WxCpSpaceRenameRequest request) throws WxErrorException { + String apiUrl = this.cpService.getWxCpConfigStorage().getApiUrl(SPACE_RENAME); + String responseContent = this.cpService.post(apiUrl, request.toJson()); + return WxCpBaseResp.fromJson(responseContent); + } + + @Override + public WxCpBaseResp spaceDismiss(@NonNull String userId, @NonNull String spaceId) throws WxErrorException { + String apiUrl = this.cpService.getWxCpConfigStorage().getApiUrl(SPACE_DISMISS); + JsonObject jsonObject = new JsonObject(); + jsonObject.addProperty("userid", userId); + jsonObject.addProperty("spaceid", spaceId); + String responseContent = this.cpService.post(apiUrl, jsonObject.toString()); + return WxCpBaseResp.fromJson(responseContent); + } + } diff --git a/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/bean/oa/wedrive/WxCpSpaceRenameRequest.java b/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/bean/oa/wedrive/WxCpSpaceRenameRequest.java new file mode 100644 index 0000000000..f7f313326e --- /dev/null +++ b/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/bean/oa/wedrive/WxCpSpaceRenameRequest.java @@ -0,0 +1,41 @@ +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 WxCpSpaceRenameRequest implements Serializable { + private static final long serialVersionUID = -4960239393895754138L; + + @SerializedName("userid") + private String userId; + + @SerializedName("spaceid") + private String spaceId; + + @SerializedName("space_name") + private String spaceName; + + public static WxCpSpaceRenameRequest fromJson(String json) { + return WxCpGsonBuilder.create().fromJson(json, WxCpSpaceRenameRequest.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 2923d8f45a..d617804c42 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 @@ -145,6 +145,8 @@ interface Oa { * https://developer.work.weixin.qq.com/document/path/93654 */ String SPACE_CREATE = "/cgi-bin/wedrive/space_create"; + String SPACE_RENAME = "/cgi-bin/wedrive/space_rename"; + String SPACE_DISMISS = "/cgi-bin/wedrive/space_dismiss"; /** * 审批流程引擎 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 eb7b682948..f212ce02bb 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 @@ -3,8 +3,10 @@ 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.config.WxCpConfigStorage; import me.chanjar.weixin.cp.demo.WxCpDemoInMemoryConfigStorage; import org.testng.annotations.Test; @@ -37,17 +39,34 @@ public void test() throws WxErrorException { WxCpSpaceCreateRequest wxCpSpaceCreateRequest = WxCpSpaceCreateRequest.fromJson(createSpace); log.info(wxCpSpaceCreateRequest.toJson()); + /** * 新建空间 */ WxCpSpaceCreateRequest request = new WxCpSpaceCreateRequest(); request.setUserId("WangKai"); - request.setSpaceName("测试云盘2"); + request.setSpaceName("测试云盘Three"); WxCpSpaceCreateData spaceCreateData = cpService.getOaWeDriveService().spaceCreate(request); - log.info("空间id为:{}", spaceCreateData.getSpaceId()); + log.info("空间id为:{}", spaceCreateData.getSpaceId()); // log.info(spaceCreateData.toJson()); + /** + * 重命名空间 + */ + WxCpSpaceRenameRequest wxCpSpaceRenameRequest = new WxCpSpaceRenameRequest(); + wxCpSpaceRenameRequest.setUserId("WangKai"); + wxCpSpaceRenameRequest.setSpaceId(spaceCreateData.getSpaceId()); + wxCpSpaceRenameRequest.setSpaceName("测试云盘Four"); + WxCpBaseResp baseResp = cpService.getOaWeDriveService().spaceRename(wxCpSpaceRenameRequest); + log.info("重命名成功:{}", baseResp.toJson()); + + /** + * 解散空间 + */ + WxCpBaseResp thisResp = cpService.getOaWeDriveService().spaceDismiss("WangKai", spaceCreateData.getSpaceId()); + log.info("解散成功:{}", thisResp.toJson()); + } }