Skip to content

Commit

Permalink
🆕 #2614 【企业微信】新增微盘空间管理的相关接口
Browse files Browse the repository at this point in the history
  • Loading branch information
0katekate0 authored Apr 24, 2022
1 parent 8831056 commit 343fa11
Show file tree
Hide file tree
Showing 8 changed files with 231 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package me.chanjar.weixin.cp.api;

import lombok.NonNull;
import me.chanjar.weixin.common.error.WxErrorException;
import me.chanjar.weixin.cp.bean.oa.wedrive.WxCpSpaceCreateData;
import me.chanjar.weixin.cp.bean.oa.wedrive.WxCpSpaceCreateRequest;

/**
* 企业微信微盘相关接口.
* https://developer.work.weixin.qq.com/document/path/93654
*
* @author <a href="https://github.com/0katekate0">Wang_Wong</a>
* @date 2022-04-22
*/
public interface WxCpOaWeDriveService {

/**
* 新建空间
* 该接口用于在微盘内新建空间,可以指定人创建空间。
* <p>
* 请求方式:POST(HTTPS)
* 请求地址: https://qyapi.weixin.qq.com/cgi-bin/wedrive/space_create?access_token=ACCESS_TOKEN
*
* @param request 新建空间对应请求参数
* @return spaceid(空间id)
*
* @throws WxErrorException
*/
WxCpSpaceCreateData spaceCreate(@NonNull WxCpSpaceCreateRequest request) throws WxErrorException;

}
Original file line number Diff line number Diff line change
Expand Up @@ -414,6 +414,13 @@ public interface WxCpService extends WxService {
*/
WxCpOaAgentService getOaAgentService();

/**
* 获取OA效率工具 微盘的服务类对象
*
* @return
*/
WxCpOaWeDriveService getOaWeDriveService();

/**
* 获取会话存档相关接口的服务类对象
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ public abstract class BaseWxCpServiceImpl<H, P> implements WxCpService, RequestH
private WxCpOaService oaService = new WxCpOaServiceImpl(this);
private WxCpLivingService livingService = new WxCpLivingServiceImpl(this);
private WxCpOaAgentService oaAgentService = new WxCpOaAgentServiceImpl(this);
private WxCpOaWeDriveService oaWeDriveService = new WxCpOaWeDriveServiceImpl(this);
private WxCpMsgAuditService msgAuditService = new WxCpMsgAuditServiceImpl(this);
private WxCpTaskCardService taskCardService = new WxCpTaskCardServiceImpl(this);
private WxCpExternalContactService externalContactService = new WxCpExternalContactServiceImpl(this);
Expand Down Expand Up @@ -502,6 +503,11 @@ public WxCpOaAgentService getOaAgentService() {
return oaAgentService;
}

@Override
public WxCpOaWeDriveService getOaWeDriveService() {
return oaWeDriveService;
}

@Override
public WxCpMsgAuditService getMsgAuditService() {
return msgAuditService;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package me.chanjar.weixin.cp.api.impl;

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.oa.wedrive.WxCpSpaceCreateData;
import me.chanjar.weixin.cp.bean.oa.wedrive.WxCpSpaceCreateRequest;

import static me.chanjar.weixin.cp.constant.WxCpApiPathConsts.Oa.SPACE_CREATE;

/**
* 企业微信微盘接口实现类.
*
* @author Wang_Wong
* @date 2022-04-22
*/
@Slf4j
@RequiredArgsConstructor
public class WxCpOaWeDriveServiceImpl implements WxCpOaWeDriveService {
private final WxCpService cpService;

@Override
public WxCpSpaceCreateData spaceCreate(@NonNull WxCpSpaceCreateRequest request) throws WxErrorException {
String apiUrl = this.cpService.getWxCpConfigStorage().getApiUrl(SPACE_CREATE);
String responseContent = this.cpService.post(apiUrl, request.toJson());
return WxCpSpaceCreateData.fromJson(responseContent);
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package me.chanjar.weixin.cp.bean.oa.wedrive;

import com.google.gson.annotations.SerializedName;
import lombok.Data;
import me.chanjar.weixin.cp.bean.WxCpBaseResp;
import me.chanjar.weixin.cp.util.json.WxCpGsonBuilder;

import java.io.Serializable;

/**
* 新建空间信息.
*
* @author Wang_Wong
*/
@Data
public class WxCpSpaceCreateData extends WxCpBaseResp implements Serializable {
private static final long serialVersionUID = -5028321625142879581L;

@SerializedName("spaceid")
private String spaceId;

public static WxCpSpaceCreateData fromJson(String json) {
return WxCpGsonBuilder.create().fromJson(json, WxCpSpaceCreateData.class);
}

public String toJson() {
return WxCpGsonBuilder.create().toJson(this);
}

}
Original file line number Diff line number Diff line change
@@ -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 WxCpSpaceCreateRequest implements Serializable {
private static final long serialVersionUID = -4960239393895754138L;

@SerializedName("userid")
private String userId;

@SerializedName("space_name")
private String spaceName;

@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 WxCpSpaceCreateRequest fromJson(String json) {
return WxCpGsonBuilder.create().fromJson(json, WxCpSpaceCreateRequest.class);
}

public String toJson() {
return WxCpGsonBuilder.create().toJson(this);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,12 @@ interface Oa {
String SCHEDULE_DEL = "/cgi-bin/oa/schedule/del";
String SCHEDULE_LIST = "/cgi-bin/oa/schedule/get_by_calendar";

/**
* 微盘
* https://developer.work.weixin.qq.com/document/path/93654
*/
String SPACE_CREATE = "/cgi-bin/wedrive/space_create";

/**
* 审批流程引擎
* https://developer.work.weixin.qq.com/document/path/90269
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
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.oa.wedrive.WxCpSpaceCreateData;
import me.chanjar.weixin.cp.bean.oa.wedrive.WxCpSpaceCreateRequest;
import me.chanjar.weixin.cp.config.WxCpConfigStorage;
import me.chanjar.weixin.cp.demo.WxCpDemoInMemoryConfigStorage;
import org.testng.annotations.Test;

import java.io.InputStream;

/**
* 微盘测试类.
* 官方文档:https://developer.work.weixin.qq.com/document/path/93654
*
* @author Wang_Wong
*/
@Slf4j
public class WxCpOaWeDriveServiceTest {

private static WxCpConfigStorage wxCpConfigStorage;
private static WxCpService cpService;

@Test
public void test() throws WxErrorException {

InputStream inputStream = ClassLoader.getSystemResourceAsStream("test-config.xml");
WxCpDemoInMemoryConfigStorage config = WxCpDemoInMemoryConfigStorage.fromXml(inputStream);

wxCpConfigStorage = config;
cpService = new WxCpServiceImpl();
cpService.setWxCpConfigStorage(config);

String createSpace = "{\"userid\":\"USERID\",\"space_name\":\"SPACE_NAME\",\"auth_info\":[{\"type\":1,\"userid\":\"USERID\",\"auth\":2},{\"type\":2,\"departmentid\":2,\"auth\":1}]}";
WxCpSpaceCreateRequest wxCpSpaceCreateRequest = WxCpSpaceCreateRequest.fromJson(createSpace);
log.info(wxCpSpaceCreateRequest.toJson());

/**
* 新建空间
*/
WxCpSpaceCreateRequest request = new WxCpSpaceCreateRequest();
request.setUserId("WangKai");
request.setSpaceName("测试云盘2");

WxCpSpaceCreateData spaceCreateData = cpService.getOaWeDriveService().spaceCreate(request);
log.info("空间id为:{}", spaceCreateData.getSpaceId());
log.info(spaceCreateData.toJson());

}

}

0 comments on commit 343fa11

Please sign in to comment.