# 用户系统

讯飞文档使用一种弱用户系统,通过 appUserId 与业务方的用户系统关联。关联成功后,即可使用讯飞文档的 uid 访问讯飞文档的 Open API。部分接口现在支持直接通过 appUserId 访问,但仍需调用 添加用户 接口进行“注册”。

# 添加用户

功能:快速批量添加用户, appUserId 若不存在则自动注册。

路径user/v1/api/bs/users

请求方法POST

请求参数

参数 必须 类型 备注
appUserIdList string[] 业务用户 ID 数组。appUserId 为为 1~32 位以内字符串。

请求示例

点击查看
/**
 * 批量添加用户(仅ID)
 * @param appUserIdList 业务用户 ID 列表
 * @returns 文档用户信息列表
 */
export async function POST(
  appUserIdList: string[]
): Promise<ResponseBody<IflydocsUser[]>> {
  const method = 'POST'
  const path = '/user/v1/api/bs/users'
  const { nonce, timestamp } = genNonce()

  const signature = sign(method, path, nonce, timestamp)
  const Authorization = authorization(signature)

  const headers = {
    Authorization,
    nonce,
    timestamp,
  }

  const data = appUserIdList

  const resp = await axios.post(path, data, {
    headers,
  })

  return resp.data
}

响应示例

点击查看
{
  "code": 0,
  "message": "success",
  "data": [
    {
      "uid": 1657589576829,
      "nickname": "",
      "email": "",
      "mobile": "",
      "telephone": "",
      "realName": "",
      "headPhotoUrl": "",
      "sex": true,
      "birthday": null,
      "appId": "6da37dd3",
      "appUserId": "0.21700556145350514",
      "updateTime": 1666859359000,
      "registrationTime": 1666859359000
    },
    {
      "uid": 1657589576832,
      "nickname": "",
      "email": "",
      "mobile": "",
      "telephone": "",
      "realName": "",
      "headPhotoUrl": "",
      "sex": true,
      "birthday": null,
      "appId": "6da37dd3",
      "appUserId": "0.2557836491649126",
      "updateTime": 1666859359000,
      "registrationTime": 1666859359000
    },
    {
      "uid": 1657589576828,
      "nickname": "",
      "email": "",
      "mobile": "",
      "telephone": "",
      "realName": "",
      "headPhotoUrl": "",
      "sex": true,
      "birthday": null,
      "appId": "6da37dd3",
      "appUserId": "0.4013480277222625",
      "updateTime": 1666859359000,
      "registrationTime": 1666859359000
    },
    {
      "uid": 1657589576824,
      "nickname": "",
      "email": "",
      "mobile": "",
      "telephone": "",
      "realName": "",
      "headPhotoUrl": "",
      "sex": true,
      "birthday": null,
      "appId": "6da37dd3",
      "appUserId": "0.4869312162870787",
      "updateTime": 1666859359000,
      "registrationTime": 1666859359000
    },
    {
      "uid": 1657589576830,
      "nickname": "",
      "email": "",
      "mobile": "",
      "telephone": "",
      "realName": "",
      "headPhotoUrl": "",
      "sex": true,
      "birthday": null,
      "appId": "6da37dd3",
      "appUserId": "0.4901209083830864",
      "updateTime": 1666859359000,
      "registrationTime": 1666859359000
    },
    {
      "uid": 1657589576833,
      "nickname": "",
      "email": "",
      "mobile": "",
      "telephone": "",
      "realName": "",
      "headPhotoUrl": "",
      "sex": true,
      "birthday": null,
      "appId": "6da37dd3",
      "appUserId": "0.5018631485353509",
      "updateTime": 1666859359000,
      "registrationTime": 1666859359000
    },
    {
      "uid": 1657589576825,
      "nickname": "",
      "email": "",
      "mobile": "",
      "telephone": "",
      "realName": "",
      "headPhotoUrl": "",
      "sex": true,
      "birthday": null,
      "appId": "6da37dd3",
      "appUserId": "0.742347831854216",
      "updateTime": 1666859359000,
      "registrationTime": 1666859359000
    },
    {
      "uid": 1657589576827,
      "nickname": "",
      "email": "",
      "mobile": "",
      "telephone": "",
      "realName": "",
      "headPhotoUrl": "",
      "sex": true,
      "birthday": null,
      "appId": "6da37dd3",
      "appUserId": "0.7794854184699629",
      "updateTime": 1666859359000,
      "registrationTime": 1666859359000
    },
    {
      "uid": 1657589576826,
      "nickname": "",
      "email": "",
      "mobile": "",
      "telephone": "",
      "realName": "",
      "headPhotoUrl": "",
      "sex": true,
      "birthday": null,
      "appId": "6da37dd3",
      "appUserId": "0.9043311053816929",
      "updateTime": 1666859359000,
      "registrationTime": 1666859359000
    },
    {
      "uid": 1657589576831,
      "nickname": "",
      "email": "",
      "mobile": "",
      "telephone": "",
      "realName": "",
      "headPhotoUrl": "",
      "sex": true,
      "birthday": null,
      "appId": "6da37dd3",
      "appUserId": "0.9687841771940771",
      "updateTime": 1666859359000,
      "registrationTime": 1666859359000
    }
  ]
}

