Skip to content

Commit 343fa11

Browse files
authored
🆕 #2614 【企业微信】新增微盘空间管理的相关接口
1 parent 8831056 commit 343fa11

File tree

8 files changed

+231
-0
lines changed

8 files changed

+231
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
package me.chanjar.weixin.cp.api;
2+
3+
import lombok.NonNull;
4+
import me.chanjar.weixin.common.error.WxErrorException;
5+
import me.chanjar.weixin.cp.bean.oa.wedrive.WxCpSpaceCreateData;
6+
import me.chanjar.weixin.cp.bean.oa.wedrive.WxCpSpaceCreateRequest;
7+
8+
/**
9+
* 企业微信微盘相关接口.
10+
* https://developer.work.weixin.qq.com/document/path/93654
11+
*
12+
* @author <a href="https://github.com/0katekate0">Wang_Wong</a>
13+
* @date 2022-04-22
14+
*/
15+
public interface WxCpOaWeDriveService {
16+
17+
/**
18+
* 新建空间
19+
* 该接口用于在微盘内新建空间,可以指定人创建空间。
20+
* <p>
21+
* 请求方式:POST(HTTPS)
22+
* 请求地址: https://qyapi.weixin.qq.com/cgi-bin/wedrive/space_create?access_token=ACCESS_TOKEN
23+
*
24+
* @param request 新建空间对应请求参数
25+
* @return spaceid(空间id)
26+
*
27+
* @throws WxErrorException
28+
*/
29+
WxCpSpaceCreateData spaceCreate(@NonNull WxCpSpaceCreateRequest request) throws WxErrorException;
30+
31+
}

weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/WxCpService.java

