| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970 |
- <!DOCTYPE html>
- <html lang="zh-CN">
- <head>
- <meta charset="utf-8">
- <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no, viewport-fit=cover">
- <meta name="format-detection" content="telephone=no">
- <title>与U宝对话</title>
- <meta property="og:title" content="和U宝的对话">
- <meta property="og:description" content="点击查看对话内容">
- <meta property="og:site_name" content="U店在哪">
- <meta name="application-name" content="U店在哪">
- <link rel="icon" type="image/png" href="https://alien-volume.oss-cn-beijing.aliyuncs.com/icon/ubao.png">
- <link rel="apple-touch-icon" href="https://alien-volume.oss-cn-beijing.aliyuncs.com/icon/ubao.png">
- <style>
- :root {
- --bg: #f4f6fb;
- --text: #151515;
- --muted: #aaaaaa;
- --orange: #f47d1f;
- --safe-bottom: env(safe-area-inset-bottom, 0px);
- }
- * {
- margin: 0;
- padding: 0;
- box-sizing: border-box;
- }
- html {
- -webkit-tap-highlight-color: transparent;
- }
- body {
- font-family: -apple-system, BlinkMacSystemFont, "PingFang SC", "Microsoft YaHei", sans-serif;
- background: var(--bg);
- color: var(--text);
- min-height: 100vh;
- padding-bottom: calc(92px + var(--safe-bottom));
- }
- .hero {
- padding: 16px 15px 0;
- }
- .hero__title {
- font-size: 20px;
- font-weight: 700;
- line-height: 1.4;
- word-break: break-word;
- }
- .hero__meta {
- margin-top: 8px;
- font-size: 12px;
- color: var(--muted);
- line-height: 1.4;
- }
- .hero__divider {
- margin-top: 14px;
- height: 1px;
- background: rgba(170, 170, 170, 0.25);
- }
- .conversation {
- padding: 14px 15px 0;
- }
- .row {
- display: flex;
- margin-bottom: 12px;
- }
- .row--user {
- justify-content: flex-end;
- }
- .row--ai {
- justify-content: flex-start;
- }
- .user-bubble {
- position: relative;
- max-width: 78%;
- padding: 10px 12px;
- background: var(--orange);
- border-radius: 6px 6px 2px 6px;
- color: #fff;
- font-size: 15px;
- font-weight: 500;
- line-height: 1.5;
- white-space: pre-wrap;
- word-break: break-word;
- }
- .user-bubble::after {
- content: "";
- position: absolute;
- right: -5px;
- bottom: 6px;
- width: 0;
- height: 0;
- border-style: solid;
- border-width: 5px 0 5px 6px;
- border-color: transparent transparent transparent var(--orange);
- }
- .ai-card {
- width: 100%;
- padding: 14px 13px;
- background: #fff;
- border-radius: 8px;
- box-shadow: 0 1px 6px rgba(0, 0, 0, 0.04);
- }
- .ai-card__text {
- font-size: 14px;
- line-height: 1.65;
- white-space: pre-wrap;
- word-break: break-word;
- text-align: left;
- }
- .fallback-card {
- margin: 14px 15px 0;
- padding: 14px 13px;
- background: #fff;
- border-radius: 8px;
- box-shadow: 0 1px 6px rgba(0, 0, 0, 0.04);
- }
- .fallback-card .ai-card__text {
- font-size: 14px;
- line-height: 1.65;
- white-space: pre-wrap;
- word-break: break-word;
- text-align: left;
- }
- .empty {
- padding: 48px 20px;
- text-align: center;
- color: var(--muted);
- font-size: 14px;
- }
- .footer {
- position: fixed;
- left: 0;
- right: 0;
- bottom: 0;
- z-index: 20;
- padding: 10px 15px calc(10px + var(--safe-bottom));
- background: linear-gradient(180deg, rgba(244, 246, 251, 0) 0%, #f4f6fb 36%);
- pointer-events: none;
- }
- .footer__dock {
- display: flex;
- justify-content: center;
- width: 100%;
- pointer-events: auto;
- }
- .footer__btn-slot {
- position: relative;
- width: 50%;
- height: 48px;
- }
- .continue-btn {
- display: flex;
- align-items: center;
- justify-content: center;
- width: 100%;
- height: 48px;
- margin: 0;
- padding: 0;
- border: none;
- border-radius: 999px;
- background: linear-gradient(90deg, #ffb84c 0%, #ff6b3e 100%);
- box-shadow: 0 4px 16px rgba(255, 107, 62, 0.32);
- touch-action: manipulation;
- -webkit-tap-highlight-color: transparent;
- }
- .continue-btn__label {
- display: block;
- height: 20px;
- width: auto;
- max-width: 90%;
- pointer-events: none;
- -webkit-user-drag: none;
- }
- #launch-btn {
- display: none;
- position: absolute;
- left: 0;
- top: 0;
- width: 100%;
- height: 100%;
- min-height: 48px;
- border-radius: 999px;
- overflow: hidden;
- }
- body.is-wechat.wx-jssdk-ready #launch-btn {
- display: block;
- }
- body.is-wechat.wx-jssdk-ready #btnContinue {
- visibility: hidden;
- pointer-events: none;
- }
- #openAppToast {
- display: none;
- position: fixed;
- left: 16px;
- right: 16px;
- bottom: calc(72px + var(--safe-bottom));
- z-index: 10001;
- padding: 10px 14px;
- font-size: 13px;
- line-height: 1.45;
- color: #fff;
- text-align: center;
- background: rgba(0, 0, 0, 0.78);
- border-radius: 8px;
- pointer-events: none;
- word-break: break-all;
- }
- </style>
- </head>
- <body>
- <main id="main">
- <div class="empty">对话内容加载中…</div>
- </main>
- <div id="openAppToast" role="status" aria-live="polite"></div>
- <footer class="footer">
- <div class="footer__dock">
- <div class="footer__btn-slot">
- <button type="button" class="continue-btn" id="btnContinue" aria-label="和U宝继续聊">
- <img class="continue-btn__label" src="images/uCharts.png" alt="和U宝继续聊" decoding="async">
- </button>
- <wx-open-launch-app id="launch-btn" appid="wxf5f1efe3a9f5012e" extinfo="">
- <script type="text/wxtag-template">
- <style>
- .wx-open-app-btn {
- display: flex;
- align-items: center;
- justify-content: center;
- width: 100%;
- height: 48px;
- margin: 0;
- padding: 0;
- border: none;
- border-radius: 999px;
- background: linear-gradient(90deg, #ffb84c 0%, #ff6b3e 100%);
- box-shadow: 0 4px 16px rgba(255, 107, 62, 0.32);
- cursor: pointer;
- -webkit-tap-highlight-color: transparent;
- box-sizing: border-box;
- }
- .wx-open-app-btn__label {
- display: block;
- height: 20px;
- width: auto;
- max-width: 90%;
- pointer-events: none;
- }
- </style>
- <button class="wx-open-app-btn" aria-label="和U宝继续聊">
- <img class="wx-open-app-btn__label" src="https://test.ailien.shop/h5/HBuilderProjects/images/uCharts.png" alt="和U宝继续聊" decoding="async">
- </button>
- </script>
- </wx-open-launch-app>
- </div>
- </div>
- </footer>
- <script src="https://res.wx.qq.com/open/js/jweixin-1.6.0.js"></script>
- <script>
- (function () {
- "use strict";
- var API_BASE = "https://test.ailien.shop/alienStore";
- var WECHAT_MP_APP_ID = "wx412792c77f47babd";
- var WECHAT_OPEN_APP_ID = "wxf5f1efe3a9f5012e";
- var WECHAT_GET_WX_CONFIG_PATH = "/wx/getWxConfig";
- var H5_PAGE_BASE_FALLBACK = "https://test.ailien.shop/h5/HBuilderProjects/";
- var WX_GET_CONFIG_SIGN_URL = H5_PAGE_BASE_FALLBACK + "shareAiConsult.html";
- var WECHAT_JS_SAFE_HOSTS = ["uat.ailien.shop", "test.ailien.shop"];
- var APP_ANDROID_PACKAGE = "com.alien.Udianzaizhe";
- var APP_IOS_URL_SCHEME = "shopro://";
- var APP_UNI_AI_PATH = "pages/aiSearchResult/index";
- var sharePayloadCache = null;
- var weChatJssdkConfigured = false;
- var wxConfigSignRetriedBaseUrl = false;
- var wxInitLastError = "";
- var wxJssdkInitPromise = null;
- function escHtml(s) {
- return String(s || "")
- .replace(/&/g, "&")
- .replace(/</g, "<")
- .replace(/>/g, ">")
- .replace(/"/g, """);
- }
- function q(name) {
- try {
- var v = new URLSearchParams(location.search || "").get(name);
- return v == null ? "" : String(v);
- } catch (e) {
- return "";
- }
- }
- function getQueryParam(name) {
- var m = new RegExp("[?&]" + name + "=([^&]*)").exec(window.location.search);
- if (!m) return "";
- try {
- return decodeURIComponent(m[1].replace(/\+/g, " "));
- } catch (e) {
- return "";
- }
- }
- function parsePayload() {
- var raw = getQueryParam("payload");
- if (!raw) return null;
- try {
- return JSON.parse(raw);
- } catch (e) {
- return null;
- }
- }
- function getFirstUserQuestion(messages) {
- var list = Array.isArray(messages) ? messages : [];
- for (var i = 0; i < list.length; i++) {
- var m = list[i];
- if (!m || m.role !== "user") continue;
- if (m.isImage) return "[图片]";
- var t = String(m.content || "").trim();
- if (t) return t;
- }
- return "";
- }
- function formatDiscussionTitle(question) {
- var qText = String(question || "").trim();
- if (!qText) return "与AI助手对话";
- if (qText.slice(-3) === "的讨论") return qText;
- return qText + "的讨论";
- }
- function formatDate(ts) {
- var d = ts ? new Date(Number(ts)) : new Date();
- if (isNaN(d.getTime())) d = new Date();
- return d.getFullYear() + "年" + (d.getMonth() + 1) + "月" + d.getDate() + "日";
- }
- function renderMessages(messages) {
- var html = "";
- var list = Array.isArray(messages) ? messages : [];
- for (var i = 0; i < list.length; i++) {
- var msg = list[i];
- if (!msg) continue;
- if (msg.role === "user") {
- var userText = msg.isImage ? "[图片]" : String(msg.content || "").trim();
- if (!userText) continue;
- html +=
- '<div class="row row--user"><div class="user-bubble">' +
- escHtml(userText) +
- "</div></div>";
- continue;
- }
- if (msg.role === "ai") {
- var aiText = String(msg.content || "").trim();
- if (!aiText) continue;
- html +=
- '<div class="row row--ai"><div class="ai-card"><div class="ai-card__text">' +
- escHtml(aiText) +
- "</div></div></div>";
- }
- }
- return html;
- }
- function applyWeixinShareMeta() {
- var siteName = "U店在哪";
- var iconUrl =
- "https://alien-volume.oss-cn-beijing.aliyuncs.com/icon/ubao.png";
- var setMeta = function (key, content) {
- var el =
- document.querySelector('meta[property="' + key + '"]') ||
- document.querySelector('meta[name="' + key + '"]');
- if (!el) {
- el = document.createElement("meta");
- if (key.indexOf("og:") === 0) {
- el.setAttribute("property", key);
- } else {
- el.setAttribute("name", key);
- }
- document.head.appendChild(el);
- }
- el.setAttribute("content", content);
- };
- setMeta("og:site_name", siteName);
- setMeta("application-name", siteName);
- setMeta("og:title", "和U宝的对话");
- setMeta("og:description", "点击查看对话内容");
- var links = document.querySelectorAll('link[rel="icon"], link[rel="apple-touch-icon"]');
- for (var i = 0; i < links.length; i++) {
- links[i].setAttribute("href", iconUrl);
- }
- }
- function render(data) {
- applyWeixinShareMeta();
- sharePayloadCache = data || null;
- var main = document.getElementById("main");
- if (!data) {
- main.innerHTML = '<div class="empty">对话内容不存在或链接已失效</div>';
- refreshWxLaunchTagAttrs();
- return;
- }
- var messages = data.messages || [];
- var firstQuestion =
- String(data.firstQuestion || "").trim() || getFirstUserQuestion(messages);
- var pageTitle = formatDiscussionTitle(firstQuestion);
- var dateText = formatDate(data.shareTime);
- document.title = pageTitle;
- var bodyHtml =
- '<section class="hero">' +
- '<h1 class="hero__title">' +
- escHtml(pageTitle) +
- "</h1>" +
- '<p class="hero__meta">' +
- escHtml(dateText) +
- " · 内容由AI生成,不能完全保障真实</p>" +
- '<div class="hero__divider"></div>' +
- "</section>";
- var convHtml = renderMessages(messages);
- if (convHtml) {
- bodyHtml += '<section class="conversation">' + convHtml + "</section>";
- } else if (data.content) {
- bodyHtml +=
- '<section class="fallback-card"><div class="ai-card__text">' +
- escHtml(data.content) +
- "</div></section>";
- } else {
- bodyHtml += '<div class="empty">暂无对话内容</div>';
- }
- main.innerHTML = bodyHtml;
- refreshWxLaunchTagAttrs();
- }
- function buildAiConsultOpenParams() {
- var params = new URLSearchParams();
- params.set("pageType", "home");
- params.set("fromShareAiConsult", "1");
- return params;
- }
- function buildAppDeepLink() {
- var path = APP_UNI_AI_PATH;
- var qs = buildAiConsultOpenParams().toString();
- var root = APP_IOS_URL_SCHEME.replace(/\/$/, "");
- return root + "/" + path + (qs ? "?" + qs : "");
- }
- function buildWeChatLaunchExtinfo() {
- var qs = buildAiConsultOpenParams().toString();
- var uniPage = qs ? APP_UNI_AI_PATH + "?" + qs : APP_UNI_AI_PATH;
- return uniPage.length <= 1024 ? uniPage : APP_UNI_AI_PATH + "?pageType=home&fromShareAiConsult=1";
- }
- function isWeChatInAppBrowser() {
- return /MicroMessenger/i.test(navigator.userAgent || "");
- }
- function isIOSWeChatBrowser() {
- var ua = navigator.userAgent || "";
- return /MicroMessenger/i.test(ua) && /iPhone|iPad|iPod/i.test(ua);
- }
- function isWxDebugOn() {
- return q("wxDebug") === "1";
- }
- function isWxForceDebug() {
- return q("wxForce") === "1";
- }
- function isWxPcAutoDebugHost() {
- var h = (location.hostname || "").toLowerCase();
- if (h === "localhost" || h === "127.0.0.1") return true;
- for (var i = 0; i < WECHAT_JS_SAFE_HOSTS.length; i++) {
- if (WECHAT_JS_SAFE_HOSTS[i] === h) return true;
- }
- return false;
- }
- function isWxPcBrowser() {
- return !isWeChatInAppBrowser();
- }
- function shouldInitWeChatJssdkOnLoad() {
- if (isWeChatInAppBrowser()) return true;
- return isWxForceDebug() || isWxPcAutoDebugHost();
- }
- function shouldFetchWxConfig(fromUserClick) {
- if (isWeChatInAppBrowser()) return true;
- if (fromUserClick) return true;
- return isWxForceDebug() || isWxPcAutoDebugHost();
- }
- function getWxHtmlUrl() {
- var forced = String(q("wxSignUrl") || "").trim();
- if (forced) return forced.split("#")[0];
- return String(location.href || "").split("#")[0];
- }
- function getWxSignPageUrlForApi() {
- var htmlUrl = getWxHtmlUrl();
- if (htmlUrl && /^https?:\/\//i.test(htmlUrl)) return htmlUrl;
- return WX_GET_CONFIG_SIGN_URL;
- }
- function getWxHtmlUrlBase() {
- var htmlUrl = getWxSignPageUrlForApi();
- try {
- var u = new URL(htmlUrl);
- return u.origin + u.pathname;
- } catch (eU) {
- return WX_GET_CONFIG_SIGN_URL;
- }
- }
- function getWxConfigSignUrl() {
- if (String(q("wxSignBaseOnly") || "") === "1") return getWxHtmlUrlBase();
- return getWxSignPageUrlForApi();
- }
- function getWxGetConfigApiUrl() {
- return API_BASE.replace(/\/$/, "") + WECHAT_GET_WX_CONFIG_PATH;
- }
- function buildWxGetConfigRequestBody(htmlUrl) {
- return {
- url: String(htmlUrl || "").split("#")[0].trim(),
- };
- }
- function resolveWxConfigAppIdFromSignData(d) {
- if (!d || typeof d !== "object") return "";
- var mp =
- d.mpAppId ||
- d.mpAppid ||
- d.officialAppId ||
- d.gzhAppId ||
- d.serviceAppId;
- if (mp != null && String(mp).trim() !== "") return String(mp).trim();
- var fromQuery = String(q("wxMpAppId") || WECHAT_MP_APP_ID || "").trim();
- if (fromQuery) return fromQuery;
- var raw = d.appId || d.appid || d.wxAppId;
- return raw != null && String(raw).trim() !== "" ? String(raw).trim() : "";
- }
- function normalizeWxJssdkSignPayload(res, signUrlUsed) {
- if (!res || typeof res !== "object") return null;
- var d = res.data != null && typeof res.data === "object" ? res.data : res;
- if (!d || typeof d !== "object") return null;
- var appId = resolveWxConfigAppIdFromSignData(d);
- var timestamp = d.timestamp != null ? d.timestamp : d.timeStamp;
- var nonceStr =
- d.nonceStr != null && String(d.nonceStr) !== ""
- ? d.nonceStr
- : d.noncestr != null && String(d.noncestr) !== ""
- ? d.noncestr
- : d.nonce;
- var signature = d.signature || d.sign;
- if (!appId || timestamp == null || nonceStr == null || nonceStr === "" || !signature) {
- return null;
- }
- return {
- appId: String(appId),
- timestamp: Number(timestamp),
- nonceStr: String(nonceStr),
- signature: String(signature),
- signUrl: String(signUrlUsed || "")
- .split("#")[0]
- .trim(),
- };
- }
- function getWxErrMsg(err) {
- if (!err) return "";
- if (err.errMsg) return String(err.errMsg);
- if (typeof err === "string") return err;
- try {
- return JSON.stringify(err);
- } catch (e) {
- return String(err);
- }
- }
- function formatWxConfigErrorTip(err, signPageUrl) {
- var errMsg = getWxErrMsg(err);
- var tip = "微信 JSSDK 配置失败";
- if (/invalid signature/i.test(errMsg)) {
- return (
- tip +
- ":签名无效。请核对:①后端用与前端相同的 url 签名;②url=" +
- (signPageUrl || getWxHtmlUrl()) +
- ";③nonceStr/timestamp 与接口返回一致;④appId=" +
- WECHAT_MP_APP_ID
- );
- }
- if (/require\s*subscribe/i.test(errMsg)) {
- return tip + ":" + errMsg + "(服务号需用户已关注)";
- }
- return errMsg ? tip + ":" + errMsg : tip;
- }
- function setWxInitError(msg) {
- wxInitLastError = String(msg || "").trim();
- if (wxInitLastError) console.warn("[wx]", wxInitLastError);
- }
- function requestWeChatJssdkSignAndConfig(htmlUrlOptional) {
- var htmlUrl = String(htmlUrlOptional != null ? htmlUrlOptional : getWxConfigSignUrl())
- .split("#")[0]
- .trim();
- if (!htmlUrl || !/^https?:\/\//i.test(htmlUrl)) {
- htmlUrl = WX_GET_CONFIG_SIGN_URL;
- }
- if (isWxDebugOn()) {
- try {
- window.alert("htmlUrl(签名用,应与地址栏一致):\n" + htmlUrl);
- } catch (eDbg) {}
- }
- var requestUrl = getWxGetConfigApiUrl();
- var requestBody = buildWxGetConfigRequestBody(htmlUrl);
- return fetch(requestUrl, {
- method: "POST",
- mode: "cors",
- credentials: "omit",
- headers: {
- Accept: "application/json",
- "Content-Type": "application/json;charset=UTF-8",
- },
- body: JSON.stringify(requestBody),
- })
- .then(function (r) {
- if (r.ok) return r.json();
- return r
- .text()
- .catch(function () {
- return "";
- })
- .then(function (text) {
- var hint = "";
- try {
- var j = JSON.parse(text);
- hint = j.msg || j.message || "";
- } catch (eP) {
- if (text) hint = text.slice(0, 120);
- }
- throw new Error("getWxConfig HTTP " + r.status + (hint ? ":" + hint : ""));
- });
- })
- .then(function (res) {
- if (res && res.code != null) {
- var c = Number(res.code);
- if (c !== 200 && c !== 0 && res.success !== true) {
- throw new Error(res.msg || res.message || "getWxConfig code " + c);
- }
- }
- var sign = normalizeWxJssdkSignPayload(res, htmlUrl);
- if (!sign) {
- throw new Error("getWxConfig 缺少 appId/timestamp/nonceStr/signature(见控制台)");
- }
- if (typeof wx === "undefined") {
- if (isWxPcBrowser()) {
- console.log("[wx] PC getWxConfig 成功(无 jweixin)", sign);
- return true;
- }
- setWxInitError("jweixin.js 未加载");
- return false;
- }
- return applyWxConfigFromSign(sign, htmlUrl);
- });
- }
- function applyWxConfigFromSign(sign, htmlUrl) {
- var wxConfigParams = {
- debug: isWxDebugOn(),
- appId: String(sign.appId),
- timestamp: sign.timestamp,
- nonceStr: String(sign.nonceStr),
- signature: String(sign.signature),
- jsApiList: [],
- openTagList: ["wx-open-launch-app"],
- };
- return new Promise(function (resolve) {
- wx.config(wxConfigParams);
- wx.ready(function () {
- weChatJssdkConfigured = true;
- document.body.classList.add("wx-jssdk-ready");
- refreshWxLaunchTagAttrs();
- console.log("[wx.config] ready, htmlUrl=", htmlUrl);
- resolve(true);
- });
- wx.error(function (err) {
- weChatJssdkConfigured = false;
- document.body.classList.remove("wx-jssdk-ready");
- wxJssdkInitPromise = null;
- var errMsg = getWxErrMsg(err);
- setWxInitError(formatWxConfigErrorTip(err, htmlUrl));
- if (isWxDebugOn()) window.alert(wxInitLastError);
- console.warn("[wx.config]", errMsg, "htmlUrl=", htmlUrl);
- var baseUrl = getWxHtmlUrlBase();
- var fullUrl = getWxSignPageUrlForApi();
- if (
- !/invalid signature/i.test(errMsg) ||
- wxConfigSignRetriedBaseUrl ||
- baseUrl === fullUrl ||
- htmlUrl === baseUrl
- ) {
- resolve(false);
- return;
- }
- wxConfigSignRetriedBaseUrl = true;
- requestWeChatJssdkSignAndConfig(baseUrl).then(resolve);
- });
- });
- }
- function refreshWxLaunchTagAttrs() {
- var tag = document.getElementById("launch-btn");
- if (!tag) return;
- try {
- tag.setAttribute("appid", WECHAT_OPEN_APP_ID);
- tag.setAttribute("extinfo", buildWeChatLaunchExtinfo());
- } catch (eA) {}
- }
- function bindWeChatLaunchTagEvents() {
- var tag = document.getElementById("launch-btn");
- if (!tag || tag._wxLaunchBound) return;
- tag._wxLaunchBound = true;
- refreshWxLaunchTagAttrs();
- tag.addEventListener("launch", function () {
- console.log("[wx-open-launch-app] launch ok");
- });
- tag.addEventListener("error", function (e) {
- var detail = e && e.detail;
- var errMsg =
- detail && detail.errMsg
- ? String(detail.errMsg)
- : detail && detail.errmsg
- ? String(detail.errmsg)
- : "";
- console.warn("[wx-open-launch-app]", detail);
- showAppOpenFailTip(
- errMsg
- ? "未能打开 App:" + errMsg
- : "未能打开 App,请确认已安装最新版「U店在哪」"
- );
- });
- }
- function initWeChatOpenLaunchApp(fromUserClick) {
- if (!shouldFetchWxConfig(!!fromUserClick)) {
- return Promise.resolve(false);
- }
- if (wxJssdkInitPromise && !fromUserClick) return wxJssdkInitPromise;
- wxConfigSignRetriedBaseUrl = false;
- wxInitLastError = "";
- var htmlUrl = getWxConfigSignUrl();
- bindWeChatLaunchTagEvents();
- wxJssdkInitPromise = requestWeChatJssdkSignAndConfig(htmlUrl)
- .then(function (ok) {
- if (ok === true) return true;
- if (!wxInitLastError) {
- setWxInitError("wx.config 失败,可加 ?wxDebug=1 查看 htmlUrl");
- }
- return false;
- })
- .catch(function (e) {
- var msg = e && e.message ? e.message : "getWxConfig 请求失败";
- setWxInitError(msg);
- console.warn("[wx] requestWeChatJssdkSignAndConfig failed", msg, "htmlUrl=", htmlUrl);
- if (isWeChatInAppBrowser() && isWxDebugOn()) window.alert(msg);
- return false;
- })
- .finally(function () {
- if (!weChatJssdkConfigured) wxJssdkInitPromise = null;
- });
- return wxJssdkInitPromise;
- }
- function scheduleWeChatJssdkBootstrap() {
- if (!shouldInitWeChatJssdkOnLoad()) return;
- var attempts = 0;
- function tick() {
- attempts += 1;
- if (weChatJssdkConfigured) return;
- initWeChatOpenLaunchApp();
- if (!weChatJssdkConfigured && attempts < 8 && typeof wx === "undefined") {
- setTimeout(tick, 400);
- }
- }
- if (isIOSWeChatBrowser()) {
- setTimeout(tick, 350);
- } else {
- tick();
- }
- }
- function showFabToast(msg, ms) {
- var tip = String(msg || "").trim();
- if (!tip) return;
- var el = document.getElementById("openAppToast");
- if (el) {
- el.textContent = tip;
- el.style.display = "block";
- if (showFabToast._t) clearTimeout(showFabToast._t);
- showFabToast._t = setTimeout(function () {
- el.style.display = "none";
- }, ms || 2800);
- }
- console.log("[openApp]", tip);
- }
- function showDownloadTip() {
- var msg = "请到应用商店下载「U店在哪」";
- if (typeof uni !== "undefined" && typeof uni.showToast === "function") {
- uni.showToast({ title: msg, icon: "none", duration: 2500 });
- } else {
- window.alert(msg);
- }
- }
- function showAppOpenFailTip(msg) {
- var tip = msg || "未能打开 App,请确认已安装最新版「U店在哪」。";
- if (typeof uni !== "undefined" && typeof uni.showToast === "function") {
- uni.showToast({ title: msg, icon: "none", duration: 2800 });
- } else if (isWeChatInAppBrowser()) {
- window.alert(tip);
- } else {
- showFabToast(tip);
- }
- }
- function launchAppDeepLink(deepLink) {
- try {
- var a = document.createElement("a");
- a.href = deepLink;
- a.setAttribute("target", "_self");
- document.body.appendChild(a);
- a.click();
- document.body.removeChild(a);
- } catch (e1) {}
- try {
- window.location.href = deepLink;
- } catch (e2) {}
- }
- function tryOpenHBuilderAppViaScheme() {
- var deepLink = buildAppDeepLink();
- if (typeof plus !== "undefined" && plus.runtime) {
- var installed = null;
- try {
- if (typeof plus.runtime.isApplicationExist === "function") {
- installed = plus.runtime.isApplicationExist({
- pname: APP_ANDROID_PACKAGE,
- action: APP_IOS_URL_SCHEME,
- });
- }
- } catch (e) {
- console.warn(e);
- }
- try {
- plus.runtime.openURL(deepLink);
- } catch (e2) {
- console.warn(e2);
- if (installed === false) {
- showDownloadTip();
- }
- }
- return;
- }
- var done = false;
- function finish() {
- if (done) return;
- done = true;
- document.removeEventListener("visibilitychange", onVis);
- window.removeEventListener("pagehide", onHide);
- }
- function onVis() {
- if (document.visibilityState === "hidden") finish();
- }
- function onHide() {
- finish();
- }
- document.addEventListener("visibilitychange", onVis);
- window.addEventListener("pagehide", onHide);
- try {
- launchAppDeepLink(deepLink);
- } catch (e3) {
- finish();
- showDownloadTip();
- return;
- }
- window.setTimeout(function () {
- finish();
- }, 3200);
- }
- function tryOpenApp() {
- if (isWeChatInAppBrowser()) {
- if (!weChatJssdkConfigured) {
- initWeChatOpenLaunchApp(true).then(function (ok) {
- if (!ok) {
- showAppOpenFailTip(wxInitLastError || "微信唤起 App 初始化失败");
- }
- });
- }
- return;
- }
- tryOpenHBuilderAppViaScheme();
- }
- if (isWeChatInAppBrowser()) {
- document.body.classList.add("is-wechat");
- }
- bindWeChatLaunchTagEvents();
- scheduleWeChatJssdkBootstrap();
- document.getElementById("btnContinue").addEventListener("click", tryOpenApp);
- render(parsePayload());
- })();
- </script>
- </body>
- </html>
|