Browse Source

:art: #3437 【企业微信】 微盘文件管理相关接口移除过期的userid参数

Binary Wang 5 months ago
parent
commit
a4e3af0eb6

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

@@ -9,7 +9,7 @@ import java.util.List;
 
 /**
  * 企业微信微盘相关接口.
- * https://developer.work.weixin.qq.com/document/path/93654
+ * <a href="https://developer.work.weixin.qq.com/document/path/93654">...</a>
  *
  * @author <a href="https://github.com/0katekate0">Wang_Wong</a> created on  2022-04-22
  */
@@ -20,7 +20,7 @@ public interface WxCpOaWeDriveService {
    * 该接口用于在微盘内新建空间,可以指定人创建空间。
    * <p>
    * 请求方式:POST(HTTPS)
-   * 请求地址: https://qyapi.weixin.qq.com/cgi-bin/wedrive/space_create?access_token=ACCESS_TOKEN
+   * 请求地址: <a href="https://qyapi.weixin.qq.com/cgi-bin/wedrive/space_create?access_token=ACCESS_TOKEN">...</a>
    *
    * @param request 新建空间对应请求参数
    * @return spaceid (空间id)
@@ -33,7 +33,7 @@ public interface WxCpOaWeDriveService {
    * 该接口用于重命名已有空间,接收userid参数,以空间管理员身份来重命名。
    * <p>
    * 请求方式:POST(HTTPS)
-   * 请求地址: https://qyapi.weixin.qq.com/cgi-bin/wedrive/space_rename?access_token=ACCESS_TOKEN
+   * 请求地址: <a href="https://qyapi.weixin.qq.com/cgi-bin/wedrive/space_rename?access_token=ACCESS_TOKEN">...</a>
    *
    * @param request 重命名空间的请求参数
    * @return wx cp base resp
@@ -46,7 +46,7 @@ public interface WxCpOaWeDriveService {
    * 该接口用于解散已有空间,需要以空间管理员身份来解散。
    * <p>
    * 请求方式:POST(HTTPS)
-   * 请求地址: https://qyapi.weixin.qq.com/cgi-bin/wedrive/space_dismiss?access_token=ACCESS_TOKEN
+   * 请求地址: <a href="https://qyapi.weixin.qq.com/cgi-bin/wedrive/space_dismiss?access_token=ACCESS_TOKEN">...</a>
    *
    * @param userId  the user id
    * @param spaceId the space id
@@ -60,7 +60,7 @@ public interface WxCpOaWeDriveService {
    * 该接口用于获取空间成员列表、信息、权限等信息。
    * <p>
    * 请求方式:POST(HTTPS)
-   * 请求地址: https://qyapi.weixin.qq.com/cgi-bin/wedrive/space_info?access_token=ACCESS_TOKEN
+   * 请求地址: <a href="https://qyapi.weixin.qq.com/cgi-bin/wedrive/space_info?access_token=ACCESS_TOKEN">...</a>
    *
    * @param userId  the user id
    * @param spaceId the space id
@@ -74,7 +74,7 @@ public interface WxCpOaWeDriveService {
    * 该接口用于对指定空间添加成员/部门,可一次性添加多个。
    * <p>
    * 请求方式:POST(HTTPS)
-   * 请求地址: https://qyapi.weixin.qq.com/cgi-bin/wedrive/space_acl_add?access_token=ACCESS_TOKEN
+   * 请求地址: <a href="https://qyapi.weixin.qq.com/cgi-bin/wedrive/space_acl_add?access_token=ACCESS_TOKEN">...</a>
    *
    * @param request 添加成员/部门请求参数
    * @return wx cp base resp
@@ -87,7 +87,7 @@ public interface WxCpOaWeDriveService {
    * 该接口用于对指定空间移除成员/部门,操作者需要有移除权限。
    * <p>
    * 请求方式:POST(HTTPS)
-   * 请求地址: https://qyapi.weixin.qq.com/cgi-bin/wedrive/space_acl_del?access_token=ACCESS_TOKEN
+   * 请求地址: <a href="https://qyapi.weixin.qq.com/cgi-bin/wedrive/space_acl_del?access_token=ACCESS_TOKEN">...</a>
    *
    * @param request 移除成员/部门请求参数
    * @return wx cp base resp
@@ -100,7 +100,7 @@ public interface WxCpOaWeDriveService {
    * 该接口用于修改空间权限,需要传入userid,修改权限范围继承传入用户的权限范围。
    * <p>
    * 请求方式:POST(HTTPS)
-   * 请求地址: https://qyapi.weixin.qq.com/cgi-bin/wedrive/space_setting?access_token=ACCESS_TOKEN
+   * 请求地址: <a href="https://qyapi.weixin.qq.com/cgi-bin/wedrive/space_setting?access_token=ACCESS_TOKEN">...</a>
    *
    * @param request 权限管理请求参数
    * @return wx cp base resp
@@ -113,7 +113,7 @@ public interface WxCpOaWeDriveService {
    * 该接口用于获取空间邀请分享链接。
    * <p>
    * 请求方式:POST(HTTPS)
-   * 请求地址: https://qyapi.weixin.qq.com/cgi-bin/wedrive/space_share?access_token=ACCESS_TOKEN
+   * 请求地址: <a href="https://qyapi.weixin.qq.com/cgi-bin/wedrive/space_share?access_token=ACCESS_TOKEN">...</a>
    *
    * @param userId  the user id
    * @param spaceId the space id
@@ -127,7 +127,7 @@ public interface WxCpOaWeDriveService {
    * 该接口用于获取指定地址下的文件列表。
    * <p>
    * 请求方式:POST(HTTPS)
-   * 请求地址: https://qyapi.weixin.qq.com/cgi-bin/wedrive/file_list?access_token=ACCESS_TOKEN
+   * 请求地址: <a href="https://qyapi.weixin.qq.com/cgi-bin/wedrive/file_list?access_token=ACCESS_TOKEN">...</a>
    *
    * @param request 获取文件列表请求参数
    * @return wx cp file list
@@ -140,7 +140,7 @@ public interface WxCpOaWeDriveService {
    * 该接口用于向微盘中的指定位置上传文件。
    * <p>
    * 请求方式:POST(HTTPS)
-   * 请求地址: https://qyapi.weixin.qq.com/cgi-bin/wedrive/file_upload?access_token=ACCESS_TOKEN
+   * 请求地址: <a href="https://qyapi.weixin.qq.com/cgi-bin/wedrive/file_upload?access_token=ACCESS_TOKEN">...</a>
    *
    * @param request 上传文件请求参数
    * @return wx cp file upload
@@ -153,54 +153,58 @@ public interface WxCpOaWeDriveService {
    * 该接口用于下载文件,请求的userid需有下载权限。
    * <p>
    * 请求方式:POST(HTTPS)
-   * 请求地址: https://qyapi.weixin.qq.com/cgi-bin/wedrive/file_download?access_token=ACCESS_TOKEN
+   * 请求地址: <a href="https://qyapi.weixin.qq.com/cgi-bin/wedrive/file_download?access_token=ACCESS_TOKEN">...</a>
    *
-   * @param userId the user id
-   * @param fileId the file id
-   * @return wx cp file download
+   * @param fileId 文件fileid(只支持下载普通文件,不支持下载文件夹或微文档)
+   * @param selectedTicket 微盘和文件选择器jsapi返回的selectedTicket。若填此参数,则不需要填fileid。
+   * @return {
+   *     "errcode": 0,
+   *     "errmsg": "ok",
+   *     "download_url": "DOWNLOAD_URL",
+   *     "cookie_name": "COOKIE_NAME",
+   *     "cookie_value": "COOKIE_VALUE"
+   * }
    * @throws WxErrorException the wx error exception
    */
-  WxCpFileDownload fileDownload(@NonNull String userId, @NonNull String fileId) throws WxErrorException;
+  WxCpFileDownload fileDownload( String fileId, String selectedTicket) throws WxErrorException;
 
   /**
    * 重命名文件
    * 该接口用于对指定文件进行重命名。
    * <p>
    * 请求方式:POST(HTTPS)
-   * 请求地址: https://qyapi.weixin.qq.com/cgi-bin/wedrive/file_rename?access_token=ACCESS_TOKEN
+   * 请求地址: <a href="https://qyapi.weixin.qq.com/cgi-bin/wedrive/file_rename?access_token=ACCESS_TOKEN">...</a>
    *
-   * @param userId  the user id
    * @param fileId  the file id
    * @param newName the new name
    * @return wx cp file rename
    * @throws WxErrorException the wx error exception
    */
-  WxCpFileRename fileRename(@NonNull String userId, @NonNull String fileId, @NonNull String newName) throws WxErrorException;
+  WxCpFileRename fileRename(@NonNull String fileId, @NonNull String newName) throws WxErrorException;
 
   /**
-   * 新建文件/文档
-   * 该接口用于在微盘指定位置新建文件、微文档
+   * 新建文件/文档
+   * 该接口用于在微盘指定位置新建文件夹、文档(更多文档接口能力可见文档API接口说明)
    * <p>
    * 请求方式:POST(HTTPS)
-   * 请求地址: https://qyapi.weixin.qq.com/cgi-bin/wedrive/file_create?access_token=ACCESS_TOKEN
+   * 请求地址: <a href="https://qyapi.weixin.qq.com/cgi-bin/wedrive/file_create?access_token=ACCESS_TOKEN">...</a>
    *
-   * @param userId   操作者userid
    * @param spaceId  空间spaceid
    * @param fatherId 父目录fileid, 在根目录时为空间spaceid
-   * @param fileType 文件类型, 1:文件夹 3:文档(文档) 4:文档(表格)
-   * @param fileName 文件名字
+   * @param fileType 文件类型, 1:文件夹 3:文档(文档) 4:文档(表格)
+   * @param fileName 文件名字(注意:文件名最多填255个字符, 英文算1个, 汉字算2个)
    * @return wx cp file create
    * @throws WxErrorException the wx error exception
    */
-  WxCpFileCreate fileCreate(@NonNull String userId, @NonNull String spaceId,
-                            @NonNull String fatherId, @NonNull Integer fileType, @NonNull String fileName) throws WxErrorException;
+  WxCpFileCreate fileCreate(@NonNull String spaceId, @NonNull String fatherId, @NonNull Integer fileType,
+                            @NonNull String fileName) throws WxErrorException;
 
   /**
    * 移动文件
    * 该接口用于将文件移动到指定位置。
    * <p>
    * 请求方式:POST(HTTPS)
-   * 请求地址: https://qyapi.weixin.qq.com/cgi-bin/wedrive/file_move?access_token=ACCESS_TOKEN
+   * 请求地址: <a href="https://qyapi.weixin.qq.com/cgi-bin/wedrive/file_move?access_token=ACCESS_TOKEN">...</a>
    *
    * @param request 移动文件的请求参数
    * @return wx cp file move
@@ -213,21 +217,33 @@ public interface WxCpOaWeDriveService {
    * 该接口用于删除指定文件。
    * <p>
    * 请求方式:POST(HTTPS)
-   * 请求地址: https://qyapi.weixin.qq.com/cgi-bin/wedrive/file_delete?access_token=ACCESS_TOKEN
+   * 请求地址: <a href="https://qyapi.weixin.qq.com/cgi-bin/wedrive/file_delete?access_token=ACCESS_TOKEN">...</a>
    *
-   * @param userId 操作者userid
-   * @param fileId 文件fileid列表
+   * @param fileIds 文件fileid列表
    * @return wx cp base resp
    * @throws WxErrorException the wx error exception
    */
-  WxCpBaseResp fileDelete(@NonNull String userId, @NonNull List<String> fileId) throws WxErrorException;
+  WxCpBaseResp fileDelete(@NonNull List<String> fileIds) throws WxErrorException;
+
+  /**
+   * 文件信息
+   * 该接口用于获取指定文件的信息。
+   * <p>
+   * 请求方式:POST(HTTPS)
+   * 请求地址: <a href="https://qyapi.weixin.qq.com/cgi-bin/wedrive/file_info?access_token=ACCESS_TOKEN">...</a>
+   *
+   * @param fileId the file id
+   * @return wx cp file info
+   * @throws WxErrorException the wx error exception
+   */
+  WxCpFileInfo fileInfo(@NonNull String fileId) throws WxErrorException;
 
   /**
    * 新增指定人
    * 该接口用于对指定文件添加指定人/部门。
    * <p>
    * 请求方式:POST(HTTPS)
-   * 请求地址: https://qyapi.weixin.qq.com/cgi-bin/wedrive/file_acl_add?access_token=ACCESS_TOKEN
+   * 请求地址: <a href="https://qyapi.weixin.qq.com/cgi-bin/wedrive/file_acl_add?access_token=ACCESS_TOKEN">...</a>
    *
    * @param request 新增指定人请求参数
    * @return wx cp base resp
@@ -240,7 +256,7 @@ public interface WxCpOaWeDriveService {
    * 该接口用于删除指定文件的指定人/部门。
    * <p>
    * 请求方式:POST(HTTPS)
-   * 请求地址: https://qyapi.weixin.qq.com/cgi-bin/wedrive/file_acl_del?access_token=ACCESS_TOKEN
+   * 请求地址: <a href="https://qyapi.weixin.qq.com/cgi-bin/wedrive/file_acl_del?access_token=ACCESS_TOKEN">...</a>
    *
    * @param request 请求参数
    * @return wx cp base resp
@@ -253,7 +269,7 @@ public interface WxCpOaWeDriveService {
    * 该接口用于文件的分享设置。
    * <p>
    * 请求方式:POST(HTTPS)
-   * 请求地址: https://qyapi.weixin.qq.com/cgi-bin/wedrive/file_setting?access_token=ACCESS_TOKEN
+   * 请求地址: <a href="https://qyapi.weixin.qq.com/cgi-bin/wedrive/file_setting?access_token=ACCESS_TOKEN">...</a>
    *
    * @param userId    the user id
    * @param fileId    the file id
@@ -269,7 +285,7 @@ public interface WxCpOaWeDriveService {
    * 该接口用于获取文件的分享链接。
    * <p>
    * 请求方式:POST(HTTPS)
-   * 请求地址: https://qyapi.weixin.qq.com/cgi-bin/wedrive/file_share?access_token=ACCESS_TOKEN
+   * 请求地址: <a href="https://qyapi.weixin.qq.com/cgi-bin/wedrive/file_share?access_token=ACCESS_TOKEN">...</a>
    *
    * @param userId the user id
    * @param fileId the file id
@@ -278,18 +294,4 @@ public interface WxCpOaWeDriveService {
    */
   WxCpFileShare fileShare(@NonNull String userId, @NonNull String fileId) throws WxErrorException;
 
-  /**
-   * 文件信息
-   * 该接口用于获取指定文件的信息。
-   * <p>
-   * 请求方式:POST(HTTPS)
-   * 请求地址: https://qyapi.weixin.qq.com/cgi-bin/wedrive/file_info?access_token=ACCESS_TOKEN
-   *
-   * @param userId the user id
-   * @param fileId the file id
-   * @return wx cp file info
-   * @throws WxErrorException the wx error exception
-   */
-  WxCpFileInfo fileInfo(@NonNull String userId, @NonNull String fileId) throws WxErrorException;
-
 }

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

@@ -114,10 +114,9 @@ public class WxCpOaWeDriveServiceImpl implements WxCpOaWeDriveService {
   }
 
   @Override
-  public WxCpFileRename fileRename(@NonNull String userId, @NonNull String fileId, @NonNull String newName) throws WxErrorException {
+  public WxCpFileRename fileRename(@NonNull String fileId, @NonNull String newName) throws WxErrorException {
     String apiUrl = this.cpService.getWxCpConfigStorage().getApiUrl(FILE_RENAME);
     JsonObject jsonObject = new JsonObject();
-    jsonObject.addProperty("userid", userId);
     jsonObject.addProperty("fileid", fileId);
     jsonObject.addProperty("new_name", newName);
     String responseContent = this.cpService.post(apiUrl, jsonObject.toString());
@@ -125,11 +124,10 @@ public class WxCpOaWeDriveServiceImpl implements WxCpOaWeDriveService {
   }
 
   @Override
-  public WxCpFileCreate fileCreate(@NonNull String userId, @NonNull String spaceId, @NonNull String fatherId,
+  public WxCpFileCreate fileCreate(@NonNull String spaceId, @NonNull String fatherId,
                                    @NonNull Integer fileType, @NonNull String fileName) throws WxErrorException {
     String apiUrl = this.cpService.getWxCpConfigStorage().getApiUrl(FILE_CREATE);
     JsonObject jsonObject = new JsonObject();
-    jsonObject.addProperty("userid", userId);
     jsonObject.addProperty("spaceid", spaceId);
     jsonObject.addProperty("fatherid", fatherId);
     jsonObject.addProperty("file_type", fileType);
@@ -146,9 +144,9 @@ public class WxCpOaWeDriveServiceImpl implements WxCpOaWeDriveService {
   }
 
   @Override
-  public WxCpBaseResp fileDelete(@NonNull String userId, @NonNull List<String> fileId) throws WxErrorException {
+  public WxCpBaseResp fileDelete(@NonNull List<String> fileIds) throws WxErrorException {
     String apiUrl = this.cpService.getWxCpConfigStorage().getApiUrl(FILE_DELETE);
-    WxCpFileDeleteRequest request = new WxCpFileDeleteRequest(userId, fileId);
+    WxCpFileDeleteRequest request = new WxCpFileDeleteRequest(fileIds);
     String responseContent = this.cpService.post(apiUrl, request.toJson());
     return WxCpBaseResp.fromJson(responseContent);
   }
@@ -193,10 +191,9 @@ public class WxCpOaWeDriveServiceImpl implements WxCpOaWeDriveService {
   }
 
   @Override
-  public WxCpFileInfo fileInfo(@NonNull String userId, @NonNull String fileId) throws WxErrorException {
+  public WxCpFileInfo fileInfo(@NonNull String fileId) throws WxErrorException {
     String apiUrl = this.cpService.getWxCpConfigStorage().getApiUrl(FILE_INFO);
     JsonObject jsonObject = new JsonObject();
-    jsonObject.addProperty("userid", userId);
     jsonObject.addProperty("fileid", fileId);
     String responseContent = this.cpService.post(apiUrl, jsonObject.toString());
     return WxCpFileInfo.fromJson(responseContent);

+ 0 - 3
weixin-java-cp/src/main/java/me/chanjar/weixin/cp/bean/oa/wedrive/WxCpFileDeleteRequest.java

@@ -22,9 +22,6 @@ import java.util.List;
 public class WxCpFileDeleteRequest implements Serializable {
   private static final long serialVersionUID = -4960239393895754138L;
 
-  @SerializedName("userid")
-  private String userId;
-
   @SerializedName("fileid")
   private List<String> fileId;
 

+ 0 - 4
weixin-java-cp/src/main/java/me/chanjar/weixin/cp/bean/oa/wedrive/WxCpFileDownload.java

@@ -35,8 +35,4 @@ public class WxCpFileDownload extends WxCpBaseResp implements Serializable {
     return WxCpGsonBuilder.create().fromJson(json, WxCpFileDownload.class);
   }
 
-  public String toJson() {
-    return WxCpGsonBuilder.create().toJson(this);
-  }
-
 }

+ 0 - 3
weixin-java-cp/src/main/java/me/chanjar/weixin/cp/bean/oa/wedrive/WxCpFileListRequest.java

@@ -21,9 +21,6 @@ import java.io.Serializable;
 public class WxCpFileListRequest implements Serializable {
   private static final long serialVersionUID = -4960239393895754138L;
 
-  @SerializedName("userid")
-  private String userId;
-
   @SerializedName("spaceid")
   private String spaceId;
 

+ 0 - 6
weixin-java-cp/src/main/java/me/chanjar/weixin/cp/bean/oa/wedrive/WxCpFileMoveRequest.java

@@ -22,12 +22,6 @@ public class WxCpFileMoveRequest implements Serializable {
   private static final long serialVersionUID = -4960239393895754138L;
 
   /**
-   * 操作者userid
-   */
-  @SerializedName("userid")
-  private String userId;
-
-  /**
    * 如果移动到的目标目录与需要移动的文件重名时,是否覆盖。
    * true:重名文件覆盖
    * false:重名文件进行冲突重命名处理(移动后文件名格式如xxx(1).txt xxx(1).doc等)

+ 0 - 3
weixin-java-cp/src/main/java/me/chanjar/weixin/cp/bean/oa/wedrive/WxCpFileUploadRequest.java

@@ -21,9 +21,6 @@ import java.io.Serializable;
 public class WxCpFileUploadRequest implements Serializable {
   private static final long serialVersionUID = -4960239393895754138L;
 
-  @SerializedName("userid")
-  private String userId;
-
   @SerializedName("spaceid")
   private String spaceId;
 

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

@@ -110,13 +110,13 @@ public class WxCpOaWeDriveServiceTest {
      */
     ArrayList<String> fileIds = Lists.newArrayList();
     fileIds.add(fileId);
-    WxCpBaseResp fileDelete = cpService.getOaWeDriveService().fileDelete(uId, fileIds);
+    WxCpBaseResp fileDelete = cpService.getOaWeDriveService().fileDelete(fileIds);
     log.info("删除文件数据为:{}", fileDelete.toJson());
 
     /**
      * 文件信息
      */
-    WxCpFileInfo fileInfo = cpService.getOaWeDriveService().fileInfo(uId, fileId);
+    WxCpFileInfo fileInfo = cpService.getOaWeDriveService().fileInfo(fileId);
     log.info("fileInfo数据为:{}", fileInfo.toJson());
 
     /**
@@ -134,7 +134,7 @@ public class WxCpOaWeDriveServiceTest {
     /**
      * 新建文件/微文档
      */
-    WxCpFileCreate fileCreate = cpService.getOaWeDriveService().fileCreate(uId, spId, spId, 3, "新建微文档1");
+    WxCpFileCreate fileCreate = cpService.getOaWeDriveService().fileCreate(spId, spId, 3, "新建微文档1");
     log.info("新建文件/微文档:{}", fileCreate.toJson());
 
     /**