+7
Original file line numberDiff line numberDiff line change
@@ -414,6 +414,13 @@ public interface WxCpService extends WxService {
414414
*/
415415
WxCpOaAgentService getOaAgentService();
416416

417+
/**
418+
* 获取OA效率工具 微盘的服务类对象
419+
*
420+
* @return
421+
*/
422+
WxCpOaWeDriveService getOaWeDriveService();
423+
417424
/**
418425
* 获取会话存档相关接口的服务类对象
419426
*

weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/impl/BaseWxCpServiceImpl.java

+6
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ public abstract class BaseWxCpServiceImpl<H, P> implements WxCpService, RequestH
5151
private WxCpOaService oaService = new WxCpOaServiceImpl(this);
5252
private WxCpLivingService livingService = new WxCpLivingServiceImpl(this);
5353
private WxCpOaAgentService oaAgentService = new WxCpOaAgentServiceImpl(this);
54+
private WxCpOaWeDriveService oaWeDriveService = new WxCpOaWeDriveServiceImpl(this);
5455
private WxCpMsgAuditService msgAuditService = new WxCpMsgAuditServiceImpl(this);
5556
private WxCpTaskCardService taskCardService = new WxCpTaskCardServiceImpl(this);
5657
private WxCpExternalContactService externalContactService = new WxCpExternalContactServiceImpl(this);
@@ -502,6 +503,11 @@ public WxCpOaAgentService getOaAgentService() {
502503
return oaAgentService;
503504
}
504505

506+
@Override
507+
public WxCpOaWeDriveService getOaWeDriveService() {
508+
return oaWeDriveService;
509+
}
510+
505511
@Override
506512
public WxCpMsgAuditService getMsgAuditService() {
507513
return msgAuditService;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
package me.chanjar.weixin.cp.api.impl;
2+
3+
import lombok.NonNull;
4+
import lombok.RequiredArgsConstructor;
5+
import lombok.extern.slf4j.Slf4j;
6+
import me.chanjar.weixin.common.error.WxErrorException;
7+
import me.chanjar.weixin.cp.api.WxCpOaWeDriveService;
8+
import me.chanjar.weixin.cp.api.WxCpService;
9+
import me.chanjar.weixin.cp.bean.oa.wedrive.WxCpSpaceCreateData;
10+
import me.chanjar.weixin.cp.bean.oa.wedrive.WxCpSpaceCreateRequest;
11+
12+
import static me.chanjar.weixin.cp.constant.WxCpApiPathConsts.Oa.SPACE_CREATE;
13+
14+
/**
15+
* 企业微信微盘接口实现类.
16+
*
17+
* @author Wang_Wong
18+
* @date 2022-04-22
19+
*/
20+
@Slf4j
21+
@RequiredArgsConstructor
22+
public class WxCpOaWeDriveServiceImpl implements WxCpOaWeDriveService {
23+
private final WxCpService cpService;
24+
25+
@Override
26+
public WxCpSpaceCreateData spaceCreate(@NonNull WxCpSpaceCreateRequest request) throws WxErrorException {
27+
String apiUrl = this.cpService.getWxCpConfigStorage().getApiUrl(SPACE_CREATE);
28+
String responseContent = this.cpService.post(apiUrl, request.toJson());
29+
return WxCpSpaceCreateData.fromJson(responseContent);
30+
}
31+
32+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
package me.chanjar.weixin.cp.bean.oa.wedrive;
2+
3+
import com.google.gson.annotations.SerializedName;
4+
import lombok.Data;
5+
import me.chanjar.weixin.cp.bean.WxCpBaseResp;
6+
import me.chanjar.weixin.cp.util.json.WxCpGsonBuilder;
7+
8+
import java.io.Serializable;
9+
10+
/**
11+
* 新建空间信息.
12+
*
13+
* @author Wang_Wong
14+
*/
15+
@Data
16+
public class WxCpSpaceCreateData extends WxCpBaseResp implements Serializable {
17+
private static final long serialVersionUID = -5028321625142879581L;
18+
19+
@SerializedName("spaceid")
20+
private String spaceId;
21+
22+
public static WxCpSpaceCreateData fromJson(String json) {
23+
return WxCpGsonBuilder.create().fromJson(json, WxCpSpaceCreateData.class);
24+
}
25+
26+
public String toJson() {
27+
return WxCpGsonBuilder.create().toJson(this);
28+
}
29+
30+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
package me.chanjar.weixin.cp.bean.oa.wedrive;
2+
3+
import com.google.gson.annotations.SerializedName;
4+
import lombok.*;
5+
import lombok.experimental.Accessors;
6+
import me.chanjar.weixin.cp.util.json.WxCpGsonBuilder;
7+
8+
import java.io.Serializable;
9+
import java.util.List;
10+
11+
/**
12+
* 新建空间请求.
13+
*/
14+
@Data
15+
@Builder
16+
@NoArgsConstructor
17+
@AllArgsConstructor
18+
@Accessors(chain = true)
19+
public class WxCpSpaceCreateRequest implements Serializable {
20+
private static final long serialVersionUID = -4960239393895754138L;
21+
22+
@SerializedName("userid")
23+
private String userId;
24+
25+
@SerializedName("space_name")
26+
private String spaceName;
27+
28+
@SerializedName("auth_info")
29+
private List<AuthInfo> authInfo;
30+
31+
@Getter
32+
@Setter
33+
public static class AuthInfo implements Serializable {
34+
private static final long serialVersionUID = -4960239393895754598L;
35+
36+
@SerializedName("type")
37+
private Integer type;
38+
39+
@SerializedName("departmentid")
40+
private Integer departmentId;
41+
42+
@SerializedName("auth")
43+
private Integer auth;
44+
45+
@SerializedName("userid")
46+
private String userId;
47+
48+
public static AuthInfo fromJson(String json) {
49+
return WxCpGsonBuilder.create().fromJson(json, AuthInfo.class);
50+
}
51+
52+
public String toJson() {
53+
return WxCpGsonBuilder.create().toJson(this);
54+
}
55+
56+
}
57+
58+
public static WxCpSpaceCreateRequest fromJson(String json) {
59+
return WxCpGsonBuilder.create().fromJson(json, WxCpSpaceCreateRequest.class);
60+
}
61+
62+
public String toJson() {
63+
return WxCpGsonBuilder.create().toJson(this);
64+
}
65+
66+
}

weixin-java-cp/src/main/java/me/chanjar/weixin/cp/constant/WxCpApiPathConsts.java

+6
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,12 @@ interface Oa {
140140
String SCHEDULE_DEL = "/cgi-bin/oa/schedule/del";
141141
String SCHEDULE_LIST = "/cgi-bin/oa/schedule/get_by_calendar";
142142

143+
/**
144+
* 微盘
145+
* https://developer.work.weixin.qq.com/document/path/93654
146+
*/
147+
String SPACE_CREATE = "/cgi-bin/wedrive/space_create";
148+
143149
/**
144150
* 审批流程引擎
145151
* https://developer.work.weixin.qq.com/document/path/90269
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
package me.chanjar.weixin.cp.api;
2+
3+
import lombok.extern.slf4j.Slf4j;
4+
import me.chanjar.weixin.common.error.WxErrorException;
5+
import me.chanjar.weixin.cp.api.impl.WxCpServiceImpl;
6+
import me.chanjar.weixin.cp.bean.oa.wedrive.WxCpSpaceCreateData;
7+
import me.chanjar.weixin.cp.bean.oa.wedrive.WxCpSpaceCreateRequest;
8+
import me.chanjar.weixin.cp.config.WxCpConfigStorage;
9+
import me.chanjar.weixin.cp.demo.WxCpDemoInMemoryConfigStorage;
10+
import org.testng.annotations.Test;
11+
12+
import java.io.InputStream;
13+
14+
/**
15+
* 微盘测试类.
16+
* 官方文档:https://developer.work.weixin.qq.com/document/path/93654
17+
*
18+
* @author Wang_Wong
19+
*/
20+
@Slf4j
21+
public class WxCpOaWeDriveServiceTest {
22+
23+
private static WxCpConfigStorage wxCpConfigStorage;
24+
private static WxCpService cpService;
25+
26+
@Test
27+
public void test() throws WxErrorException {
28+
29+
InputStream inputStream = ClassLoader.getSystemResourceAsStream("test-config.xml");
30+
WxCpDemoInMemoryConfigStorage config = WxCpDemoInMemoryConfigStorage.fromXml(inputStream);
31+
32+
wxCpConfigStorage = config;
33+
cpService = new WxCpServiceImpl();
34+
cpService.setWxCpConfigStorage(config);
35+
36+
String createSpace = "{\"userid\":\"USERID\",\"space_name\":\"SPACE_NAME\",\"auth_info\":[{\"type\":1,\"userid\":\"USERID\",\"auth\":2},{\"type\":2,\"departmentid\":2,\"auth\":1}]}";
37+
WxCpSpaceCreateRequest wxCpSpaceCreateRequest = WxCpSpaceCreateRequest.fromJson(createSpace);
38+
log.info(wxCpSpaceCreateRequest.toJson());
39+
40+
/**
41+
* 新建空间
42+
*/
43+
WxCpSpaceCreateRequest request = new WxCpSpaceCreateRequest();
44+
request.setUserId("WangKai");
45+
request.setSpaceName("测试云盘2");
46+
47+
WxCpSpaceCreateData spaceCreateData = cpService.getOaWeDriveService().spaceCreate(request);
48+
log.info("空间id为:{}", spaceCreateData.getSpaceId());
49+
log.info(spaceCreateData.toJson());
50+
51+
}
52+
53+
}

0 commit comments

Comments
 (0)