# 添加用户及详情

功能:批量添加用户,并设置用户详细信息, appUserId 若不存在则自动注册。

路径/user/v1/api/bs/users/more

请求方法POST

请求参数

参数 必须 类型 备注
appUserId string 业务用户 ID。appUserId 为 1~32 位以内字符串。
nickname string 业务用户昵称。nickname 为 1~128 位以内字符串。
email string 电子邮箱。email 为 1~64 位以内字符串。
mobile string 手机号。mobile 为 1~32 位以内字符串。
headPhotoUrl string 头像链接。headPhotoUrl 为 1~256 位以内字符串。

参数示例

[
  {
    "appUserId": "150",
    "nickname": "jack"
  },
  {
    "appUserId": "151",
    "nickname": "tom"
  }
]

请求示例

点击查看
/**
 * 批量添加用户及用户信息
 * @param appUserList 注册用户信息列表
 * @returns 文档用户信息列表
 */
export async function POST(
  appUserList: UserRegisterVm[]
): Promise<ResponseBody<IflydocsUser[]>> {
  const method = 'POST'
  const path = '/user/v1/api/bs/users/more'
  const { nonce, timestamp } = genNonce()

  const signature = sign(method, path, nonce, timestamp)
  const Authorization = authorization(signature)

  const headers = {
    Authorization,
    nonce,
    timestamp,
  }

  const data = appUserList

  const resp = await axios.post(path, data, {
    headers,
  })

  return resp.data
}

响应示例

点击查看
{
  "code": 0,
  "message": "success",
  "data": [
    {
      "uid": 1657589576959,
      "nickname": "0.058530241192200405",
      "email": "",
      "mobile": "",
      "telephone": "",
      "realName": "",
      "headPhotoUrl": "",
      "sex": true,
      "birthday": null,
      "appId": "6da37dd3",
      "appUserId": "0.058530241192200405",
      "updateTime": 1666859361000,
      "registrationTime": 1666859361000
    },
    {
      "uid": 1657589576963,
      "nickname": "0.10152208463504175",
      "email": "",
      "mobile": "",
      "telephone": "",
      "realName": "",
      "headPhotoUrl": "",
      "sex": true,
      "birthday": null,
      "appId": "6da37dd3",
      "appUserId": "0.10152208463504175",
      "updateTime": 1666859361000,
      "registrationTime": 1666859361000
    },
    {
      "uid": 1657589576961,
      "nickname": "0.19842921773953037",
      "email": "",
      "mobile": "",
      "telephone": "",
      "realName": "",
      "headPhotoUrl": "",
      "sex": true,
      "birthday": null,
      "appId": "6da37dd3",
      "appUserId": "0.19842921773953037",
      "updateTime": 1666859361000,
      "registrationTime": 1666859361000
    },
    {
      "uid": 1657589576965,
      "nickname": "0.3427107319588705",
      "email": "",
      "mobile": "",
      "telephone": "",
      "realName": "",
      "headPhotoUrl": "",
      "sex": true,
      "birthday": null,
      "appId": "6da37dd3",
      "appUserId": "0.3427107319588705",
      "updateTime": 1666859361000,
      "registrationTime": 1666859361000
    },
    {
      "uid": 1657589576957,
      "nickname": "0.5573998605464048",
      "email": "",
      "mobile": "",
      "telephone": "",
      "realName": "",
      "headPhotoUrl": "",
      "sex": true,
      "birthday": null,
      "appId": "6da37dd3",
      "appUserId": "0.5573998605464048",
      "updateTime": 1666859361000,
      "registrationTime": 1666859361000
    },
    {
      "uid": 1657589576964,
      "nickname": "0.6978586282360504",
      "email": "",
      "mobile": "",
      "telephone": "",
      "realName": "",
      "headPhotoUrl": "",
      "sex": true,
      "birthday": null,
      "appId": "6da37dd3",
      "appUserId": "0.6978586282360504",
      "updateTime": 1666859361000,
      "registrationTime": 1666859361000
    },
    {
      "uid": 1657589576958,
      "nickname": "0.7483770112204271",
      "email": "",
      "mobile": "",
      "telephone": "",
      "realName": "",
      "headPhotoUrl": "",
      "sex": true,
      "birthday": null,
      "appId": "6da37dd3",
      "appUserId": "0.7483770112204271",
      "updateTime": 1666859361000,
      "registrationTime": 1666859361000
    },
    {
      "uid": 1657589576960,
      "nickname": "0.8138193344791118",
      "email": "",
      "mobile": "",
      "telephone": "",
      "realName": "",
      "headPhotoUrl": "",
      "sex": true,
      "birthday": null,
      "appId": "6da37dd3",
      "appUserId": "0.8138193344791118",
      "updateTime": 1666859361000,
      "registrationTime": 1666859361000
    },
    {
      "uid": 1657589576962,
      "nickname": "0.8265884150769851",
      "email": "",
      "mobile": "",
      "telephone": "",
      "realName": "",
      "headPhotoUrl": "",
      "sex": true,
      "birthday": null,
      "appId": "6da37dd3",
      "appUserId": "0.8265884150769851",
      "updateTime": 1666859361000,
      "registrationTime": 1666859361000
    },
    {
      "uid": 1657589576966,
      "nickname": "0.8975569013765008",
      "email": "",
      "mobile": "",
      "telephone": "",
      "realName": "",
      "headPhotoUrl": "",
      "sex": true,
      "birthday": null,
      "appId": "6da37dd3",
      "appUserId": "0.8975569013765008",
      "updateTime": 1666859361000,
      "registrationTime": 1666859361000
    }
  ]
}

