企业微信效率工具的使用(二)

907 阅读13分钟

微盘

概述

企业通过微盘相关接口,可以对微盘的文件进行操作和设置权限。

开发流程

  1. 进入管理后台-应用管理-微盘,进入微盘api设置页,开启api接口同步;
  2. 开启后,可设置微盘api的权限:只读权限或编辑权限;
  3. 获取微盘的secret,通过相应的secret及corpid换取access_token
  4. 通过获得的access_token调用微盘相关接口。

访问频率限制

免费企业调用微盘api累计上限为1000次/月,付费企业为100,000次/月,上限次数按自然月计算。

空间管理

新建空间

用于在微盘内新建空间,可以指定人创建空间。

请求方式:POST(HTTPS)

请求地址: qyapi.weixin.qq.com/cgi-bin/wed…

请求参数

 {
     "userid": "serendipity",
     "space_name": "微盘空间标题",
     "auth_info": [{
         "type": 1,
         "userid": "serendipity"
     }]
 }

参数说明

参数类型是否必须说明
useridstring操作者userid
space_namestring空间标题
auth_infoobj[]空间其他成员信息
typeuint32成员类型 1:个人 2:部门
useridstring成员userid,字符串
departmentiduint32部门departmentid, 32位整型范围是[0, 2^32)
authuint32成员权限 1:可下载 2:可编辑 4:可预览(仅专业版企业可设置)

返回结果

 {
     "errcode": 0,
     "errmsg": "ok",
     "spaceid": "s.ww028e7efec93353d4.629261407R2I"
 }

参数说明

参数类型说明
spaceidstring空间id

重命名空间

用于重命名已有空间,接收userid参数,以空间管理员身份来重命名。

请求方式:POST(HTTPS)

请求地址: qyapi.weixin.qq.com/cgi-bin/wed…

请求参数

 {
     "userid": "serendipity",
     "spaceid": "s.ww028e7efec93353d4.629261407R2I",
     "space_name": "重命名空间"
 }

参数说明

参数类型是否必须说明
useridstring操作者userid
spaceidstring空间spaceid
space_namestring重命名后的空间名

返回结果

 {
     "errcode": 0,
     "errmsg": "ok"
 }

解散空间

用于解散已有空间,需要以空间管理员身份来解散。

请求方式:POST(HTTPS)

请求地址: qyapi.weixin.qq.com/cgi-bin/wed…

请求参数

 {
     "userid": "serendipity",
     "spaceid": "s.ww028e7efec93353d4.629261407R2I"
 }

参数说明

参数类型是否必须说明
useridstring操作者userid
spaceidstring空间spaceid

返回结果

 {
     "errcode": 0,
     "errmsg": "ok"
 }

获取空间信息

用于获取空间成员列表、信息、权限等信息。

请求方式:POST(HTTPS)

请求地址: qyapi.weixin.qq.com/cgi-bin/wed…

请求参数

 {
     "userid": "serendipity",
     "spaceid": "s.ww028e7efec93353d4.629262066paL"
 }

参数说明

参数类型是否必须说明
useridstring操作者userid
spaceidstring空间spaceid

返回结果

 {
     "errcode": 0,
     "errmsg": "ok",
     "space_info": {
         "spaceid": "s.ww028e7efec93353d4.629262066paL",
         "space_name": "微盘空间标题",
         "auth_list": {
             "auth_info": [
                 {
                     "type": 1,
                     "userid": "serendipity",
                     "auth": 3
                 }
             ]
         }
     }
 }

参数说明

参数类型说明
spaceidstring空间spaceid
space_namestring空间名称
auth_listobj[]空间成员列表
auth_infoobj[]空间成员信息
typeuint32成员类型 1:个人 2:部门
useridstring成员userid,字符串
departmentiduint32部门departmentid, 32位整型范围是[0, 2^32)
authuint32成员权限 1:可下载 2:可编辑 3;管理员 4:可预览
quit_useridstring[]空间无权限成员userid (成员在一个有权限的部门中, 自己退出空间或者被移除权限)

空间权限

添加成员/部门

用于对指定空间添加成员/部门,可一次性添加多个。

