""" 企微内嵌 H5 成功后自动关页。 本文件职责:给附件上传成功、选线路成功页一段共用脚本。 手机端只调一次 WeixinJSBridge.closeWindow,关掉当前 H5 后留在询价对话里。 再调 ww/wx/window.close 会把询价小助手整个退出,回到企业微信首页。 电脑企微没有这套桥,加载 wecom-jssdk、用 /inquiry-form/jsapi-signature 注册后再关一次。 失败、过期页不要挂这段。 副作用:只产出 HTML 片段;关窗签名走浏览器短请求,不占智能体请求线程做慢活。 """ from __future__ import annotations from html import escape from agent.config import get_settings # 签名完成后再稍停,让销售看见「已成功」。 _CLOSE_DELAY_MS = 400 def wecom_auto_close_script() -> str: """ 成功页脚:加载企微 JS-SDK,register 后关掉当前 H5 窗口。 线程:浏览器端执行。签名接口与复制页共用,ticket 已缓存在 Redis。 为何这样写:上一版只调 WeixinJSBridge,电脑端企微关不掉,会停在成功页。 """ settings = get_settings() corp = escape((settings.wecom_corp_id or "").strip(), quote=True) agent = escape(str(settings.wecom_agent_id or "1000010").strip(), quote=True) delay = _CLOSE_DELAY_MS return f""" """