# 修改用户信息

功能:批量修改用户信息。

路径/user/v1/api/bs/users

请求方法PUT

请求参数

参数 必须 类型 备注
appUserId string 业务用户 ID。appUserId 为 1~32 位以内字符串。
nickname string 业务用户昵称。nickname 为 1~128 位以内字符串。
email string 电子邮箱。email 为 1~64 位以内字符串。
mobile string 手机号。mobile 为 1~32 位以内字符串。
headPhotoUrl string 头像链接。headPhotoUrl 为 1~256 位以内字符串。

参数示例

[
  {
    "appUserId": "150",
    "nickname": "jack"
  },
  {
    "appUserId": "151",
    "nickname": "tom"
  }
]

请求示例

点击查看
/**
 * 批量修改用户信息
 * @param appUserList 修改用户信息列表
 * @returns 文档用户信息列表
 */
export async function PUT(
  appUserList: UserRegisterVm[]
): Promise<ResponseBody<IflydocsUser[]>> {
  const method = 'PUT'
  const path = '/user/v1/api/bs/users'
  const { nonce, timestamp } = genNonce()

  const signature = sign(method, path, nonce, timestamp)
  const Authorization = authorization(signature)

  const headers = {
    Authorization,
    nonce,
    timestamp,
  }

  const data = appUserList

  const resp = await axios.put(path, data, {
    headers,
  })
  
  return resp.data
}

响应示例