请求方式:POST(HTTPS)

请求地址: qyapi.weixin.qq.com/cgi-bin/wed…

请求参数

 {
     "userid": "serendipity",
     "spaceid": "s.ww028e7efec93353d4.629262066paL",
     "auth_info": [{
         "type": 1,
         "userid": "MoDaoBuXiaoHun"
         "auth": 1
     }]
 }

参数说明

参数类型是否必须说明
useridstring操作者userid
spaceidstring空间spaceid
auth_infoobj[]被添加的空间成员信息
typeuint32成员类型 1:个人 2:部门
useridstring成员userid,字符串 (type为1时填写)
departmentiduint32部门departmentid, 32位整型范围是[0, 2^32) (type为2时填写)
authuint321:可下载 2:可编辑 4:可预览(仅专业版企业可设置)

返回结果

 {
     "errcode": 0,
     "errmsg": "ok"
 }

移除成员/部门

用于对指定空间移除成员/部门,操作者需要有移除权限。

请求方式:POST(HTTPS)

请求地址: qyapi.weixin.qq.com/cgi-bin/wed…

请求参数

 {
     "userid": "serendipity",
     "spaceid": "s.ww028e7efec93353d4.629262066paL",
     "auth_info": [{
         "type": 1,
         "userid": "MoDaoBuXiaoHun"
     }]
 }

参数说明

参数类型是否必须说明
useridstring操作者userid
spaceidstring空间spaceid
auth_infoobj[]被移除的空间成员信息
typeuint32成员类型 1:个人 2:部门
useridstring成员userid,字符串 (type为1时填写)
departmentiduint32部门departmentid, 32位整型范围是[0, 2^32) (type为2时填写)

返回结果

 {
     "errcode": 0,
     "errmsg": "ok"
 }

权限管理

用于修改空间权限,需要传入userid,修改权限范围继承传入用户的权限范围。

请求方式:POST(HTTPS)

请求地址: qyapi.weixin.qq.com/cgi-bin/wed…

请求参数

 {
     "userid": "serendipity",
     "spaceid": "s.ww028e7efec93353d4.629262066paL",
     "add_member_only_admin": true,
     "enable_share_url": false,
     "share_url_no_approve": true,
     "share_url_no_approve_default_auth": 1
 }
参数类型是否必须说明
useridstring操作者userid
spaceidstring空间spaceid
enable_watermarkbool(本字段仅专业版企业可设置)启用水印。false:关 true:开 ;如果不填充此字段为保持原有状态
add_member_only_adminbool仅管理员可增减空间成员和修改文件分享设置。false:关 true:开 ;如果不填充此字段为保持原有状态
enable_share_urlbool启用成员邀请链接。false:关 true:开 ;如果不填充此字段为保持原有状态
share_url_no_approvebool通过链接加入空间无需审批。false:关; true:开; 如果不填充此字段为保持原有状态
share_url_no_approve_default_authuint32邀请链接默认权限。1:仅浏览(可下载)2:可编辑 4:可预览(仅专业版企业可设置);如果不填充此字段为保持原有状态

返回结果

 {
     "errcode": 0,
     "errmsg": "ok"
 }

获取邀请链接

用于获取空间邀请分享链接。

请求方式:POST(HTTPS)

请求地址: qyapi.weixin.qq.com/cgi-bin/wed…

请求参数

 {
     "userid": "serendipity",
     "spaceid": "s.ww028e7efec93353d4.629262066paL"
 }

参数说明

参数类型是否必须说明
useridstring操作者userid
spaceidstring空间spaceid

返回结果

 {
     "errcode": 0,
     "errmsg": "ok",
     "space_share_url": "https://drive.weixin.qq.com/s?k=AC8ApgecABEiKCpOvr"
 }

参数说明

参数类型说明
space_share_urlstring邀请链接

文件管理

获取文件列表

用于获取指定地址下的文件列表。

请求方式:POST(HTTPS)

请求地址: qyapi.weixin.qq.com/cgi-bin/wed…

请求参数

 {
     "userid": "serendipity",
     "spaceid": "s.ww028e7efec93353d4.629262066paL"
     "fatherid": "s.ww028e7efec93353d4.629262066paL"
     "sort_type": 6,
     "start": 0,
     "limit": 1000
 }

