mirror of
https://gitee.com/binary/weixin-java-tools.git
synced 2025-04-05 17:38:05 +08:00
🆕 #2624【企业微信】增加微盘重命名以及解散空间的接口
This commit is contained in:
parent
5227c45653
commit
f1977f53fd
@ -2,8 +2,10 @@ 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;
|
||||
|
||||
/**
|
||||
* 企业微信微盘相关接口.
|
||||
@ -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;
|
||||
|
||||
}
|
||||
|
@ -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 class WxCpOaWeDriveServiceImpl implements WxCpOaWeDriveService {
|
||||
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);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -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);
|
||||
}
|
||||
|
||||
}
|
@ -146,6 +146,8 @@ public interface WxCpApiPathConsts {
|
||||
* 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";
|
||||
|
||||
/**
|
||||
* 审批流程引擎
|
||||
|
@ -3,8 +3,10 @@ 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.config.WxCpConfigStorage;
|
||||
import me.chanjar.weixin.cp.demo.WxCpDemoInMemoryConfigStorage;
|
||||
import org.testng.annotations.Test;
|
||||
@ -37,17 +39,34 @@ public class WxCpOaWeDriveServiceTest {
|
||||
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());
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user