点击查看
{
  "code": 0,
  "message": "success",
  "data": [
    {
      "uid": 1657589576953,
      "nickname": "我是0.2454122077580294",
      "email": "",
      "mobile": "",
      "telephone": "",
      "realName": "",
      "headPhotoUrl": "",
      "sex": true,
      "birthday": null,
      "appId": "6da37dd3",
      "appUserId": "0.2454122077580294",
      "updateTime": 1666859360000,
      "registrationTime": 1666859360000
    },
    {
      "uid": 1657589576948,
      "nickname": "我是0.24815688588575435",
      "email": "",
      "mobile": "",
      "telephone": "",
      "realName": "",
      "headPhotoUrl": "",
      "sex": true,
      "birthday": null,
      "appId": "6da37dd3",
      "appUserId": "0.24815688588575435",
      "updateTime": 1666859360000,
      "registrationTime": 1666859360000
    },
    {
      "uid": 1657589576949,
      "nickname": "我是0.25347599481722405",
      "email": "",
      "mobile": "",
      "telephone": "",
      "realName": "",
      "headPhotoUrl": "",
      "sex": true,
      "birthday": null,
      "appId": "6da37dd3",
      "appUserId": "0.25347599481722405",
      "updateTime": 1666859360000,
      "registrationTime": 1666859360000
    },
    {
      "uid": 1657589576950,
      "nickname": "我是0.28063991327647364",
      "email": "",
      "mobile": "",
      "telephone": "",
      "realName": "",
      "headPhotoUrl": "",
      "sex": true,
      "birthday": null,
      "appId": "6da37dd3",
      "appUserId": "0.28063991327647364",
      "updateTime": 1666859360000,
      "registrationTime": 1666859360000
    },
    {
      "uid": 1657589576955,
      "nickname": "我是0.2964894963448794",
      "email": "",
      "mobile": "",
      "telephone": "",
      "realName": "",
      "headPhotoUrl": "",
      "sex": true,
      "birthday": null,
      "appId": "6da37dd3",
      "appUserId": "0.2964894963448794",
      "updateTime": 1666859360000,
      "registrationTime": 1666859360000
    },
    {
      "uid": 1657589576956,
      "nickname": "我是0.31955138135733563",
      "email": "",
      "mobile": "",
      "telephone": "",
      "realName": "",
      "headPhotoUrl": "",
      "sex": true,
      "birthday": null,
      "appId": "6da37dd3",
      "appUserId": "0.31955138135733563",
      "updateTime": 1666859360000,
      "registrationTime": 1666859360000
    },
    {
      "uid": 1657589576954,
      "nickname": "我是0.3593984976828657",
      "email": "",
      "mobile": "",
      "telephone": "",
      "realName": "",
      "headPhotoUrl": "",
      "sex": true,
      "birthday": null,
      "appId": "6da37dd3",
      "appUserId": "0.3593984976828657",
      "updateTime": 1666859360000,
      "registrationTime": 1666859360000
    },
    {
      "uid": 1657589576952,
      "nickname": "我是0.49293872255177096",
      "email": "",
      "mobile": "",
      "telephone": "",
      "realName": "",
      "headPhotoUrl": "",
      "sex": true,
      "birthday": null,
      "appId": "6da37dd3",
      "appUserId": "0.49293872255177096",
      "updateTime": 1666859360000,
      "registrationTime": 1666859360000
    },
    {
      "uid": 1657589576951,
      "nickname": "我是0.5617069643773036",
      "email": "",
      "mobile": "",
      "telephone": "",
      "realName": "",
      "headPhotoUrl": "",
      "sex": true,
      "birthday": null,
      "appId": "6da37dd3",
      "appUserId": "0.5617069643773036",
      "updateTime": 1666859360000,
      "registrationTime": 1666859360000
    },
    {
      "uid": 1657589576947,
      "nickname": "我是0.7397981326054033",
      "email": "",
      "mobile": "",
      "telephone": "",
      "realName": "",
      "headPhotoUrl": "",
      "sex": true,
      "birthday": null,
      "appId": "6da37dd3",
      "appUserId": "0.7397981326054033",
      "updateTime": 1666859360000,
      "registrationTime": 1666859360000
    }
  ]
}

# 查询用户

功能:批量查询用户,通过 appUserId 获取 uidappUserId 若不存在则自动忽略。

路径user/v1/api/bs/users

请求方法GET

请求参数

参数 必须 类型 备注
appUserIdList string[] 业务用户 ID 数组。appUserId 为 1~32 位以内字符串。

请求示例

点击查看
/**
 * 批量查询用户信息
 * @param appUserIdList 业务用户 ID 列表
 * @returns 文档用户信息列表
 */
export async function GET(
  appUserIdList: string[]
): Promise<ResponseBody<IflydocsUser[]>> {
  const method = 'GET'
  const path = '/user/v1/api/bs/users'
  const { nonce, timestamp } = genNonce()

  const signature = sign(method, path, nonce, timestamp)
  const Authorization = authorization(signature)

  const headers = {
    Authorization,
    nonce,
    timestamp,
  }

  const resp = await axios.get(path, {
    params: {
      appUserIdList,
    },
    paramsSerializer: (params) => qs.stringify(params),
    headers,
  })

  return resp.data
}

响应示例