参数说明

参数类型是否必须说明
useridstring操作者userid
spaceidstring空间spaceid
fatheridstring当前目录的fileid,根目录时为空间spaceid
sort_typeuint32列表排序方式 1:名字升序;2:名字降序;3:大小升序;4:大小降序;5:修改时间升序;6:修改时间降序
startuint32首次填0, 后续填上一次请求返回的next_start
limituint32分批拉取最大文件数, 不超过1000

返回结果

 {
     "errcode": 0,
     "errmsg": "ok",
     "file_list": {
         "item": [
             {
                 "fileid": "s.ww028e7efec93353d4.629262066paL_w2.629276182qraO",
                 "file_name": "测试文件1",
                 "spaceid": "s.ww028e7efec93353d4.629262066paL",
                 "fatherid": "s.ww028e7efec93353d4.629262066paL",
                 "file_size": 0,
                 "ctime": 1629276182,
                 "mtime": 1629276244,
                 "file_type": 3,
                 "file_status": 1,
                 "create_userid": "serendipity",
                 "update_userid": "serendipity",
                 "sha": "",
                 "md5": "",
                 "url": "https://doc.weixin.qq.com/txdoc/word?docid=w2_ACAA7AbnADw9nDd1LqORc6ZEu00Bx&scode=AC8ApgecABEXxY6eIZACAA7AbnADw&type=0"
             },
             {
                 "fileid": "s.ww028e7efec93353d4.629262066paL_w2.6292761721R0k",
                 "file_name": "测试文件2",
                 "spaceid": "s.ww028e7efec93353d4.629262066paL",
                 "fatherid": "s.ww028e7efec93353d4.629262066paL",
                 "file_size": 0,
                 "ctime": 1629276172,
                 "mtime": 1629276238,
                 "file_type": 3,
                 "file_status": 1,
                 "create_userid": "serendipity",
                 "update_userid": "serendipity",
                 "sha": "",
                 "md5": "",
                 "url": "https://doc.weixin.qq.com/txdoc/word?docid=w2_ACAA7AbnADwIRLX1ALfTCGwSTWakf&scode=AC8ApgecABEtHrb7FiACAA7AbnADw&type=0"
             }
         ]
     },
     "next_start": 2,
     "has_more": false
 }

参数说明

参数类型说明
has_morebooltrue为列表还有内容, 需要继续分批拉取
next_startuint32下次分批拉取对应的请求参数start值
file_listobj[]文件列表
fileidstring文件fileid
file_namestring文件名字
spaceidstring文件所在的空间spaceid
fatheridstring文件所在的目录fileid, 在根目录时为fileid
file_sizeuint64文件大小
ctimeuint64文件创建时间
mtimeuint64文件最后修改时间
file_typeuint32文件类型, 1:文件夹 2:文件 3:微文档(文档) 4:微文档(表格) 5:微文档(收集表)
file_statusuint32文件状态, 1:正常 2:删除
create_useridstring文件创建者userid
update_useridstring文件最后修改者userid
shastring文件sha
md5string文件md5
urlstring仅微文档类型返回访问链接

上传文件

用于向微盘中的指定位置上传文件。

请求方式:POST(HTTPS)

请求地址: qyapi.weixin.qq.com/cgi-bin/wed…

请求参数

 {
     "userid": "serendipity",
     "spaceid": "s.ww028e7efec93353d4.629262066paL",
     "fatherid": "s.ww028e7efec93353d4.629262066paL",
     "file_name": "文件名字",
     "file_base64_content": "文件内容"
 }

参数说明

参数类型是否必须说明
useridstring操作者userid
spaceidstring空间spaceid
fatheridstring父目录fileid, 在根目录时为空间spaceid
file_namestring文件名字
file_base64_contentstring文件内容base64(注意:只需要填入文件内容的Base64,不需要添加任何如:”data:application/x-javascript;base64” 的数据类型描述信息)

返回结果

 {
     "errcode": 0,
     "errmsg": "ok",
     "fileid": "s.ww028e7efec93353d4.629262066paL_f.6292780609RUa"
 }

