Skip to content

Commit

Permalink
🆕 #2639【企业微信】增加微盘空间权限管理的接口
Browse files Browse the repository at this point in the history
  • Loading branch information
0katekate0 committed May 12, 2022
1 parent 858a3b9 commit 6177ca0
Show file tree
Hide file tree
Showing 6 changed files with 149 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -94,4 +94,31 @@ public interface WxCpOaWeDriveService {
*/
WxCpBaseResp spaceAclDel(@NonNull WxCpSpaceAclDelRequest request) throws WxErrorException;

/**
* 权限管理
* 该接口用于修改空间权限,需要传入userid,修改权限范围继承传入用户的权限范围。
* <p>
* 请求方式:POST(HTTPS)
* 请求地址: https://qyapi.weixin.qq.com/cgi-bin/wedrive/space_setting?access_token=ACCESS_TOKEN
*
* @param request 权限管理请求参数
* @return
* @throws WxErrorException
*/
WxCpBaseResp spaceSetting(@NonNull WxCpSpaceSettingRequest request) throws WxErrorException;

/**
* 获取邀请链接
* 该接口用于获取空间邀请分享链接。
* <p>
* 请求方式:POST(HTTPS)
* 请求地址: https://qyapi.weixin.qq.com/cgi-bin/wedrive/space_share?access_token=ACCESS_TOKEN
*
* @param userId
* @param spaceId
* @return
* @throws WxErrorException
*/
WxCpSpaceShare spaceShare(@NonNull String userId, @NonNull String spaceId) throws WxErrorException;

}
Original file line number Diff line number Diff line change
Expand Up @@ -71,4 +71,21 @@ public WxCpBaseResp spaceAclDel(@NonNull WxCpSpaceAclDelRequest request) throws
return WxCpBaseResp.fromJson(responseContent);
}

@Override
public WxCpBaseResp spaceSetting(@NonNull WxCpSpaceSettingRequest request) throws WxErrorException {
String apiUrl = this.cpService.getWxCpConfigStorage().getApiUrl(SPACE_SETTING);
String responseContent = this.cpService.post(apiUrl, request.toJson());
return WxCpBaseResp.fromJson(responseContent);
}

@Override
public WxCpSpaceShare spaceShare(@NonNull String userId, @NonNull String spaceId) throws WxErrorException {
String apiUrl = this.cpService.getWxCpConfigStorage().getApiUrl(SPACE_SHARE);
JsonObject jsonObject = new JsonObject();
jsonObject.addProperty("userid", userId);
jsonObject.addProperty("spaceid", spaceId);
String responseContent = this.cpService.post(apiUrl, jsonObject.toString());
return WxCpSpaceShare.fromJson(responseContent);
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
package me.chanjar.weixin.cp.bean.oa.wedrive;

import com.google.gson.annotations.SerializedName;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.experimental.Accessors;
import me.chanjar.weixin.cp.util.json.WxCpGsonBuilder;

import java.io.Serializable;

/**
* 权限管理请求.
*/
@Data
@Builder
@NoArgsConstructor
@AllArgsConstructor
@Accessors(chain = true)
public class WxCpSpaceSettingRequest implements Serializable {
private static final long serialVersionUID = -4960239393895754138L;

@SerializedName("userid")
private String userId;

@SerializedName("spaceid")
private String spaceId;

@SerializedName("enable_watermark")
private Boolean enableWatermark;

@SerializedName("add_member_only_admin")
private Boolean addMemberOnlyAdmin;

@SerializedName("enable_share_url")
private Boolean enableShareUrl;

@SerializedName("share_url_no_approve")
private Boolean shareUrlNoApprove;

@SerializedName("share_url_no_approve_default_auth")
private Integer shareUrlNoApproveDefaultAuth;

public static WxCpSpaceSettingRequest fromJson(String json) {
return WxCpGsonBuilder.create().fromJson(json, WxCpSpaceSettingRequest.class);
}

public String toJson() {
return WxCpGsonBuilder.create().toJson(this);
}

}
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 WxCpSpaceShare extends WxCpBaseResp implements Serializable {
private static final long serialVersionUID = -5028321625142879581L;

@SerializedName("space_share_url")
private String spaceShareUrl;

public static WxCpSpaceShare fromJson(String json) {
return WxCpGsonBuilder.create().fromJson(json, WxCpSpaceShare.class);
}

public String toJson() {
return WxCpGsonBuilder.create().toJson(this);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,8 @@ interface Oa {
String SPACE_INFO = "/cgi-bin/wedrive/space_info";
String SPACE_ACL_ADD = "/cgi-bin/wedrive/space_acl_add";
String SPACE_ACL_DEL = "/cgi-bin/wedrive/space_acl_del";
String SPACE_SETTING = "/cgi-bin/wedrive/space_setting";
String SPACE_SHARE = "/cgi-bin/wedrive/space_share";

/**
* 审批流程引擎
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,26 @@ public void test() throws WxErrorException {
String uId = "WangKai";
String spId = "s.ww45d3e188865aca30.652091685u4h";

/**
* 权限管理
*/
WxCpSpaceSettingRequest spaceSettingRequest = new WxCpSpaceSettingRequest();
spaceSettingRequest.setUserId(uId);
spaceSettingRequest.setSpaceId(spId);
// spaceSettingRequest.setEnableWatermark(false);
spaceSettingRequest.setAddMemberOnlyAdmin(true);
spaceSettingRequest.setEnableShareUrl(false);
spaceSettingRequest.setShareUrlNoApprove(true);
spaceSettingRequest.setShareUrlNoApproveDefaultAuth(2);

WxCpBaseResp spaceSetting = cpService.getOaWeDriveService().spaceSetting(spaceSettingRequest);
log.info("权限管理信息为:{}", spaceSetting.toJson());

/**
* 获取邀请链接
*/
WxCpSpaceShare spaceShare = cpService.getOaWeDriveService().spaceShare(uId, spId);
log.info("获取邀请链接信息为:{}", spaceShare.toJson());

/**
* 获取空间信息
Expand Down

0 comments on commit 6177ca0

Please sign in to comment.