点击查看
{
  "code": 0,
  "message": "success",
  "data": [
    {
      "uid": 1657589576938,
      "nickname": "",
      "email": "",
      "mobile": "",
      "telephone": "",
      "realName": "",
      "headPhotoUrl": "",
      "sex": true,
      "birthday": null,
      "appId": "6da37dd3",
      "appUserId": "0.02404679902268958",
      "updateTime": 1666859360000,
      "registrationTime": 1666859360000
    },
    {
      "uid": 1657589576937,
      "nickname": "",
      "email": "",
      "mobile": "",
      "telephone": "",
      "realName": "",
      "headPhotoUrl": "",
      "sex": true,
      "birthday": null,
      "appId": "6da37dd3",
      "appUserId": "0.19287944954994063",
      "updateTime": 1666859360000,
      "registrationTime": 1666859360000
    },
    {
      "uid": 1657589576944,
      "nickname": "",
      "email": "",
      "mobile": "",
      "telephone": "",
      "realName": "",
      "headPhotoUrl": "",
      "sex": true,
      "birthday": null,
      "appId": "6da37dd3",
      "appUserId": "0.2881033956440979",
      "updateTime": 1666859360000,
      "registrationTime": 1666859360000
    },
    {
      "uid": 1657589576946,
      "nickname": "",
      "email": "",
      "mobile": "",
      "telephone": "",
      "realName": "",
      "headPhotoUrl": "",
      "sex": true,
      "birthday": null,
      "appId": "6da37dd3",
      "appUserId": "0.3170184622327952",
      "updateTime": 1666859360000,
      "registrationTime": 1666859360000
    },
    {
      "uid": 1657589576939,
      "nickname": "",
      "email": "",
      "mobile": "",
      "telephone": "",
      "realName": "",
      "headPhotoUrl": "",
      "sex": true,
      "birthday": null,
      "appId": "6da37dd3",
      "appUserId": "0.36259012463742857",
      "updateTime": 1666859360000,
      "registrationTime": 1666859360000
    },
    {
      "uid": 1657589576941,
      "nickname": "",
      "email": "",
      "mobile": "",
      "telephone": "",
      "realName": "",
      "headPhotoUrl": "",
      "sex": true,
      "birthday": null,
      "appId": "6da37dd3",
      "appUserId": "0.5041808309768951",
      "updateTime": 1666859360000,
      "registrationTime": 1666859360000
    },
    {
      "uid": 1657589576945,
      "nickname": "",
      "email": "",
      "mobile": "",
      "telephone": "",
      "realName": "",
      "headPhotoUrl": "",
      "sex": true,
      "birthday": null,
      "appId": "6da37dd3",
      "appUserId": "0.5123757438883221",
      "updateTime": 1666859360000,
      "registrationTime": 1666859360000
    },
    {
      "uid": 1657589576940,
      "nickname": "",
      "email": "",
      "mobile": "",
      "telephone": "",
      "realName": "",
      "headPhotoUrl": "",
      "sex": true,
      "birthday": null,
      "appId": "6da37dd3",
      "appUserId": "0.5309339599302683",
      "updateTime": 1666859360000,
      "registrationTime": 1666859360000
    },
    {
      "uid": 1657589576943,
      "nickname": "",
      "email": "",
      "mobile": "",
      "telephone": "",
      "realName": "",
      "headPhotoUrl": "",
      "sex": true,
      "birthday": null,
      "appId": "6da37dd3",
      "appUserId": "0.5363083760110623",
      "updateTime": 1666859360000,
      "registrationTime": 1666859360000
    },
    {
      "uid": 1657589576942,
      "nickname": "",
      "email": "",
      "mobile": "",
      "telephone": "",
      "realName": "",
      "headPhotoUrl": "",
      "sex": true,
      "birthday": null,
      "appId": "6da37dd3",
      "appUserId": "0.7016381869984458",
      "updateTime": 1666859360000,
      "registrationTime": 1666859360000
    }
  ]
}

# 添加协作者

功能

批量添加协作者,添加之后协作者可正常访问该文件。

如果协作者列表中包含已经拥有协作权限的用户,则返回错误,所有协作者均添加失败。

路径fs/bs/collaborators

请求方法POST

请求参数

参数 必须 类型 备注
appUserIdList String[] 业务用户 ID 数组
fid string 文件 ID
role RoleType 用户角色
inviterAppUserId String 邀请人业务用户 ID

参数示例

{
  "fid": "1tbf",
  "appUserRoleList": [
    {
      "appUserId": "007",
      "role": "editor"
    },
    {
      "appUserId": "008",
      "role": "admin"
    }
  ],
  "inviterAppUserId": "006"
}

请求示例

点击查看
/**
 * 批量添加协作者,添加之后协作者可正常访问该文件。
 * 如果协作者列表中包含已经拥有协作权限的用户,则返回错误。
 * 所有协作者均添加失败。
 * @param appUserIdList 应用用户 ID 列表
 * @param fid 文件 ID
 * @param role 用户角色
 */
export async function POST(
  appUserIdList: string[],
  fid: string,
  role: RoleType,
  inviterAppUserId: string
): Promise<ResponseBody<null>> {
  const method = 'POST'
  const path = '/fs/bs/collaborators'
  const { nonce, timestamp } = genNonce()

  const signature = sign(method, path, nonce, timestamp)
  const Authorization = authorization(signature)

  const headers = {
    Authorization,
    nonce,
    timestamp,
  }

  const data = {
    appUserIdList,
    fid,
    role,
    inviterAppUserId,
  }

  const resp = await axios.post(path, data, {
    headers,
  })

  return resp.data
}

响应示例

点击查看
{
  "code": 0,
  "message": "success",
  "data": null
}

# 添加协作者-细分

功能

批量添加协作者,可不同用户添加不同角色。

如果协作者列表中包含已经拥有协作权限的用户,则返回错误,所有协作者均添加失败。

路径fs/bs/collaborators/more

请求方法POST

请求参数