参数说明

参数类型说明
fileidstring新建文件的fielid

下载文件

用于下载文件,请求的userid需有下载权限。

请求方式:POST(HTTPS)

请求地址: qyapi.weixin.qq.com/cgi-bin/wed…

请求参数

 {
     "userid": "serendipity",
     "fileid": "s.ww028e7efec93353d4.629262066paL_f.6292780609RUa"
 }

参数说明

参数类型是否必须说明
useridstring操作者userid
fileidstring文件fileid(只支持下载普通文件,不支持下载文件夹或微文档)

返回结果

 {
     "errcode": 0,
     "errmsg": "ok",
     "download_url": "https://sz-btfs-v2-down.wework.ftn.qq.com/ftn_handler/3f1db5c032f59190d57fffe672d86ef02e0bed9c484ca7925f046787800245f91b8954198ad3dbb6df0644145332307a2760f40e449a7bdd49f58f7a03a0004f?fname=%E6%96%87%E4%BB%B6%E5%90%8D%E5%AD%97.txt",
     "cookie_name": "FTN5K",
     "cookie_value": "ada7a394"
 }

参数说明

参数类型说明
download_urlstring下载请求url (有效期2个小时)
cookie_namestring下载请求带cookie的key
cookie_valuestring下载请求带cookie的value

新建文件/微文档

在微盘指定位置新建文件、微文档。

请求方式:POST(HTTPS)

请求地址: qyapi.weixin.qq.com/cgi-bin/wed…

参数说明

 {
     "userid": "serendipity",
     "spaceid": "s.ww028e7efec93353d4.629262066paL",
     "fatherid": "s.ww028e7efec93353d4.629262066paL",
     "file_type": 1,
     "file_name": "FILE_NAME"
 }

参数说明

参数类型是否必须说明
useridstring操作者userid
spaceidstring空间spaceid
fatheridstring父目录fileid, 在根目录时为空间spaceid
file_typeuint32文件类型, 1:文件夹 3:微文档(文档) 4:微文档(表格) 5:微文档(收集表)
file_namestring文件名字

返回结果

 {
     "errcode": 0,
     "errmsg": "ok",
     "fileid": "s.ww028e7efec93353d4.629262066paL_d.629281662Yc65"
 }

参数说明

参数类型说明
fileidstring新建文件的fileid
urlstring微文档的访问链接,仅在新建微文档时返回

重命名文件

用于对指定文件进行重命名。

请求方式:POST(HTTPS)

请求地址: qyapi.weixin.qq.com/cgi-bin/wed…

请求参数

 {
     "userid": "serendipity",
     "fileid": "s.ww028e7efec93353d4.629262066paL_d.629281662Yc65",
     "new_name": "NEW_NAME"
 }

参数说明

参数类型是否必须说明
useridstring操作者userid
fileidstring文件fileid
new_namestring重命名后的文件名

返回结果

 {
     "errcode": 0,
     "errmsg": "ok",
     "file": {
         "fileid": "s.ww028e7efec93353d4.629262066paL_d.629281662Yc65",
         "file_name": "NEW_NAME",
         "spaceid": "s.ww028e7efec93353d4.629262066paL",
         "fatherid": "s.ww028e7efec93353d4.629262066paL",
         "file_size": 0,
         "ctime": 1629281662,
         "mtime": 1629282000,
         "file_type": 1,
         "file_status": 1,
         "create_userid": "serendipity",
         "update_userid": "serendipity",
         "sha": "",
         "md5": ""
     }
 }

参数说明

参数类型说明
fileidstring文件fileid
file_namestring文件名字
spaceidstring文件所在的空间spaceid
fatheridstring文件所在的目录fileid, 在根目录时为spaceid
file_sizeuint64文件大小
ctimeuint64文件创建时间
mtimeuint64文件最后修改时间
file_typeuint32文件类型, 1:文件夹 2:文件 3:微文档(文档) 4:微文档(表格) 5:微文档(收集表)
file_statusuint32文件状态, 1:正常 2:删除
create_useridstring文件创建者userid
update_useridstring文件最后修改者userid
shastring文件sha
md5string文件md5

