Skip to content

WeCom Office WeDrive SKILL (wecom-office-wedrive)

企业微信微盘域 SKILL:覆盖空间 CRUD、文件/文件夹管理、文件权限配置、文件分块上传、6 种回调事件等 24 个 API。


1. Prerequisites

应用类型凭证要求权限要求
自建应用应用 secret微盘权限
第三方应用suite_access_token微盘权限

2. Core Concepts

微盘体系
├── 空间 (Space)
│   ├── 空间成员管理 → 添加/移除/权限设置
│   ├── 空间安全设置 → 水印/外部分享/下载限制
│   └── 文件系统
│       ├── 文件夹 (Folder)
│       └── 文件 (File) → 上传/下载/移动/复制/删除
└── 文件权限
    ├── 成员权限 → 管理员/编辑/查看
    ├── 分享设置 → 企业内/外分享规则
    └── 安全设置 → 只读复制/水印

3. API Quick Reference

3.1 空间管理

#接口方法Endpoint
W1创建空间POSTwedrive/space_create
W2重命名空间POSTwedrive/space_rename
W3获取空间信息POSTwedrive/space_info
W4解散空间POSTwedrive/space_dismiss

3.2 空间成员

#接口方法Endpoint
W5添加空间成员POSTwedrive/space_acl_add
W6删除空间成员POSTwedrive/space_acl_del
W7修改空间权限POSTwedrive/space_setting

3.3 文件/文件夹管理

#接口方法Endpoint
W8获取文件列表POSTwedrive/file_list
W9上传文件POST (multipart)wedrive/file_upload
W10下载文件POSTwedrive/file_download
W11新建文件夹/文档POSTwedrive/file_create
W12重命名文件POSTwedrive/file_rename
W13移动文件POSTwedrive/file_move
W14复制文件POSTwedrive/file_copy
W15删除文件POSTwedrive/file_delete
W16获取文件信息POSTwedrive/file_info
W17文件分块上传POSTwedrive/file_upload_part

3.4 文件权限

#接口方法Endpoint
W18新增文件成员POSTwedrive/file_acl_add
W19删除文件成员POSTwedrive/file_acl_del
W20分享设置POSTwedrive/file_share
W21获取分享链接POSTwedrive/file_share_url
W22获取文件权限信息POSTwedrive/file_acl_info
W23修改文件安全设置POSTwedrive/file_secure_setting

4. Code Templates

python
"""WeCom WeDrive Client — 微盘管理"""
from wecom_core import WeComClient


class WeDriveClient:
    def __init__(self, client: WeComClient):
        self.client = client

    # ── 空间 ──

    def space_create(self, userid: str, space_name: str, auth_info: list[dict] | None = None) -> dict:
        """W1: 创建空间"""
        body: dict = {"userid": userid, "space_name": space_name}
        if auth_info:
            body["auth_info"] = auth_info
        return self.client.post("/wedrive/space_create", json=body)

    def space_info(self, spaceid: str) -> dict:
        """W3: 获取空间信息"""
        return self.client.post("/wedrive/space_info", json={"spaceid": spaceid})

    def space_dismiss(self, spaceid: str) -> None:
        """W4: 解散空间"""
        self.client.post("/wedrive/space_dismiss", json={"spaceid": spaceid})

    # ── 文件 ──

    def file_list(self, spaceid: str, fatherid: str, sort_type: int = 1,
                  start: int = 0, limit: int = 100) -> dict:
        """W8: 获取文件列表"""
        return self.client.post("/wedrive/file_list", json={
            "spaceid": spaceid, "fatherid": fatherid,
            "sort_type": sort_type, "start": start, "limit": limit,
        })

    def file_upload(self, spaceid: str, fatherid: str, filepath: str) -> dict:
        """W9: 上传文件"""
        import os
        from pathlib import Path
        filename = Path(filepath).name
        with open(filepath, "rb") as f:
            files = {"file": (filename, f)}
            return self.client.post(
                "/wedrive/file_upload",
                params={"spaceid": spaceid, "fatherid": fatherid},
                files=files,
            )

    def file_download(self, fileid: str) -> dict:
        """W10: 下载文件(返回下载链接)"""
        return self.client.post("/wedrive/file_download", json={"fileid": fileid})

    def file_create(self, spaceid: str, fatherid: str, file_type: int, file_name: str) -> dict:
        """W11: 新建文件夹/文档
        file_type: 1=文件夹, 3=文档, 4=表格
        """
        return self.client.post("/wedrive/file_create", json={
            "spaceid": spaceid, "fatherid": fatherid,
            "file_type": file_type, "file_name": file_name,
        })

    def file_delete(self, fileid_list: list[str]) -> None:
        """W15: 删除文件"""
        self.client.post("/wedrive/file_delete", json={"fileid": fileid_list})

    def file_info(self, fileid: str) -> dict:
        """W16: 获取文件信息"""
        return self.client.post("/wedrive/file_info", json={"fileid": fileid})

    # ── 权限 ──

    def file_acl_add(self, fileid: str, auth_info: list[dict]) -> None:
        """W18: 新增文件成员"""
        self.client.post("/wedrive/file_acl_add", json={
            "fileid": fileid, "auth_info": auth_info,
        })

    def file_share(self, fileid: str, auth_scope: int) -> None:
        """W20: 设置分享范围 (auth_scope: 1=仅成员, 2=企业内, 3=企业外)"""
        self.client.post("/wedrive/file_share", json={
            "fileid": fileid, "auth_scope": auth_scope,
        })

