|
| 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