移动文件

用于将文件移动到指定位置。

请求方式:POST(HTTPS)

请求地址: qyapi.weixin.qq.com/cgi-bin/wed…

请求参数

 {
     "userid": "serendipity",
     "fatherid": "s.ww028e7efec93353d4.629262066paL_d.629281662Yc65",
     "replace": true,
     "fileid": ["s.ww028e7efec93353d4.629262066paL_f.629280823Jtzz"]
 }

参数说明

参数类型是否必须说明
useridstring操作者userid
fatheridstring要移动到那个目录的fileid,根目录时为空间spaceid
replacebool如果移动到的目标目录与需要移动的文件重名时,是否覆盖。true:重名文件覆盖 false:重名文件进行冲突重命名处理(移动后文件名格式如xxx(1).txt xxx(1).doc等)
fileidstring文件fileid

返回结果

 {
     "errcode": 0,
     "errmsg": "ok",
     "file_list": {
         "item": [
             {
                 "fileid": "s.ww028e7efec93353d4.629262066paL_f.629280823Jtzz",
                 "file_name": "测试文件.txt",
                 "spaceid": "s.ww028e7efec93353d4.629262066paL",
                 "fatherid": "s.ww028e7efec93353d4.629262066paL_d.629281662Yc65",
                 "file_size": 12,
                 "ctime": 1629280823,
                 "mtime": 1629362040,
                 "file_type": 2,
                 "file_status": 1,
                 "create_userid": "serendipity",
                 "update_userid": "serendipity",
                 "sha": "",
                 "md5": "b27f229c812da4e6420795e69d14bb87"
             }
         ]
     }
 }

参数说明

参数类型说明
file_listobj[]移动文件的信息列表
fileidstring文件fileid
file_namestring文件名字
spaceidstring文件所在的空间spaceid
fatheridstring文件所在的目录fileid, 在根目录时为fileid
file_sizeuint64文件大小
ctimeuint64文件创建时间
mtimeuint64文件最后修改时间
file_typeuint32文件类型, 1:文件夹 2:文件 3:微文档(文档) 4:微文档(表格) 5:微文档(收集表)
file_statusuint32文件状态, 1:正常 2:删除
create_useridstring文件创建者userid
update_useridstring文件最后修改者userid
shastring文件sha
md5string文件md5

删除文件

用于删除指定文件。

请求方式:POST(HTTPS)

请求地址: qyapi.weixin.qq.com/cgi-bin/wed…

请求参数

 {
     "userid": "serendipity",
     "fileid": ["s.ww028e7efec93353d4.629262066paL_f.629280823Jtzz"]
 }

参数说明

参数类型是否必须说明
useridstring操作者userid
fileidstring[]文件fileid

注意:可删除多个文件

返回结果

 {
     "errcode": 0,
     "errmsg": "ok"
 }

文件信息

用于获取指定文件的信息。

请求方式:POST(HTTPS)

请求地址: qyapi.weixin.qq.com/cgi-bin/wed…

请求参数

 {
     "userid": "serendipity",
     "fileid": "s.ww028e7efec93353d4.629262066paL_f.629280823Jtzz"
 }

参数说明

参数类型是否必须说明
useridstring操作者userid
fileidstring文件fileid

返回结果

 {
     "errcode": 0,
     "errmsg": "ok",
     "file_info": {
         "fileid": "s.ww028e7efec93353d4.629262066paL_f.629280823Jtzz",
         "file_name": "测试文件.txt",
         "spaceid": "s.ww028e7efec93353d4.629262066paL",
         "fatherid": "s.ww028e7efec93353d4.629262066paL_d.629281662Yc65",
         "file_size": 12,
         "ctime": 1629280823,
         "mtime": 1629362299,
         "file_type": 2,
         "file_status": 2,
         "create_userid": "serendipity",
         "update_userid": "serendipity",
         "sha": "",
         "md5": "b27f229c812da4e6420795e69d14bb87"
     }
 }

参数说明

