Skip to content

Commit

Permalink
🆕 #2624【企业微信】增加微盘重命名以及解散空间的接口
Browse files Browse the repository at this point in the history
  • Loading branch information
0katekate0 authored Apr 27, 2022
1 parent 5227c45 commit f1977f5
Show file tree
Hide file tree
Showing 5 changed files with 114 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;

/**
* 企业微信微盘相关接口.
Expand All @@ -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;

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

/**
* 企业微信微盘接口实现类.
Expand All @@ -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);
}

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

}
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,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";

/**
* 审批流程引擎
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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());

}

}

0 comments on commit f1977f5

Please sign in to comment.