开发者文档中心

OpenAPI进入控制台

Web / H5 · 2026-10-31

附件与业务扩展

统一使用访客鉴权,按当前入口权限展示能力。

下载接入包

附件限制

项目限制
图片最大 5 MB
视频 / 文件最大 10 MB;视频限 60 秒
每条消息最多 3 件,总计不超过 12 MB
类型与访问服务端复核 MIME、类型、入口与访客权限

上传并发送

运行前

web/attachments.mjs · 模块文件 · 接入包 0.3.15

  • client 来自已打开的 Web 接待实例,file 来自用户选择的 File/Blob。
  • 仅 Web 示例;小程序上传传本地临时路径,下载返回临时路径,不调用 releaseDownload。
完整代码 · 13 行
web/attachments.mjsJavaScript
// client comes from openSupport(); file is the File/Blob selected by the customer.
export async function uploadAndSend(client, file) {
  const media = await client.upload(file);
  // On an uncertain result inspect pending state; do not upload/send again automatically.
  await client.sendText('请查看这个附件', [media.id]);
  return media;
}

export async function useDownload(client, mediaId, consume) {
  const localUrl = await client.download(mediaId);
  try { return await consume(localUrl); }
  finally { client.releaseDownload(localUrl); }
}
使用流程预览 · 示意图

帮助理解此示例的使用顺序,不执行代码或验证连接。

  1. 准备

    client 来自已打开的 Web 接待实例,file 来自用户选择的 File/Blob。 仅 Web 示例;小程序上传传本地临时路径,下载返回临时路径,不调用 releaseDownload。

  2. 在项目中使用

    web/attachments.mjs · 模块文件

  3. 核对结果

    按用户操作调用 uploadAndSend;useDownload 在消费完成或失败后均释放本地 URL。

预期结果:按用户操作调用 uploadAndSend;useDownload 在消费完成或失败后均释放本地 URL。

扩展方法

方法约束
submitContact({ phone?, email?, consent: true })用户明确同意后提交,不预勾选同意
rate(score, comment?)服务端下发评价邀请后使用,分值按当前 maxScore
searchKnowledge(text?, page?, articleId?)只读取入口绑定的公开知识库
memory() / changeMemory("ignore" | "stop" | "forget")控制记忆,不代表删除企业依法保留的记录

安全下载

下载使用当前访客 Bearer,得到本地 blob URL 或小程序临时文件。不要把令牌加到 URL,不转交第三方域名;Web 在预览后 releaseDownload,销毁也会回收资源。

实现依据 · 仓库内路径
  • sdk/wechat-miniapp/README.md
  • sdk/client-kit/web/client.d.mts

文档描述当前源码能力;不等于你的宿主或生产环境已通过验收。