4.1 Java 示例

java
public class WecomOfficeWedriveService {
    private final WeComClient client;

    public WecomOfficeWedriveService(WeComClient client) {
        this.client = client;
    }

    /**
     * 使用示例:调用 wecom-office-wedrive 相关 API
     * 请参考本 SKILL 的 API 速查表选择具体接口
     */
    public JsonObject callApi(String path, JsonObject params) throws Exception {
        return client.post(path, params);
    }

    // 更多方法请参考上方 API 详细说明章节,每个接口对应一个方法
    // 关键注意事项请查阅「踩坑指南」章节
}

依赖 (Maven):

xml
<dependency>
    <groupId>com.squareup.okhttp3</groupId>
    <artifactId>okhttp</artifactId>
    <version>4.12.0</version>
</dependency>
<dependency>
    <groupId>com.google.code.gson</groupId>
    <artifactId>gson</artifactId>
    <version>2.10.1</version>
</dependency>

4.2 PHP 示例

php
<?php
class WecomOfficeWedriveService
{
    private WeComClient $client;

    public function __construct(WeComClient $client) { $this->client = $client; }

    /**
     * 使用示例:调用 wecom-office-wedrive 相关 API
     * 请参考本 SKILL 的 API 速查表选择具体接口
     */
    public function callApi(string $path, array $params = []): array
    {
        return $this->client->post($path, $params);
    }

    // 更多方法请参考上方 API 详细说明章节
    // 关键注意事项请查阅「踩坑指南」章节
}

依赖 (Composer):

bash
composer require guzzlehttp/guzzle

5. Callbacks

#事件说明
C1wedrive_space_change空间文件变更
C2wedrive_space_dismiss解散空间
C3wedrive_space_member_change修改空间成员
C4wedrive_space_secure_change修改空间安全设置
C5wedrive_file_change文件变更
C6wedrive_capacity_warning微盘容量不足

6. Gotcha Guide

G1. fileid vs spaceid

每个文件/文件夹都有唯一的 fileid,空间有唯一的 spaceid。操作文件时需要同时知道 spaceidfileid

G2. 分块上传用于大文件

超过 20MB 的文件建议使用分块上传 (file_upload_part),需要分步完成:初始化 → 分块上传 → 完成。

G3. 文件下载返回的是链接

file_download 不直接返回文件内容,而是返回一个临时下载链接(有效期有限),需要用该链接再发 HTTP GET 下载。


7. References

doc_id 范围说明
39418-26914空间管理 + 文件管理
44647-44681空间/文件/权限/回调
40102文件分块上传
50758-50760高级功能账号管理

依赖 SKILLwecom-core

Released under the Apache 2.0 License.