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 new file mode 100644 index 0000000000..39b6d4d5f5 --- /dev/null +++ b/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/WxCpOaWeDriveService.java @@ -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 Wang_Wong + * @date 2022-04-22 + */ +public interface WxCpOaWeDriveService { + + /** + * 新建空间 + * 该接口用于在微盘内新建空间,可以指定人创建空间。 + *

+ * 请求方式: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; + +} diff --git a/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/WxCpService.java b/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/WxCpService.java index 851e9c192f..769ef0d2e7 100644 --- a/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/WxCpService.java +++ b/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/WxCpService.java @@ -414,6 +414,13 @@ public interface WxCpService extends WxService { */ WxCpOaAgentService getOaAgentService(); + /** + * 获取OA效率工具 微盘的服务类对象 + * + * @return + */ + WxCpOaWeDriveService getOaWeDriveService(); + /** * 获取会话存档相关接口的服务类对象 * diff --git a/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/impl/BaseWxCpServiceImpl.java b/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/impl/BaseWxCpServiceImpl.java index ece8bd9add..6de02c3e25 100644 --- a/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/impl/BaseWxCpServiceImpl.java +++ b/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/impl/BaseWxCpServiceImpl.java @@ -51,6 +51,7 @@ public abstract class BaseWxCpServiceImpl 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); @@ -502,6 +503,11 @@ public WxCpOaAgentService getOaAgentService() { return oaAgentService; } + @Override + public WxCpOaWeDriveService getOaWeDriveService() { + return oaWeDriveService; + } + @Override public WxCpMsgAuditService getMsgAuditService() { return msgAuditService; 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 new file mode 100644 index 0000000000..5f58cbb452 --- /dev/null +++ b/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/impl/WxCpOaWeDriveServiceImpl.java @@ -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); + } + +} diff --git a/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/bean/oa/wedrive/WxCpSpaceCreateData.java b/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/bean/oa/wedrive/WxCpSpaceCreateData.java new file mode 100644 index 0000000000..1217452043 --- /dev/null +++ b/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/bean/oa/wedrive/WxCpSpaceCreateData.java @@ -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); + } + +} diff --git a/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/bean/oa/wedrive/WxCpSpaceCreateRequest.java b/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/bean/oa/wedrive/WxCpSpaceCreateRequest.java new file mode 100644 index 0000000000..3b9319e43d --- /dev/null +++ b/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/bean/oa/wedrive/WxCpSpaceCreateRequest.java @@ -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; + + @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); + } + +} 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 c3b4e03ecb..99b64a6cbe 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 @@ -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 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 new file mode 100644 index 0000000000..eb7b682948 --- /dev/null +++ b/weixin-java-cp/src/test/java/me/chanjar/weixin/cp/api/WxCpOaWeDriveServiceTest.java @@ -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()); + + } + +}