参数 必须 类型 备注
appUserRoleList UserRegisterVm[] 协作者和角色数组
UserRegisterVm.appUserId String 协作者业务用户 ID
UserRegisterVm.role RoleType 协作者角色
fid string 文件 ID
inviterAppUserId String 邀请人业务用户 ID

参数示例

{
  "fid": "xx",
  "appUserRoleList": [
    {
      "appUserId": "007",
      "role": "editor"
    },
    {
      "appUserId": "008",
      "role": "admin"
    }
  ],
  "inviterAppUserId": "006"
}

请求示例

点击查看
/**
 * 批量添加协作者,添加之后协作者可正常访问该文件。
 * 如果协作者列表中包含已经拥有协作权限的用户,则返回错误。
 * 所有协作者均添加失败。
 * @param appUserIdList 应用用户 ID 列表
 * @param fid 文件 ID
 * @param role 用户角色
 */
export async function POST(
  appUserRoleList: AppUserRoleVm[],
  fid: string,
  inviterAppUserId: string
): Promise<ResponseBody<null>> {
  const method = 'POST'
  const path = '/fs/bs/collaborators/more'
  const { nonce, timestamp } = genNonce()

  const signature = sign(method, path, nonce, timestamp)
  const Authorization = authorization(signature)

  const headers = {
    Authorization,
    nonce,
    timestamp,
  }

  const data = {
    appUserRoleList,
    fid,
    inviterAppUserId,
  }

  const resp = await axios.post(path, data, {
    headers,
  })

  return resp.data
}

响应示例

点击查看
{
  "code": 0,
  "message": "success",
  "data": null
}

# 修改协作者

功能

批量更新协作者。

如果协作者列表中包含没有协作权限的用户,则返回错误。所有协作者均更新失败。

路径fs/bs/collaborators

请求方法PUT

请求参数

参数 必须 类型 备注
appUserIdList string[] 业务用户 ID
fid string 文件 ID
role RoleType 用户角色
inviterAppUserId String 操作人业务用户 ID

请求示例

点击查看
/**
 * 批量更新协作者。
 * 如果协作者列表中包含没有协作权限的用户,则返回错误。
 * 所有协作者均更新失败。
 * @param appUserIdList 应用用户 ID 列表
 * @param fid 文件 ID
 * @param role 用户角色
 */
export async function PUT(
  appUserIdList: string[],
  fid: string,
  role: RoleType,
  inviterAppUserId: String
): Promise<ResponseBody<null>> {
  const method = 'PUT'
  const path = '/fs/bs/collaborators'
  const { nonce, timestamp } = genNonce()

  const signature = sign(method, path, nonce, timestamp)
  const Authorization = authorization(signature)

  const headers = {
    Authorization,
    nonce,
    timestamp,
  }

  const data = {
    appUserIdList,
    fid,
    role,
    inviterAppUserId,
  }

  const resp = await axios.put(path, data, {
    headers,
  })

  return resp.data
}

响应示例

点击查看
```jsonc
//#region post
{
  "code": 0,
  "message": "success",
  "data": null
}
//#endregion post
```

```jsonc
//#region delete
{
  "code": 0,
  "message": "success",
  "data": null
}
//#endregion delete
```

```jsonc
//#region get
{
  "code": 0,
  "message": "success",
  "data": {
    "upper": [],
    "direct": [
      {
        "fid": "10tbW",
        "uid": 1657589576821,
        "role": "owner",
        "modifyTime": "2022-10-27T08:28:06.428+00:00",
        "nickName": "",
        "headPhotoUrl": "",
        "mobile": null,
        "isMine": false,
        "describe": "所有者",
        "appUserId": "dev-docs-001"
      },
      {
        "fid": "10tbW",
        "uid": 1621562447748,
        "role": "reader",
        "modifyTime": "2022-10-27T08:28:05.783+00:00",
        "nickName": "",
        "headPhotoUrl": "",
        "mobile": null,
        "isMine": false,
        "describe": "仅查看",
        "appUserId": "co1"
      },
      {
        "fid": "10tbW",
        "uid": 1621562447957,
        "role": "editor",
        "modifyTime": "2022-10-27T08:28:05.322+00:00",
        "nickName": "",
        "headPhotoUrl": "",
        "mobile": null,
        "isMine": false,
        "describe": "可编辑",
        "appUserId": "co4"
      }
    ]
  }
}
//#endregion get
```

# 修改协作者-细分

功能

批量修改协作者,可不同用户添加不同角色。

如果协作者列表中包含已经拥有协作权限的用户,则返回错误,所有协作者均添加失败。

路径fs/bs/collaborators/more

请求方法PUT

请求参数

参数 必须 类型 备注
appUserRoleList UserRegisterVm[] 协作者和角色数组
UserRegisterVm.appUserId String 协作者业务用户 ID
UserRegisterVm.role RoleType 协作者角色
fid string 文件 ID
inviterAppUserId String 邀请人业务用户 ID

