Skip to content

Commit 6177ca0

Browse files
authored
🆕 #2639【企业微信】增加微盘空间权限管理的接口
1 parent 858a3b9 commit 6177ca0

File tree

6 files changed

+149
-0
lines changed

6 files changed

+149
-0
lines changed

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

+27
Original file line numberDiff line numberDiff line change
@@ -94,4 +94,31 @@ public interface WxCpOaWeDriveService {
9494
*/
9595
WxCpBaseResp spaceAclDel(@NonNull WxCpSpaceAclDelRequest request) throws WxErrorException;
9696

97+
/**
98+
* 权限管理
99+
* 该接口用于修改空间权限,需要传入userid,修改权限范围继承传入用户的权限范围。
100+
* <p>
101+
* 请求方式:POST(HTTPS)
102+
* 请求地址: https://qyapi.weixin.qq.com/cgi-bin/wedrive/space_setting?access_token=ACCESS_TOKEN
103+
*
104+
* @param request 权限管理请求参数
105+
* @return
106+
* @throws WxErrorException
107+
*/
108+
WxCpBaseResp spaceSetting(@NonNull WxCpSpaceSettingRequest request) throws WxErrorException;
109+
110+
/**
111+
* 获取邀请链接
112+
* 该接口用于获取空间邀请分享链接。
113+
* <p>
114+
* 请求方式:POST(HTTPS)
115+
* 请求地址: https://qyapi.weixin.qq.com/cgi-bin/wedrive/space_share?access_token=ACCESS_TOKEN
116+
*
117+
* @param userId
118+
* @param spaceId
119+
* @return
120+
* @throws WxErrorException
121+
*/
122+
WxCpSpaceShare spaceShare(@NonNull String userId, @NonNull String spaceId) throws WxErrorException;
123+
97124
}

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

+17
Original file line numberDiff line numberDiff line change
@@ -71,4 +71,21 @@ public WxCpBaseResp spaceAclDel(@NonNull WxCpSpaceAclDelRequest request) throws
7171
return WxCpBaseResp.fromJson(responseContent);
7272
}
7373

74+
@Override
75+
public WxCpBaseResp spaceSetting(@NonNull WxCpSpaceSettingRequest request) throws WxErrorException {
76+
String apiUrl = this.cpService.getWxCpConfigStorage().getApiUrl(SPACE_SETTING);
77+
String responseContent = this.cpService.post(apiUrl, request.toJson());
78+
return WxCpBaseResp.fromJson(responseContent);
79+
}
80+
81+
@Override
82+
public WxCpSpaceShare spaceShare(@NonNull String userId, @NonNull String spaceId) throws WxErrorException {
83+
String apiUrl = this.cpService.getWxCpConfigStorage().getApiUrl(SPACE_SHARE);
84+
JsonObject jsonObject = new JsonObject();
85+
jsonObject.addProperty("userid", userId);
86+
jsonObject.addProperty("spaceid", spaceId);
87+
String responseContent = this.cpService.post(apiUrl, jsonObject.toString());
88+
return WxCpSpaceShare.fromJson(responseContent);
89+
}
90+
7491
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
package me.chanjar.weixin.cp.bean.oa.wedrive;
2+
3+
import com.google.gson.annotations.SerializedName;
4+
import lombok.AllArgsConstructor;
5+
import lombok.Builder;
6+
import lombok.Data;
7+
import lombok.NoArgsConstructor;
8+
import lombok.experimental.Accessors;
9+
import me.chanjar.weixin.cp.util.json.WxCpGsonBuilder;
10+
11+
import java.io.Serializable;
12+
13+
/**
14+
* 权限管理请求.
15+
*/
16+
@Data
17+
@Builder
18+
@NoArgsConstructor
19+
@AllArgsConstructor
20+
@Accessors(chain = true)
21+
public class WxCpSpaceSettingRequest implements Serializable {
22+
private static final long serialVersionUID = -4960239393895754138L;
23+
24+
@SerializedName("userid")
25+
private String userId;
26+
27+
@SerializedName("spaceid")
28+
private String spaceId;
29+
30+
@SerializedName("enable_watermark")
31+
private Boolean enableWatermark;
32+
33+
@SerializedName("add_member_only_admin")
34+
private Boolean addMemberOnlyAdmin;
35+
36+
@SerializedName("enable_share_url")
37+
private Boolean enableShareUrl;
38+
39+
@SerializedName("share_url_no_approve")
40+
private Boolean shareUrlNoApprove;
41+
42+
@SerializedName("share_url_no_approve_default_auth")
43+
private Integer shareUrlNoApproveDefaultAuth;
44+
45+
public static WxCpSpaceSettingRequest fromJson(String json) {
46+
return WxCpGsonBuilder.create().fromJson(json, WxCpSpaceSettingRequest.class);
47+
}
48+
49+
public String toJson() {
50+
return WxCpGsonBuilder.create().toJson(this);
51+
}
52+
53+
}
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 WxCpSpaceShare extends WxCpBaseResp implements Serializable {
17+
private static final long serialVersionUID = -5028321625142879581L;
18+
19+
@SerializedName("space_share_url")
20+
private String spaceShareUrl;
21+
22+
public static WxCpSpaceShare fromJson(String json) {
23+
return WxCpGsonBuilder.create().fromJson(json, WxCpSpaceShare.class);
24+
}
25+
26+
public String toJson() {
27+
return WxCpGsonBuilder.create().toJson(this);
28+
}
29+
30+
}

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

+2
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,8 @@ interface Oa {
151151
String SPACE_INFO = "/cgi-bin/wedrive/space_info";
152152
String SPACE_ACL_ADD = "/cgi-bin/wedrive/space_acl_add";
153153
String SPACE_ACL_DEL = "/cgi-bin/wedrive/space_acl_del";
154+
String SPACE_SETTING = "/cgi-bin/wedrive/space_setting";
155+
String SPACE_SHARE = "/cgi-bin/wedrive/space_share";
154156

155157
/**
156158
* 审批流程引擎

weixin-java-cp/src/test/java/me/chanjar/weixin/cp/api/WxCpOaWeDriveServiceTest.java

+20
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,26 @@ public void test() throws WxErrorException {
4141
String uId = "WangKai";
4242
String spId = "s.ww45d3e188865aca30.652091685u4h";
4343

44+
/**
45+
* 权限管理
46+
*/
47+
WxCpSpaceSettingRequest spaceSettingRequest = new WxCpSpaceSettingRequest();
48+
spaceSettingRequest.setUserId(uId);
49+
spaceSettingRequest.setSpaceId(spId);
50+
// spaceSettingRequest.setEnableWatermark(false);
51+
spaceSettingRequest.setAddMemberOnlyAdmin(true);
52+
spaceSettingRequest.setEnableShareUrl(false);
53+
spaceSettingRequest.setShareUrlNoApprove(true);
54+
spaceSettingRequest.setShareUrlNoApproveDefaultAuth(2);
55+
56+
WxCpBaseResp spaceSetting = cpService.getOaWeDriveService().spaceSetting(spaceSettingRequest);
57+
log.info("权限管理信息为:{}", spaceSetting.toJson());
58+
59+
/**
60+
* 获取邀请链接
61+
*/
62+
WxCpSpaceShare spaceShare = cpService.getOaWeDriveService().spaceShare(uId, spId);
63+
log.info("获取邀请链接信息为:{}", spaceShare.toJson());
4464

4565
/**
4666
* 获取空间信息

0 commit comments

Comments
 (0)