-
-
Notifications
You must be signed in to change notification settings - Fork 8.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
8831056
commit 343fa11
Showing
8 changed files
with
231 additions
and
0 deletions.
There are no files selected for viewing
31 changes: 31 additions & 0 deletions
31
weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/WxCpOaWeDriveService.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
32 changes: 32 additions & 0 deletions
32
weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/impl/WxCpOaWeDriveServiceImpl.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
|
||
} |
30 changes: 30 additions & 0 deletions
30
weixin-java-cp/src/main/java/me/chanjar/weixin/cp/bean/oa/wedrive/WxCpSpaceCreateData.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
|
||
} |
66 changes: 66 additions & 0 deletions
66
...in-java-cp/src/main/java/me/chanjar/weixin/cp/bean/oa/wedrive/WxCpSpaceCreateRequest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
53 changes: 53 additions & 0 deletions
53
weixin-java-cp/src/test/java/me/chanjar/weixin/cp/api/WxCpOaWeDriveServiceTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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()); | ||
|
||
} | ||
|
||
} |