参数示例

{
  "fid": "xx",
  "appUserRoleList": [
    {
      "appUserId": "007",
      "role": "editor"
    },
    {
      "appUserId": "008",
      "role": "admin"
    }
  ],
  "inviterAppUserId": "006"
}

请求示例

点击查看
/**
 * 批量添加协作者,添加之后协作者可正常访问该文件。
 * 如果协作者列表中包含已经拥有协作权限的用户,则返回错误。
 * 所有协作者均添加失败。
 * @param appUserIdList 应用用户 ID 列表
 * @param fid 文件 ID
 * @param role 用户角色
 */
export async function PUT(
  appUserRoleList: AppUserRoleVm[],
  fid: string,
  inviterAppUserId: string
): Promise<ResponseBody<null>> {
  const method = 'PUT'
  const path = '/fs/bs/collaborators/more'
  const { nonce, timestamp } = genNonce()

  const signature = sign(method, path, nonce, timestamp)
  const Authorization = authorization(signature)

  const headers = {
    Authorization,
    nonce,
    timestamp,
  }

  const data = {
    appUserRoleList,
    fid,
    inviterAppUserId,
  }

  const resp = await axios.put(path, data, {
    headers,
  })

  return resp.data
}

响应示例

点击查看
{
  "code": 0,
  "message": "success",
  "data": null
}

# 移除协作者

功能

批量移除协作者。

如果用户不拥有协作权限,则忽略,其他用户正常处理。

路径fs/bs/collaborators

请求方法DELETE

请求参数

参数 必须 类型 备注
appUserIdList string[] 业务用户 ID
fid string 文件 ID
inviterAppUserId String 操作人业务用户 ID,不为 null 时校验操作人权限

请求示例

点击查看
/**
 * 批量移除协作者
 * 如果用户不拥有协作权限,则忽略,其他用户正常处理。
 * @param appUserIdList 应用用户 ID 列表
 * @param fid 文件 ID
 */
export async function DELETE(
  appUserIdList: string[],
  fid: string
): Promise<ResponseBody<null>> {
  const method = 'DELETE'
  const path = '/fs/bs/collaborators'
  const { nonce, timestamp } = genNonce()

  const signature = sign(method, path, nonce, timestamp)
  const Authorization = authorization(signature)

  const headers = {
    Authorization,
    nonce,
    timestamp,
  }

  const params = {
    appUserIdList,
    fid,
  }

  const resp = await axios.delete(path, {
    headers,
    // NOTE: DELETE 请求通过 body 传参有潜在风险
    // 参考:https://stackoverflow.com/questions/299628/is-an-entity-body-allowed-for-an-http-delete-request
    data: params,
    // params,
    // paramsSerializer: (params) => qs.stringify(params),
  })

  return resp.data
}

响应示例

点击查看
{
  "code": 0,
  "message": "success",
  "data": null
}

# 查询协作者

功能

批量获取文件协作者。

路径fs/bs/collaborators

请求方法GET

请求参数

参数 必须 类型 备注
fid string 文件 ID

请求示例

点击查看
/**
 * 获取指定文件的所有协作者
 * 包含继承自上级的协作者和本级直接授权的协作者
 * @param fid 文件 ID
 * @returns 协作者列表
 */
export async function GET(
  fid: string
): Promise<ResponseBody<IflydocsCollaborators>> {
  const method = 'GET'
  const path = '/fs/bs/collaborators'
  const { nonce, timestamp } = genNonce()

  const signature = sign(method, path, nonce, timestamp)
  const Authorization = authorization(signature)

  const headers = {
    Authorization,
    nonce,
    timestamp,
  }

  const params = {
    fid,
  }

  const resp = await axios.get(path, {
    headers,
    params,
    paramsSerializer: (params) => qs.stringify(params),
  })

  return resp.data
}

响应示例

点击查看
{
  "code": 0,
  "message": "success",
  "data": {
    "upper": [],
    "direct": [
      {
        "fid": "10tbW",
        "uid": 1657589576821,
        "role": "owner",
        "modifyTime": "2022-10-27T08:28:06.428+00:00",
        "nickName": "",
        "headPhotoUrl": "",
        "mobile": null,
        "isMine": false,
        "describe": "所有者",
        "appUserId": "dev-docs-001"
      },
      {
        "fid": "10tbW",
        "uid": 1621562447748,
        "role": "reader",
        "modifyTime": "2022-10-27T08:28:05.783+00:00",
        "nickName": "",
        "headPhotoUrl": "",
        "mobile": null,
        "isMine": false,
        "describe": "仅查看",
        "appUserId": "co1"
      },
      {
        "fid": "10tbW",
        "uid": 1621562447957,
        "role": "editor",
        "modifyTime": "2022-10-27T08:28:05.322+00:00",
        "nickName": "",
        "headPhotoUrl": "",
        "mobile": null,
        "isMine": false,
        "describe": "可编辑",
        "appUserId": "co4"
      }
    ]
  }
}

