{"templateId":"markdown","sharedDataIds":{"sidebar":"sidebar-@l10n/zh/sidebars.yaml"},"props":{"metadata":{"markdoc":{"tagList":[]},"type":"markdown"},"seo":{"title":"异步操作"},"dynamicMarkdocComponents":[],"compilationErrors":[],"ast":{"$$mdtype":"Tag","name":"article","attributes":{},"children":[{"$$mdtype":"Tag","name":"Heading","attributes":{"level":1,"id":"异步操作","__idx":0},"children":["异步操作"]},{"$$mdtype":"Tag","name":"p","attributes":{},"children":["部分 MoreLogin 操作会在底层浏览器、云手机、文件、应用或 RPA 执行到达最终状态之前就接受请求。提交成功的响应只代表请求已被接受，并不总是代表目标状态已经达成。"]},{"$$mdtype":"Tag","name":"Heading","attributes":{"level":2,"id":"客户端状态模型","__idx":1},"children":["客户端状态模型"]},{"$$mdtype":"Tag","name":"div","attributes":{"className":"md-table-wrapper"},"children":[{"$$mdtype":"Tag","name":"table","attributes":{"className":"md"},"children":[{"$$mdtype":"Tag","name":"thead","attributes":{},"children":[{"$$mdtype":"Tag","name":"tr","attributes":{},"children":[{"$$mdtype":"Tag","name":"th","attributes":{"data-label":"状态"},"children":["状态"]},{"$$mdtype":"Tag","name":"th","attributes":{"data-label":"含义"},"children":["含义"]},{"$$mdtype":"Tag","name":"th","attributes":{"data-label":"客户端应做什么"},"children":["客户端应做什么"]}]}]},{"$$mdtype":"Tag","name":"tbody","attributes":{},"children":[{"$$mdtype":"Tag","name":"tr","attributes":{},"children":[{"$$mdtype":"Tag","name":"td","attributes":{},"children":["已提交"]},{"$$mdtype":"Tag","name":"td","attributes":{},"children":["接口已接受命令或已创建任务"]},{"$$mdtype":"Tag","name":"td","attributes":{},"children":["保存返回的 ID 与 ",{"$$mdtype":"Tag","name":"code","attributes":{},"children":["requestId"]},"；不要立刻重复提交同一次写操作"]}]},{"$$mdtype":"Tag","name":"tr","attributes":{},"children":[{"$$mdtype":"Tag","name":"td","attributes":{},"children":["等待中或执行中"]},{"$$mdtype":"Tag","name":"td","attributes":{},"children":["下游操作仍在推进"]},{"$$mdtype":"Tag","name":"td","attributes":{},"children":["以递增间隔轮询文档指定的状态/结果接口"]}]},{"$$mdtype":"Tag","name":"tr","attributes":{},"children":[{"$$mdtype":"Tag","name":"td","attributes":{},"children":["已成功"]},{"$$mdtype":"Tag","name":"td","attributes":{},"children":["目标资源或任务到达成功终态"]},{"$$mdtype":"Tag","name":"td","attributes":{},"children":["停止轮询，继续后续流程"]}]},{"$$mdtype":"Tag","name":"tr","attributes":{},"children":[{"$$mdtype":"Tag","name":"td","attributes":{},"children":["已失败"]},{"$$mdtype":"Tag","name":"td","attributes":{},"children":["状态/结果接口报告失败或终态业务错误"]},{"$$mdtype":"Tag","name":"td","attributes":{},"children":["停止自动重试；保留 ID、失败详情与 ",{"$$mdtype":"Tag","name":"code","attributes":{},"children":["requestId"]}]}]},{"$$mdtype":"Tag","name":"tr","attributes":{},"children":[{"$$mdtype":"Tag","name":"td","attributes":{},"children":["结果未知"]},{"$$mdtype":"Tag","name":"td","attributes":{},"children":["写操作超时，或连接断开且没有可用响应"]},{"$$mdtype":"Tag","name":"td","attributes":{},"children":["先查询资源/任务当前状态，再决定是否重试"]}]}]}]}]},{"$$mdtype":"Tag","name":"Heading","attributes":{"level":2,"id":"轮询规则","__idx":2},"children":["轮询规则"]},{"$$mdtype":"Tag","name":"ul","attributes":{},"children":[{"$$mdtype":"Tag","name":"li","attributes":{},"children":["从约 1 秒开始，逐步增加到 2、4、8 秒，上限 15–30 秒。"]},{"$$mdtype":"Tag","name":"li","attributes":{},"children":["加入抖动，避免并发客户端在同一瞬间轮询。"]},{"$$mdtype":"Tag","name":"li","attributes":{},"children":["到达文档定义的终态即停止；不要无限轮询。"]},{"$$mdtype":"Tag","name":"li","attributes":{},"children":["只有接口明确说明该行为时，才把 ",{"$$mdtype":"Tag","name":"code","attributes":{},"children":["data: null"]}," 当作等待中。"]},{"$$mdtype":"Tag","name":"li","attributes":{},"children":["写操作的传输超时并不证明失败。"]}]},{"$$mdtype":"Tag","name":"Heading","attributes":{"level":2,"id":"已记录的工作流","__idx":3},"children":["已记录的工作流"]},{"$$mdtype":"Tag","name":"div","attributes":{"className":"md-table-wrapper"},"children":[{"$$mdtype":"Tag","name":"table","attributes":{"className":"md"},"children":[{"$$mdtype":"Tag","name":"thead","attributes":{},"children":[{"$$mdtype":"Tag","name":"tr","attributes":{},"children":[{"$$mdtype":"Tag","name":"th","attributes":{"data-label":"工作流"},"children":["工作流"]},{"$$mdtype":"Tag","name":"th","attributes":{"data-label":"提交操作"},"children":["提交操作"]},{"$$mdtype":"Tag","name":"th","attributes":{"data-label":"观察操作"},"children":["观察操作"]},{"$$mdtype":"Tag","name":"th","attributes":{"data-label":"终态"},"children":["终态"]}]}]},{"$$mdtype":"Tag","name":"tbody","attributes":{},"children":[{"$$mdtype":"Tag","name":"tr","attributes":{},"children":[{"$$mdtype":"Tag","name":"td","attributes":{},"children":["云浏览器开启/关闭"]},{"$$mdtype":"Tag","name":"td","attributes":{},"children":[{"$$mdtype":"Tag","name":"code","attributes":{},"children":["POST /cloudbrowser/start"]}," 或 ",{"$$mdtype":"Tag","name":"code","attributes":{},"children":["/cloudbrowser/stop"]}]},{"$$mdtype":"Tag","name":"td","attributes":{},"children":[{"$$mdtype":"Tag","name":"code","attributes":{},"children":["POST /cloudbrowser/page"]}]},{"$$mdtype":"Tag","name":"td","attributes":{},"children":["运行实例达到预期状态，或关闭后消失"]}]},{"$$mdtype":"Tag","name":"tr","attributes":{},"children":[{"$$mdtype":"Tag","name":"td","attributes":{},"children":["云手机开关机"]},{"$$mdtype":"Tag","name":"td","attributes":{},"children":[{"$$mdtype":"Tag","name":"code","attributes":{},"children":["POST /cloudphone/powerOn"]}," 或 ",{"$$mdtype":"Tag","name":"code","attributes":{},"children":["/cloudphone/powerOff"]}]},{"$$mdtype":"Tag","name":"td","attributes":{},"children":[{"$$mdtype":"Tag","name":"code","attributes":{},"children":["POST /cloudphone/page"]}]},{"$$mdtype":"Tag","name":"td","attributes":{},"children":[{"$$mdtype":"Tag","name":"code","attributes":{},"children":["envStatus=4"]}," 已开机或 ",{"$$mdtype":"Tag","name":"code","attributes":{},"children":["envStatus=2"]}," 已关机；",{"$$mdtype":"Tag","name":"code","attributes":{},"children":["1"]}," 表示创建失败"]}]},{"$$mdtype":"Tag","name":"tr","attributes":{},"children":[{"$$mdtype":"Tag","name":"td","attributes":{},"children":["云手机文件上传"]},{"$$mdtype":"Tag","name":"td","attributes":{},"children":["上传到签名 URL，然后 ",{"$$mdtype":"Tag","name":"code","attributes":{},"children":["POST /cloudphone/uploadFile"]}]},{"$$mdtype":"Tag","name":"td","attributes":{},"children":[{"$$mdtype":"Tag","name":"code","attributes":{},"children":["POST /cloudphone/uploadFileResult"]}]},{"$$mdtype":"Tag","name":"td","attributes":{},"children":[{"$$mdtype":"Tag","name":"code","attributes":{},"children":["status=1"]}," 成功或 ",{"$$mdtype":"Tag","name":"code","attributes":{},"children":["status=2"]}," 失败；",{"$$mdtype":"Tag","name":"code","attributes":{},"children":["data: null"]}," 与 ",{"$$mdtype":"Tag","name":"code","attributes":{},"children":["status=0"]}," 表示等待中"]}]},{"$$mdtype":"Tag","name":"tr","attributes":{},"children":[{"$$mdtype":"Tag","name":"td","attributes":{},"children":["云手机下载"]},{"$$mdtype":"Tag","name":"td","attributes":{},"children":[{"$$mdtype":"Tag","name":"code","attributes":{},"children":["POST /cloudphone/download"]}]},{"$$mdtype":"Tag","name":"td","attributes":{},"children":[{"$$mdtype":"Tag","name":"code","attributes":{},"children":["POST /cloudphone/download/result"]}]},{"$$mdtype":"Tag","name":"td","attributes":{},"children":[{"$$mdtype":"Tag","name":"code","attributes":{},"children":["status=20"]}," 成功、",{"$$mdtype":"Tag","name":"code","attributes":{},"children":["30"]}," 失败、",{"$$mdtype":"Tag","name":"code","attributes":{},"children":["40"]}," 已取消；",{"$$mdtype":"Tag","name":"code","attributes":{},"children":["10"]}," 表示执行中"]}]},{"$$mdtype":"Tag","name":"tr","attributes":{},"children":[{"$$mdtype":"Tag","name":"td","attributes":{},"children":["应用安装"]},{"$$mdtype":"Tag","name":"td","attributes":{},"children":[{"$$mdtype":"Tag","name":"code","attributes":{},"children":["POST /cloudphone/app/install"]}]},{"$$mdtype":"Tag","name":"td","attributes":{},"children":[{"$$mdtype":"Tag","name":"code","attributes":{},"children":["POST /cloudphone/app/installedList"]}]},{"$$mdtype":"Tag","name":"td","attributes":{},"children":["目标包名出现在已安装应用列表中"]}]},{"$$mdtype":"Tag","name":"tr","attributes":{},"children":[{"$$mdtype":"Tag","name":"td","attributes":{},"children":["RPA 计划/执行"]},{"$$mdtype":"Tag","name":"td","attributes":{},"children":[{"$$mdtype":"Tag","name":"code","attributes":{},"children":["POST /cloudphone/rpa/task/save"]}," 或 ",{"$$mdtype":"Tag","name":"code","attributes":{},"children":["/onceTask/save"]}]},{"$$mdtype":"Tag","name":"td","attributes":{},"children":[{"$$mdtype":"Tag","name":"code","attributes":{},"children":["POST /cloudphone/rpa/task/page"]},"、",{"$$mdtype":"Tag","name":"code","attributes":{},"children":["/subTask/page"]}," 与 ",{"$$mdtype":"Tag","name":"code","attributes":{},"children":["/subTask/detail/{id}"]}]},{"$$mdtype":"Tag","name":"td","attributes":{},"children":[{"$$mdtype":"Tag","name":"code","attributes":{},"children":["taskState=2"]}," 已完成或 ",{"$$mdtype":"Tag","name":"code","attributes":{},"children":["3"]}," 已取消；再看 ",{"$$mdtype":"Tag","name":"code","attributes":{},"children":["handleResult"]},"（",{"$$mdtype":"Tag","name":"code","attributes":{},"children":["0"]}," 失败，",{"$$mdtype":"Tag","name":"code","attributes":{},"children":["1"]}," 成功）"]}]},{"$$mdtype":"Tag","name":"tr","attributes":{},"children":[{"$$mdtype":"Tag","name":"td","attributes":{},"children":["直播"]},{"$$mdtype":"Tag","name":"td","attributes":{},"children":[{"$$mdtype":"Tag","name":"code","attributes":{},"children":["POST /cloudphone/live/start"]}," 或 ",{"$$mdtype":"Tag","name":"code","attributes":{},"children":["/live/end"]}]},{"$$mdtype":"Tag","name":"td","attributes":{},"children":[{"$$mdtype":"Tag","name":"code","attributes":{},"children":["POST /cloudphone/live/status"]}]},{"$$mdtype":"Tag","name":"td","attributes":{},"children":["状态确认已开始或已停止推流"]}]},{"$$mdtype":"Tag","name":"tr","attributes":{},"children":[{"$$mdtype":"Tag","name":"td","attributes":{},"children":["云存储上传"]},{"$$mdtype":"Tag","name":"td","attributes":{},"children":[{"$$mdtype":"Tag","name":"code","attributes":{},"children":["POST /cloudstorage/upload/init"]},"，随后对对象存储发 ",{"$$mdtype":"Tag","name":"code","attributes":{},"children":["PUT"]}]},{"$$mdtype":"Tag","name":"td","attributes":{},"children":["全部必需 PUT 成功后调用 ",{"$$mdtype":"Tag","name":"code","attributes":{},"children":["POST /cloudstorage/upload/complete"]}]},{"$$mdtype":"Tag","name":"td","attributes":{},"children":["完成请求返回成功；对象上传成功前绝不要调用 complete"]}]}]}]}]},{"$$mdtype":"Tag","name":"p","attributes":{},"children":["Local API 的对应接口在文档标注处使用 ",{"$$mdtype":"Tag","name":"code","attributes":{},"children":["/api"]}," 前缀。逐个操作的指引见",{"$$mdtype":"Tag","name":"MarkdownLink","attributes":{"href":"/zh/api-reference/getting-started/endpoint-behavior"},"children":["端点重试与完成矩阵"]},"。"]},{"$$mdtype":"Tag","name":"Heading","attributes":{"level":2,"id":"超时恢复示例","__idx":4},"children":["超时恢复示例"]},{"$$mdtype":"Tag","name":"CodeBlock","attributes":{"data-language":"python","header":{"controls":{"copy":{}}},"source":"try:\n    submit_operation()\nexcept TimeoutError:\n    # The write may already have succeeded.\n    current = query_current_state()\n    if current.is_terminal_success:\n        pass\n    elif current.is_pending:\n        poll_until_terminal()\n    else:\n        decide_whether_retry_is_safe(current)\n","lang":"python"},"children":[]},{"$$mdtype":"Tag","name":"p","attributes":{},"children":["公开接口目前没有定义通用的幂等键请求头。因此资源 ID、任务 ID、状态查询与 ",{"$$mdtype":"Tag","name":"code","attributes":{},"children":["requestId"]}," 是安全恢复的关键。"]}]},"headings":[{"value":"异步操作","id":"异步操作","depth":1},{"value":"客户端状态模型","id":"客户端状态模型","depth":2},{"value":"轮询规则","id":"轮询规则","depth":2},{"value":"已记录的工作流","id":"已记录的工作流","depth":2},{"value":"超时恢复示例","id":"超时恢复示例","depth":2}],"frontmatter":{"seo":{"title":"异步操作"}},"lastModified":"2026-09-03T05:46:01.000Z","pagePropGetterError":{"message":"","name":""}},"slug":"/zh/api-reference/getting-started/async-operations","userData":{"isAuthenticated":false,"teams":["anonymous"]},"isPublic":true}