参数类型说明
fileidstring文件fileid
file_namestring文件名字
spaceidstring文件所在的空间spaceid
fatheridstring文件所在的目录fileid, 在根目录时为fileid
file_sizeuint64文件大小
ctimeuint64文件创建时间
mtimeuint64文件最后修改时间
file_typeuint321: 文件夹 2:文件 3: 微文档(文档) 4: 微文档(表格) 5:微文档(收集表)
file_statusuint32文件状态, 1:正常 2:删除
create_useridstring文件创建者userid
update_useridstring文件最后修改者userid
shastring文件sha
md5string文件md5
urlstring仅微文档类型返回访问链接

文件权限

新增指定人

用于对指定文件添加指定人/部门。

请求方式:POST(HTTPS)

请求地址: qyapi.weixin.qq.com/cgi-bin/wed…

请求参数

 {
     "userid": "serendipity",
     "fileid": "s.ww028e7efec93353d4.629262066paL_f.629362693V1Jj",
     "auth_info": [{
         "type": 1,
         "userid": "WoShiZhuangZhuangXiaoKeAi",
         "auth": 1
     }]
 }

参数说明

参数类型是否必须说明
useridstring操作者userid
fileidstring文件fileid
auth_infoobj[]添加成员的信息
typeuint32成员类型 1:个人 2:部门
useridstring成员userid,字符串 (type为1时填写)
authuint32新增成员的权限信息 普通文档:1:仅浏览(可下载) 4:仅预览(仅专业版企业可设置);如果不填充此字段为保持原有状态 微 文 档:1:仅浏览(可下载)2:可编辑;如果不填充此字段为保持原有状态
departmentiduint32部门departmentid, 32位整型范围是[0, 2^32) (type为2时填写)

返回结果

 {
     "errcode": 0,
     "errmsg": "ok"
 }

删除指定人

用于删除指定文件的指定人/部门。

请求方式:POST(HTTPS)

请求地址: qyapi.weixin.qq.com/cgi-bin/wed…

请求参数

 {
     "userid": "serendipity",
     "fileid": "s.ww028e7efec93353d4.629262066paL_f.629362693V1Jj",
     "auth_info": [{
         "type": 1,
         "userid": "WoShiZhuangZhuangXiaoKeAi"
     }]
 }

参数说明

参数类型是否必须说明
useridstring操作者userid
fileidstring文件fileid
auth_infoobj[]被移除的成员信息
typeuint32成员类型 1:个人 2:部门
useridstring成员userid,字符串 (type为1时填写)
departmentiduint32部门departmentid, 32位整型范围是[0, 2^32) (type为2时填写)

返回结果

 {
     "errcode": 0,
     "errmsg": "ok"
 }

分享设置

用于文件的分享设置。

请求方式:POST(HTTPS)

请求地址: qyapi.weixin.qq.com/cgi-bin/wed…

请求参数

 {
     "userid": "serendipity",
     "fileid": "s.ww028e7efec93353d4.629262066paL_f.629362693V1Jj",
     "auth_scope": 3,
     "auth": 1
 }

参数说明

参数类型是否必须说明
useridstring操作者userid
fileidstring文件fileid
auth_scopeuint32权限范围:1:指定人 2:企业内 3:企业外
authuint32权限信息 普通文档: 1:仅浏览(可下载) 4:仅预览(仅专业版企业可设置);如果不填充此字段为保持原有状态 微文档: 1:仅浏览(可下载) 2:可编辑;如果不填充此字段为保持原有状态

返回结果

 {
     "errcode": 0,
     "errmsg": "ok"
 }

获取分享链接

用于获取文件的分享链接。

请求方式:POST(HTTPS)

请求地址: qyapi.weixin.qq.com/cgi-bin/wed…

请求参数

 {
     "userid": "serendipity",
     "fileid": "s.ww028e7efec93353d4.629262066paL_f.629362693V1Jj"
 }

参数说明

参数类型是否必须说明
useridstring操作者userid
fileidstring文件fileid

返回结果

 {
     "errcode": 0,
     "errmsg": "ok",
     "share_url": "https://drive.weixin.qq.com/s?k=AC8ApgecABEiOnZp4dACAA7AbnADw"
 }

参数说明

参数类型说明
share_urlstring分享文件的链接