# 获取用户令牌-直连

功能:账号授权,appUserId 若不存在则自动注册。

路径user/v1/api/auth/token

请求方法POST

请求参数

参数 必须 类型 备注
appId string 应用 ID
appSecret string 应用秘钥
appUerId string 业务用户 ID

注意

由于参数中携带了应用秘钥的明文,任何情况下都不能从客户端发起这个请求!

如果确实需要从客户端获取用户令牌,请使用 签名方式

请求示例

点击查看
/**
 * 以服务直连的方式获取授权
 * 注意:请勿直接通过客户端请求,这会导致秘钥泄露!
 * @param appId 应用 ID
 * @param appSecret 应用秘钥
 * @param appUserId 业务用户 ID
 * @returns 授权令牌 JWT
 */
export default async function POST(
  appId: string,
  appSecret: string,
  appUserId: string
): Promise<ResponseBody<IflydocsJWT>> {
  const resp = await axios.post('user/v1/api/auth/token', {
    appId,
    appSecret,
    appUserId,
  })

  return resp.data
}

响应示例

点击查看
{
  "code": 0,
  "message": "正常",
  "data": {
    "accessToken": "eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJjIjoiNmRhMzdkZDMiLCJzIjoxNjY2ODU5MzU4Njg2LCJ0IjoiQSIsInUiOiIxNjU3NTg5NTc2ODIxIiwiaXNzIjoiYXV0aDAiLCJleHAiOjE2NjY5NDU3NTh9.MIxlO-vwy4VhPGgyS94HBZ1NlFnzCkiHPKcW8TlyXZE",
    "refreshToken": "eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJjIjoiNmRhMzdkZDMiLCJzIjoxNjY2ODU5MzU4Njg0LCJ0IjoiUiIsInUiOiIxNjU3NTg5NTc2ODIxIiwiaXNzIjoiYXV0aDAiLCJleHAiOjE2Njk0NTEzNTh9.2s_7GF4Y_9Um0vy76k3e7lrNAOrQa8BYPlwu8Ip246E",
    "expiresIn": 86399,
    "expireTime": 1666945758686,
    "uid": 1657589576821,
    "appId": "6da37dd3",
    "appUserId": "dev-docs-001"
  }
}

# 获取用户令牌-签名

功能:账号授权,appUserId 若不存在则自动注册。

路径user/v1/api/auth/signAuth

请求方法POST

请求参数

参数 必须 类型 备注
appId string 应用 ID
appUerId string 业务用户 ID
ts string 秒时间戳
sign string 签名,请参考下文示例代码

签名示例

提示

由于通过签名的方式进行参数校验,你可以放心地在客户端发起请求。

请求示例

点击查看
/**
 * 通过签名方式获取授权
 * 支持客户端请求,但需要妥善保管秘钥。
 * @param appId 应用 ID
 * @param appUserId 业务用户 ID
 * @param ts 秒时间戳
 * @param sign 签名
 * @returns 授权令牌 JWT
 */
export async function POST(
  appId: string,
  appUserId: string,
  ts: string,
  sign: string
): Promise<ResponseBody<IflydocsJWT>> {
  const resp = await axios.post('user/v1/api/auth/signAuth', {
    appId,
    appUserId,
    ts,
    sign,
  })

  return resp.data
}

响应示例

点击查看
{
  "code": 0,
  "message": "正常",
  "data": {
    "accessToken": "eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJjIjoiNmRhMzdkZDMiLCJzIjoxNjY2ODU5MzU3MzM5LCJ0IjoiQSIsInUiOiIxNjU3NTg5NTc2ODIxIiwiaXNzIjoiYXV0aDAiLCJleHAiOjE2NjY5NDU3NTd9.Mn5I01cgP_oqZ4_82Syl9PKvG8I_zYltOdezOQStioc",
    "refreshToken": "eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJjIjoiNmRhMzdkZDMiLCJzIjoxNjY2ODU5MzU3MzM3LCJ0IjoiUiIsInUiOiIxNjU3NTg5NTc2ODIxIiwiaXNzIjoiYXV0aDAiLCJleHAiOjE2Njk0NTEzNTd9.zhzJJa-TmSjWu8ajvKLC3TQEVF2qQtULpKD9hkHUloU",
    "expiresIn": 86399,
    "expireTime": 1666945757339,
    "uid": 1657589576821,
    "appId": "6da37dd3",
    "appUserId": "dev-docs-001"
  }
}