shareAiConsult.html 41 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339
  1. <!DOCTYPE html>
  2. <html lang="zh-CN">
  3. <head>
  4. <meta charset="utf-8">
  5. <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no, viewport-fit=cover">
  6. <meta name="format-detection" content="telephone=no">
  7. <title>与U宝对话</title>
  8. <meta property="og:title" content="和U宝的对话">
  9. <meta property="og:description" content="点击查看对话内容">
  10. <meta property="og:site_name" content="U店在哪">
  11. <meta name="application-name" content="U店在哪">
  12. <link rel="icon" type="image/png" href="https://alien-volume.oss-cn-beijing.aliyuncs.com/icon/ubao.png">
  13. <link rel="apple-touch-icon" href="https://alien-volume.oss-cn-beijing.aliyuncs.com/icon/ubao.png">
  14. <style>
  15. :root {
  16. --bg: #f4f6fb;
  17. --text: #151515;
  18. --muted: #aaaaaa;
  19. --orange: #f47d1f;
  20. --safe-bottom: env(safe-area-inset-bottom, 0px);
  21. }
  22. * {
  23. margin: 0;
  24. padding: 0;
  25. box-sizing: border-box;
  26. }
  27. html {
  28. height: 100%;
  29. -webkit-tap-highlight-color: transparent;
  30. overflow: hidden;
  31. }
  32. body {
  33. font-family: -apple-system, BlinkMacSystemFont, "PingFang SC", "Microsoft YaHei", sans-serif;
  34. background: var(--bg);
  35. color: var(--text);
  36. height: 100vh;
  37. display: flex;
  38. flex-direction: column;
  39. overflow: hidden;
  40. }
  41. #main {
  42. flex: 1;
  43. min-height: 0;
  44. overflow-x: hidden;
  45. overflow-y: auto;
  46. -webkit-overflow-scrolling: touch;
  47. padding-bottom: calc(100px + var(--safe-bottom));
  48. }
  49. .hero {
  50. padding: 16px 15px 0;
  51. }
  52. .hero__title {
  53. font-size: 20px;
  54. font-weight: 700;
  55. line-height: 1.4;
  56. word-break: break-word;
  57. }
  58. .hero__meta {
  59. margin-top: 8px;
  60. font-size: 12px;
  61. color: var(--muted);
  62. line-height: 1.4;
  63. }
  64. .hero__divider {
  65. margin-top: 14px;
  66. height: 1px;
  67. background: rgba(170, 170, 170, 0.25);
  68. }
  69. .conversation {
  70. padding: 14px 15px 8px;
  71. }
  72. .scroll-spacer {
  73. height: calc(72px + var(--safe-bottom));
  74. flex-shrink: 0;
  75. }
  76. .conversation .row:last-child {
  77. margin-bottom: 0;
  78. }
  79. .row {
  80. display: flex;
  81. margin-bottom: 12px;
  82. }
  83. .row--user {
  84. justify-content: flex-end;
  85. }
  86. .row--ai {
  87. justify-content: flex-start;
  88. }
  89. .user-bubble {
  90. position: relative;
  91. max-width: 78%;
  92. padding: 10px 14px;
  93. background: var(--orange);
  94. border-radius: 8px 8px 2px 8px;
  95. color: #fff;
  96. font-size: 15px;
  97. font-weight: 500;
  98. line-height: 1.5;
  99. white-space: pre-wrap;
  100. word-break: break-word;
  101. }
  102. .user-bubble::after {
  103. content: "";
  104. position: absolute;
  105. right: -6px;
  106. bottom: 8px;
  107. width: 0;
  108. height: 0;
  109. border-style: solid;
  110. border-width: 6px 0 6px 7px;
  111. border-color: transparent transparent transparent var(--orange);
  112. }
  113. .ai-card {
  114. width: 100%;
  115. padding: 14px 13px;
  116. background: #fff;
  117. border-radius: 12px;
  118. box-shadow: 0 1px 6px rgba(0, 0, 0, 0.04);
  119. }
  120. .ai-card__text {
  121. font-size: 14px;
  122. line-height: 1.65;
  123. white-space: pre-wrap;
  124. word-break: break-word;
  125. text-align: left;
  126. }
  127. .ai-card__image {
  128. display: block;
  129. max-width: 100%;
  130. height: auto;
  131. margin: 8px 0;
  132. border-radius: 6px;
  133. }
  134. .user-bubble__image {
  135. display: block;
  136. max-width: 180px;
  137. border-radius: 4px;
  138. }
  139. .fallback-card {
  140. margin: 14px 15px 0;
  141. padding: 14px 13px;
  142. background: #fff;
  143. border-radius: 8px;
  144. box-shadow: 0 1px 6px rgba(0, 0, 0, 0.04);
  145. }
  146. .fallback-card .ai-card__text {
  147. font-size: 14px;
  148. line-height: 1.65;
  149. white-space: pre-wrap;
  150. word-break: break-word;
  151. text-align: left;
  152. }
  153. .empty {
  154. padding: 48px 20px;
  155. text-align: center;
  156. color: var(--muted);
  157. font-size: 14px;
  158. }
  159. .fab-wrap {
  160. position: fixed;
  161. left: 0;
  162. right: 0;
  163. bottom: 0;
  164. z-index: 200;
  165. padding: 12px 24px calc(12px + var(--safe-bottom));
  166. background: linear-gradient(to top, rgba(255, 255, 255, 0.98) 70%, transparent);
  167. pointer-events: none;
  168. }
  169. .fab-dock__slot {
  170. width: 100%;
  171. max-width: 198px;
  172. height: 48px;
  173. margin: 0 auto;
  174. pointer-events: auto;
  175. }
  176. #openApp.fab {
  177. padding: 0 10px;
  178. -webkit-font-smoothing: antialiased;
  179. text-rendering: optimizeLegibility;
  180. }
  181. .fab__brand-clip {
  182. display: block;
  183. flex-shrink: 0;
  184. line-height: 0;
  185. }
  186. .fab__brand-img {
  187. display: block;
  188. height: 26px;
  189. width: auto;
  190. max-width: none;
  191. pointer-events: none;
  192. -webkit-user-drag: none;
  193. }
  194. .fab__label {
  195. font-size: 15px;
  196. line-height: 1;
  197. letter-spacing: 0.04em;
  198. white-space: nowrap;
  199. }
  200. #launch-btn {
  201. display: none;
  202. width: 100%;
  203. height: 48px;
  204. min-height: 48px;
  205. border-radius: 24px;
  206. overflow: hidden;
  207. opacity: 1;
  208. }
  209. body.is-wechat.wx-jssdk-ready #launch-btn {
  210. display: block;
  211. pointer-events: auto;
  212. }
  213. body.is-wechat.wx-jssdk-ready #openApp {
  214. display: none !important;
  215. }
  216. .fab-wrap .fab {
  217. pointer-events: auto;
  218. }
  219. #openApp {
  220. touch-action: manipulation;
  221. }
  222. .fab {
  223. display: flex;
  224. align-items: center;
  225. justify-content: center;
  226. gap: 4px;
  227. width: 100%;
  228. max-width: 198px;
  229. margin: 0 auto;
  230. height: 48px;
  231. border: none;
  232. border-radius: 24px;
  233. background: #F47D1F;
  234. color: #fff;
  235. font-size: 16px;
  236. font-weight: 600;
  237. box-shadow: 0 4px 16px rgba(245, 130, 32, 0.45);
  238. cursor: pointer;
  239. }
  240. .home-indicator {
  241. height: 5px;
  242. background: #000;
  243. border-radius: 3px;
  244. width: 134px;
  245. margin: 8px auto 4px;
  246. opacity: 0.2;
  247. }
  248. #openAppToast {
  249. display: none;
  250. position: fixed;
  251. left: 16px;
  252. right: 16px;
  253. bottom: calc(72px + var(--safe-bottom));
  254. z-index: 10001;
  255. padding: 10px 14px;
  256. font-size: 13px;
  257. line-height: 1.45;
  258. color: #fff;
  259. text-align: center;
  260. background: rgba(0, 0, 0, 0.78);
  261. border-radius: 8px;
  262. pointer-events: none;
  263. word-break: break-all;
  264. }
  265. </style>
  266. </head>
  267. <body>
  268. <main id="main">
  269. <div class="empty">对话内容加载中…</div>
  270. </main>
  271. <div id="openAppToast" role="status" aria-live="polite"></div>
  272. <div class="fab-wrap">
  273. <div class="fab-dock__slot">
  274. <!-- 与 secondShareGoods 相同顺序:openApp 在下,launch-btn 在上,避免挡住点击 -->
  275. <button type="button" class="fab" id="openApp" aria-label="APP内打开">
  276. <span class="fab__brand-clip" aria-hidden="true">
  277. <img class="fab__brand-img" src="images/uCharts.png" alt="" decoding="async">
  278. </span>
  279. </button>
  280. <wx-open-launch-app id="launch-btn" appid="wxf5f1efe3a9f5012e" extinfo="">
  281. <script type="text/wxtag-template">
  282. <style>
  283. .wx-open-app-btn {
  284. display: flex;
  285. align-items: center;
  286. justify-content: center;
  287. gap: 4px;
  288. width: 100%;
  289. height: 48px;
  290. margin: 0;
  291. padding: 0 10px;
  292. border: none;
  293. border-radius: 24px;
  294. background: #F47D1F;
  295. box-shadow: 0 4px 16px rgba(245, 130, 32, 0.45);
  296. color: #fff;
  297. font-family: -apple-system, BlinkMacSystemFont, "PingFang SC", "Helvetica Neue", sans-serif;
  298. -webkit-font-smoothing: antialiased;
  299. cursor: pointer;
  300. overflow: hidden;
  301. -webkit-tap-highlight-color: transparent;
  302. box-sizing: border-box;
  303. }
  304. .wx-open-app-btn .fab__brand-clip {
  305. display: block;
  306. flex-shrink: 0;
  307. line-height: 0;
  308. }
  309. .wx-open-app-btn .fab__brand-img {
  310. display: block;
  311. height: 26px;
  312. width: auto;
  313. max-width: none;
  314. pointer-events: none;
  315. -webkit-user-drag: none;
  316. }
  317. .wx-open-app-btn .fab__label {
  318. font-size: 15px;
  319. line-height: 1;
  320. letter-spacing: 0.04em;
  321. white-space: nowrap;
  322. }
  323. </style>
  324. <button class="wx-open-app-btn" aria-label="APP内打开">
  325. <span class="fab__brand-clip" aria-hidden="true">
  326. <img class="fab__brand-img" src="https://prod.ailien.shop/h5/HBuilderProjects/images/uCharts.png" alt="" decoding="async">
  327. </span>
  328. </button>
  329. </script>
  330. </wx-open-launch-app>
  331. </div>
  332. </div>
  333. <script src="https://res.wx.qq.com/open/js/jweixin-1.6.0.js"></script>
  334. <script>
  335. (function () {
  336. "use strict";
  337. var API_BASE = "https://prod.ailien.shop/alienStore";
  338. var WECHAT_MP_APP_ID = "wx412792c77f47babd";
  339. var WECHAT_OPEN_APP_ID = "wxf5f1efe3a9f5012e";
  340. var WECHAT_GET_WX_CONFIG_PATH = "/wx/getWxConfig";
  341. var H5_PAGE_BASE_FALLBACK = "https://prod.ailien.shop/h5/HBuilderProjects/";
  342. var WX_GET_CONFIG_SIGN_URL = H5_PAGE_BASE_FALLBACK + "shareAiConsult.html";
  343. var WECHAT_JS_SAFE_HOSTS = ["uat.ailien.shop", "prod.ailien.shop"];
  344. var APP_ANDROID_PACKAGE = "com.alien.Udianzaizhe";
  345. var APP_IOS_URL_SCHEME = "shopro://";
  346. var APP_UNI_AI_PATH = "pages/aiSearchResult/index";
  347. var sharePayloadCache = null;
  348. var weChatJssdkConfigured = false;
  349. var wxConfigSignRetriedBaseUrl = false;
  350. var wxInitLastError = "";
  351. var wxJssdkInitPromise = null;
  352. function escHtml(s) {
  353. return String(s || "")
  354. .replace(/&/g, "&amp;")
  355. .replace(/</g, "&lt;")
  356. .replace(/>/g, "&gt;")
  357. .replace(/"/g, "&quot;");
  358. }
  359. var IMAGE_EXT = "(?:jpe?g|png|gif|webp|bmp|avif)";
  360. var IMAGE_URL_PATTERN =
  361. "https?:\\/\\/[^\\s))\\]]+\\." + IMAGE_EXT + "(?:\\?[^\\s))\\]]*)?";
  362. function isInsideImageUrlSyntax(full, offset) {
  363. if (offset >= 2 && full.slice(offset - 2, offset) === "](") return true;
  364. if (offset >= 1 && full[offset - 1] === "(") return true;
  365. if (offset >= 6 && full.slice(offset - 6, offset) === "{{IMG|") return true;
  366. return false;
  367. }
  368. /** AI 回复常见:店名(https://...jpg) — 转为可渲染的图片占位 */
  369. function embedInlineImageUrls(text) {
  370. if (text == null) return "";
  371. var t = String(text);
  372. t = t.replace(
  373. new RegExp("([^\\n((]+?)\\((" + IMAGE_URL_PATTERN + ")\\)", "gi"),
  374. function (_, label, url) {
  375. var name = String(label).trim();
  376. if (!name) return "\n\n{{IMG|" + url + "|}}\n\n";
  377. var alt = name.length > 24 ? "图片" : name.replace(/[\[\]]/g, "");
  378. return name + "\n\n{{IMG|" + url + "|" + alt + "}}\n\n";
  379. }
  380. );
  381. t = t.replace(
  382. new RegExp("\\((" + IMAGE_URL_PATTERN + ")\\)", "gi"),
  383. function (_, url) {
  384. return "\n\n{{IMG|" + url + "|}}\n\n";
  385. }
  386. );
  387. t = t.replace(new RegExp(IMAGE_URL_PATTERN, "gi"), function (url, offset, full) {
  388. if (isInsideImageUrlSyntax(full, offset)) return url;
  389. return "\n\n{{IMG|" + url + "|}}\n\n";
  390. });
  391. return t.replace(/\n{3,}/g, "\n\n");
  392. }
  393. function formatTextBlockHtml(text) {
  394. return escHtml(text).replace(/\n/g, "<br>");
  395. }
  396. function buildAiImageTag(url, alt) {
  397. var safeUrl = escHtml(url);
  398. var safeAlt = escHtml(alt || "图片");
  399. return (
  400. '<img class="ai-card__image" src="' +
  401. safeUrl +
  402. '" alt="' +
  403. safeAlt +
  404. '" loading="lazy" decoding="async" />'
  405. );
  406. }
  407. function renderAiContentHtml(text) {
  408. var t = embedInlineImageUrls(text);
  409. var html = "";
  410. var tokenRe = /\{\{IMG\|([^|]+)\|([^}]*)\}\}/g;
  411. var lastIndex = 0;
  412. var match;
  413. while ((match = tokenRe.exec(t)) !== null) {
  414. if (match.index > lastIndex) {
  415. html += formatTextBlockHtml(t.slice(lastIndex, match.index));
  416. }
  417. html += buildAiImageTag(match[1], match[2]);
  418. lastIndex = tokenRe.lastIndex;
  419. }
  420. if (lastIndex < t.length) {
  421. html += formatTextBlockHtml(t.slice(lastIndex));
  422. }
  423. return html;
  424. }
  425. function q(name) {
  426. try {
  427. var v = new URLSearchParams(location.search || "").get(name);
  428. return v == null ? "" : String(v);
  429. } catch (e) {
  430. return "";
  431. }
  432. }
  433. function getQueryParam(name) {
  434. var m = new RegExp("[?&]" + name + "=([^&]*)").exec(window.location.search);
  435. if (!m) return "";
  436. try {
  437. return decodeURIComponent(m[1].replace(/\+/g, " "));
  438. } catch (e) {
  439. return "";
  440. }
  441. }
  442. function parsePayload() {
  443. var raw = getQueryParam("payload");
  444. if (!raw) return null;
  445. try {
  446. return JSON.parse(raw);
  447. } catch (e) {
  448. return null;
  449. }
  450. }
  451. function getFirstUserQuestion(messages) {
  452. var list = Array.isArray(messages) ? messages : [];
  453. for (var i = 0; i < list.length; i++) {
  454. var m = list[i];
  455. if (!m || m.role !== "user") continue;
  456. if (m.isImage) return "[图片]";
  457. var t = String(m.content || "").trim();
  458. if (t) return t;
  459. }
  460. return "";
  461. }
  462. function formatDiscussionTitle(question) {
  463. var qText = String(question || "").trim();
  464. if (!qText) return "与AI助手对话";
  465. if (qText.slice(-3) === "的讨论") return qText;
  466. return qText + "的讨论";
  467. }
  468. function formatDate(ts) {
  469. var d = ts ? new Date(Number(ts)) : new Date();
  470. if (isNaN(d.getTime())) d = new Date();
  471. return d.getFullYear() + "年" + (d.getMonth() + 1) + "月" + d.getDate() + "日";
  472. }
  473. function renderMessages(messages) {
  474. var html = "";
  475. var list = Array.isArray(messages) ? messages : [];
  476. for (var i = 0; i < list.length; i++) {
  477. var msg = list[i];
  478. if (!msg) continue;
  479. if (msg.role === "user") {
  480. if (msg.isImage && msg.imageUrl) {
  481. html +=
  482. '<div class="row row--user"><div class="user-bubble"><img class="user-bubble__image" src="' +
  483. escHtml(msg.imageUrl) +
  484. '" alt="图片" loading="lazy" decoding="async" /></div></div>';
  485. continue;
  486. }
  487. var userText = String(msg.content || "").trim();
  488. if (!userText) continue;
  489. html +=
  490. '<div class="row row--user"><div class="user-bubble">' +
  491. escHtml(userText) +
  492. "</div></div>";
  493. continue;
  494. }
  495. if (msg.role === "ai" || msg.role === "assistant") {
  496. var aiText = String(msg.content || "").trim();
  497. if (!aiText) continue;
  498. html +=
  499. '<div class="row row--ai"><div class="ai-card"><div class="ai-card__text">' +
  500. renderAiContentHtml(aiText) +
  501. "</div></div></div>";
  502. }
  503. }
  504. return html;
  505. }
  506. function applyWeixinShareMeta() {
  507. var siteName = "U店在哪";
  508. var iconUrl =
  509. "https://alien-volume.oss-cn-beijing.aliyuncs.com/icon/ubao.png";
  510. var setMeta = function (key, content) {
  511. var el =
  512. document.querySelector('meta[property="' + key + '"]') ||
  513. document.querySelector('meta[name="' + key + '"]');
  514. if (!el) {
  515. el = document.createElement("meta");
  516. if (key.indexOf("og:") === 0) {
  517. el.setAttribute("property", key);
  518. } else {
  519. el.setAttribute("name", key);
  520. }
  521. document.head.appendChild(el);
  522. }
  523. el.setAttribute("content", content);
  524. };
  525. setMeta("og:site_name", siteName);
  526. setMeta("application-name", siteName);
  527. setMeta("og:title", "和U宝的对话");
  528. setMeta("og:description", "点击查看对话内容");
  529. var links = document.querySelectorAll('link[rel="icon"], link[rel="apple-touch-icon"]');
  530. for (var i = 0; i < links.length; i++) {
  531. links[i].setAttribute("href", iconUrl);
  532. }
  533. }
  534. function countDisplayableMessages(messages) {
  535. var list = Array.isArray(messages) ? messages : [];
  536. var count = 0;
  537. for (var i = 0; i < list.length; i++) {
  538. var msg = list[i];
  539. if (!msg) continue;
  540. if (msg.role === "user") {
  541. if (msg.isImage && msg.imageUrl) {
  542. count += 1;
  543. continue;
  544. }
  545. if (String(msg.content || "").trim()) count += 1;
  546. continue;
  547. }
  548. if (msg.role === "ai" || msg.role === "assistant") {
  549. if (String(msg.content || "").trim()) count += 1;
  550. }
  551. }
  552. return count;
  553. }
  554. function parseMessagesFromContent(text) {
  555. var raw = String(text || "").trim();
  556. if (!raw) return [];
  557. var list = [];
  558. var blocks = raw.split(/\n\n+/);
  559. for (var i = 0; i < blocks.length; i++) {
  560. var block = String(blocks[i] || "").trim();
  561. if (!block) continue;
  562. var userMatch = block.match(/^我[::]\s*([\s\S]*)$/);
  563. if (userMatch) {
  564. var userText = String(userMatch[1] || "").trim();
  565. if (userText) list.push({ role: "user", content: userText });
  566. continue;
  567. }
  568. var aiMatch = block.match(/^UBAO[::]\s*([\s\S]*)$/i);
  569. if (aiMatch) {
  570. var aiText = String(aiMatch[1] || "").trim();
  571. if (aiText) list.push({ role: "ai", content: aiText });
  572. }
  573. }
  574. if (list.length) return list;
  575. var current = null;
  576. var lines = raw.split(/\n/);
  577. for (var j = 0; j < lines.length; j++) {
  578. var line = String(lines[j] || "");
  579. var userLine = line.match(/^我[::]\s*(.*)$/);
  580. var aiLine = line.match(/^UBAO[::]\s*(.*)$/i);
  581. if (userLine) {
  582. if (current) list.push(current);
  583. current = { role: "user", content: String(userLine[1] || "").trim() };
  584. continue;
  585. }
  586. if (aiLine) {
  587. if (current) list.push(current);
  588. current = { role: "ai", content: String(aiLine[1] || "").trim() };
  589. continue;
  590. }
  591. if (current && line.trim()) {
  592. current.content = (current.content ? current.content + "\n" : "") + line.trim();
  593. }
  594. }
  595. if (current && String(current.content || "").trim()) list.push(current);
  596. return list;
  597. }
  598. function resolveShareMessagesForDisplay(data) {
  599. var fromArray = Array.isArray(data && data.messages) ? data.messages : [];
  600. var fromContent = parseMessagesFromContent((data && data.content) || "");
  601. var arrayCount = countDisplayableMessages(fromArray);
  602. var contentCount = countDisplayableMessages(fromContent);
  603. // 分享链接超长时 messages 会被截断,但 content 仍保留完整对话文本
  604. if (contentCount > arrayCount) return fromContent;
  605. if (arrayCount) return fromArray;
  606. return fromContent;
  607. }
  608. function render(data) {
  609. applyWeixinShareMeta();
  610. sharePayloadCache = data || null;
  611. var main = document.getElementById("main");
  612. if (!data) {
  613. main.innerHTML = '<div class="empty">对话内容不存在或链接已失效</div>';
  614. refreshWxLaunchTagAttrs();
  615. return;
  616. }
  617. var messages = resolveShareMessagesForDisplay(data);
  618. var firstQuestion =
  619. String(data.firstQuestion || "").trim() ||
  620. getFirstUserQuestion(messages) ||
  621. (function () {
  622. var text = String(data.content || "").trim();
  623. var m = text.match(/^我[::]([\s\S]+?)(?:\n\n|$)/);
  624. return m ? String(m[1] || "").trim() : "";
  625. })();
  626. var pageTitle = formatDiscussionTitle(firstQuestion);
  627. var dateText = formatDate(data.shareTime);
  628. document.title = pageTitle;
  629. var bodyHtml =
  630. '<section class="hero">' +
  631. '<h1 class="hero__title">' +
  632. escHtml(pageTitle) +
  633. "</h1>" +
  634. '<p class="hero__meta">' +
  635. escHtml(dateText) +
  636. " · 内容由AI生成,不能完全保障真实</p>" +
  637. '<div class="hero__divider"></div>' +
  638. "</section>";
  639. var convHtml = renderMessages(messages);
  640. if (convHtml) {
  641. bodyHtml +=
  642. '<section class="conversation">' +
  643. convHtml +
  644. '</section><div class="scroll-spacer" aria-hidden="true"></div>';
  645. } else {
  646. bodyHtml += '<div class="empty">暂无对话内容</div>';
  647. }
  648. main.innerHTML = bodyHtml;
  649. refreshWxLaunchTagAttrs();
  650. }
  651. function buildAiConsultOpenParams() {
  652. var params = new URLSearchParams();
  653. params.set("pageType", "home");
  654. params.set("fromShareAiConsult", "1");
  655. return params;
  656. }
  657. function buildAppDeepLink() {
  658. var path = APP_UNI_AI_PATH;
  659. var qs = buildAiConsultOpenParams().toString();
  660. var root = APP_IOS_URL_SCHEME.replace(/\/$/, "");
  661. return root + "/" + path + (qs ? "?" + qs : "");
  662. }
  663. function buildWeChatLaunchExtinfo(useBarePathOnly) {
  664. var path = APP_UNI_AI_PATH.replace(/^\//, "");
  665. if (useBarePathOnly) return path;
  666. var qs = buildAiConsultOpenParams().toString();
  667. var uniPage = qs ? path + "?" + qs : path;
  668. if (uniPage.length <= 1024) return uniPage;
  669. return path + "?pageType=home&fromShareAiConsult=1";
  670. }
  671. function isWeChatInAppBrowser() {
  672. return /MicroMessenger/i.test(navigator.userAgent || "");
  673. }
  674. function getWxShareEntryFrom() {
  675. var from = q("from");
  676. if (from) return String(from).trim().toLowerCase();
  677. try {
  678. var h = location.hash || "";
  679. var qi = h.indexOf("?");
  680. if (qi >= 0) {
  681. var hf = new URLSearchParams(h.slice(qi + 1)).get("from");
  682. if (hf) return String(hf).trim().toLowerCase();
  683. }
  684. } catch (eH) {}
  685. return "";
  686. }
  687. function logWxEntryDiagnostics() {
  688. if (!isWeChatInAppBrowser()) return;
  689. console.log("[wx-entry]", {
  690. entryFrom: getWxShareEntryFrom() || "(无)",
  691. wxJssdkReady: weChatJssdkConfigured,
  692. signUrl: getWxConfigSignUrl(),
  693. });
  694. }
  695. function isIOSWeChatBrowser() {
  696. var ua = navigator.userAgent || "";
  697. return /MicroMessenger/i.test(ua) && /iPhone|iPad|iPod/i.test(ua);
  698. }
  699. function isWxDebugOn() {
  700. return q("wxDebug") === "1";
  701. }
  702. function isWxForceDebug() {
  703. return q("wxForce") === "1";
  704. }
  705. function isWxConfigOnClickDebug() {
  706. return q("wxConfigOnClick") === "1";
  707. }
  708. function isWxPcAutoDebugHost() {
  709. var h = (location.hostname || "").toLowerCase();
  710. if (h === "localhost" || h === "127.0.0.1") return true;
  711. for (var i = 0; i < WECHAT_JS_SAFE_HOSTS.length; i++) {
  712. if (WECHAT_JS_SAFE_HOSTS[i] === h) return true;
  713. }
  714. return false;
  715. }
  716. function isWxPcBrowser() {
  717. return !isWeChatInAppBrowser();
  718. }
  719. function shouldInitWeChatJssdkOnLoad() {
  720. if (isWeChatInAppBrowser()) return true;
  721. return isWxForceDebug() || isWxPcAutoDebugHost();
  722. }
  723. function shouldFetchWxConfig(fromUserClick) {
  724. if (isWeChatInAppBrowser()) return true;
  725. if (fromUserClick) return true;
  726. return isWxForceDebug() || isWxPcAutoDebugHost();
  727. }
  728. function getWxHtmlUrl() {
  729. var forced = String(q("wxSignUrl") || "").trim();
  730. if (forced) return forced.split("#")[0];
  731. return String(location.href || "").split("#")[0];
  732. }
  733. function getWxSignPageUrlForApi() {
  734. var htmlUrl = getWxHtmlUrl();
  735. if (htmlUrl && /^https?:\/\//i.test(htmlUrl)) return htmlUrl;
  736. return WX_GET_CONFIG_SIGN_URL;
  737. }
  738. function getWxHtmlUrlBase() {
  739. var htmlUrl = getWxSignPageUrlForApi();
  740. try {
  741. var u = new URL(htmlUrl);
  742. return u.origin + u.pathname;
  743. } catch (eU) {
  744. return WX_GET_CONFIG_SIGN_URL;
  745. }
  746. }
  747. /** 默认 pathname 验签:AI 分享链常带超长 payload,与后端无参签名一致,避免开放标签 fail_check */
  748. function getWxConfigSignUrl() {
  749. if (String(q("wxSignFullUrl") || "") === "1") return getWxSignPageUrlForApi();
  750. if (String(q("wxSignBaseOnly") || "") === "1") return getWxHtmlUrlBase();
  751. if (isWeChatInAppBrowser()) return getWxHtmlUrlBase();
  752. return getWxSignPageUrlForApi();
  753. }
  754. function getWxGetConfigApiUrl() {
  755. return API_BASE.replace(/\/$/, "") + WECHAT_GET_WX_CONFIG_PATH;
  756. }
  757. function buildWxGetConfigRequestBody(htmlUrl) {
  758. return {
  759. url: String(htmlUrl || "").split("#")[0].trim(),
  760. };
  761. }
  762. function resolveWxConfigAppIdFromSignData(d) {
  763. if (!d || typeof d !== "object") return "";
  764. var mp =
  765. d.mpAppId ||
  766. d.mpAppid ||
  767. d.officialAppId ||
  768. d.gzhAppId ||
  769. d.serviceAppId;
  770. if (mp != null && String(mp).trim() !== "") return String(mp).trim();
  771. var fromQuery = String(q("wxMpAppId") || WECHAT_MP_APP_ID || "").trim();
  772. if (fromQuery) return fromQuery;
  773. var raw = d.appId || d.appid || d.wxAppId;
  774. return raw != null && String(raw).trim() !== "" ? String(raw).trim() : "";
  775. }
  776. function normalizeWxJssdkSignPayload(res, signUrlUsed) {
  777. if (!res || typeof res !== "object") return null;
  778. var d = res.data != null && typeof res.data === "object" ? res.data : res;
  779. if (!d || typeof d !== "object") return null;
  780. var appId = resolveWxConfigAppIdFromSignData(d);
  781. var timestamp = d.timestamp != null ? d.timestamp : d.timeStamp;
  782. var nonceStr =
  783. d.nonceStr != null && String(d.nonceStr) !== ""
  784. ? d.nonceStr
  785. : d.noncestr != null && String(d.noncestr) !== ""
  786. ? d.noncestr
  787. : d.nonce;
  788. var signature = d.signature || d.sign;
  789. if (!appId || timestamp == null || nonceStr == null || nonceStr === "" || !signature) {
  790. return null;
  791. }
  792. return {
  793. appId: String(appId),
  794. timestamp: Number(timestamp),
  795. nonceStr: String(nonceStr),
  796. signature: String(signature),
  797. signUrl: String(signUrlUsed || "")
  798. .split("#")[0]
  799. .trim(),
  800. };
  801. }
  802. function getWxErrMsg(err) {
  803. if (!err) return "";
  804. if (err.errMsg) return String(err.errMsg);
  805. if (typeof err === "string") return err;
  806. try {
  807. return JSON.stringify(err);
  808. } catch (e) {
  809. return String(err);
  810. }
  811. }
  812. function formatWxConfigErrorTip(err, signPageUrl) {
  813. var errMsg = getWxErrMsg(err);
  814. var tip = "微信 JSSDK 配置失败";
  815. if (/invalid signature/i.test(errMsg)) {
  816. return (
  817. tip +
  818. ":签名无效。请核对:①后端用与前端相同的 url 签名;②url=" +
  819. (signPageUrl || getWxHtmlUrl()) +
  820. ";③nonceStr/timestamp 与接口返回一致;④appId=" +
  821. WECHAT_MP_APP_ID
  822. );
  823. }
  824. if (/require\s*subscribe/i.test(errMsg)) {
  825. return tip + ":" + errMsg + "(服务号需用户已关注)";
  826. }
  827. return errMsg ? tip + ":" + errMsg : tip;
  828. }
  829. function setWxInitError(msg) {
  830. wxInitLastError = String(msg || "").trim();
  831. if (wxInitLastError) console.warn("[wx]", wxInitLastError);
  832. }
  833. function requestWeChatJssdkSignAndConfig(htmlUrlOptional) {
  834. var htmlUrl = String(htmlUrlOptional != null ? htmlUrlOptional : getWxConfigSignUrl())
  835. .split("#")[0]
  836. .trim();
  837. if (!htmlUrl || !/^https?:\/\//i.test(htmlUrl)) {
  838. htmlUrl = WX_GET_CONFIG_SIGN_URL;
  839. }
  840. if (isWxDebugOn()) {
  841. try {
  842. window.alert("htmlUrl(签名用,应与地址栏一致):\n" + htmlUrl);
  843. } catch (eDbg) {}
  844. }
  845. var requestUrl = getWxGetConfigApiUrl();
  846. var requestBody = buildWxGetConfigRequestBody(htmlUrl);
  847. return fetch(requestUrl, {
  848. method: "POST",
  849. mode: "cors",
  850. credentials: "omit",
  851. headers: {
  852. Accept: "application/json",
  853. "Content-Type": "application/json;charset=UTF-8",
  854. },
  855. body: JSON.stringify(requestBody),
  856. })
  857. .then(function (r) {
  858. if (r.ok) return r.json();
  859. return r
  860. .text()
  861. .catch(function () {
  862. return "";
  863. })
  864. .then(function (text) {
  865. var hint = "";
  866. try {
  867. var j = JSON.parse(text);
  868. hint = j.msg || j.message || "";
  869. } catch (eP) {
  870. if (text) hint = text.slice(0, 120);
  871. }
  872. throw new Error("getWxConfig HTTP " + r.status + (hint ? ":" + hint : ""));
  873. });
  874. })
  875. .then(function (res) {
  876. if (res && res.code != null) {
  877. var c = Number(res.code);
  878. if (c !== 200 && c !== 0 && res.success !== true) {
  879. throw new Error(res.msg || res.message || "getWxConfig code " + c);
  880. }
  881. }
  882. var sign = normalizeWxJssdkSignPayload(res, htmlUrl);
  883. if (!sign) {
  884. throw new Error("getWxConfig 缺少 appId/timestamp/nonceStr/signature(见控制台)");
  885. }
  886. if (typeof wx === "undefined") {
  887. if (isWxPcBrowser()) {
  888. console.log("[wx] PC getWxConfig 成功(无 jweixin)", sign);
  889. return true;
  890. }
  891. setWxInitError("jweixin.js 未加载");
  892. return false;
  893. }
  894. return applyWxConfigFromSign(sign, htmlUrl);
  895. });
  896. }
  897. function applyWxConfigFromSign(sign, htmlUrl) {
  898. var wxConfigParams = {
  899. debug: isWxDebugOn(),
  900. appId: String(sign.appId),
  901. timestamp: sign.timestamp,
  902. nonceStr: String(sign.nonceStr),
  903. signature: String(sign.signature),
  904. jsApiList: [],
  905. openTagList: ["wx-open-launch-app"],
  906. };
  907. return new Promise(function (resolve) {
  908. wx.config(wxConfigParams);
  909. wx.ready(function () {
  910. weChatJssdkConfigured = true;
  911. document.body.classList.add("wx-jssdk-ready");
  912. refreshWxLaunchTagAttrs();
  913. console.log("[wx.config] ready, htmlUrl=", htmlUrl);
  914. resolve(true);
  915. });
  916. wx.error(function (err) {
  917. weChatJssdkConfigured = false;
  918. document.body.classList.remove("wx-jssdk-ready");
  919. wxJssdkInitPromise = null;
  920. var errMsg = getWxErrMsg(err);
  921. setWxInitError(formatWxConfigErrorTip(err, htmlUrl));
  922. if (isWxDebugOn()) window.alert(wxInitLastError);
  923. console.warn("[wx.config]", errMsg, "htmlUrl=", htmlUrl);
  924. var baseUrl = getWxHtmlUrlBase();
  925. var fullUrl = getWxSignPageUrlForApi();
  926. if (
  927. !/invalid signature/i.test(errMsg) ||
  928. wxConfigSignRetriedBaseUrl ||
  929. baseUrl === fullUrl ||
  930. htmlUrl === baseUrl
  931. ) {
  932. resolve(false);
  933. return;
  934. }
  935. wxConfigSignRetriedBaseUrl = true;
  936. requestWeChatJssdkSignAndConfig(baseUrl).then(resolve);
  937. });
  938. });
  939. }
  940. function refreshWxLaunchTagAttrs(useBarePathOnly) {
  941. var tag = document.getElementById("launch-btn");
  942. if (!tag) return;
  943. try {
  944. tag.setAttribute("appid", WECHAT_OPEN_APP_ID);
  945. tag.setAttribute("extinfo", buildWeChatLaunchExtinfo(!!useBarePathOnly));
  946. console.log("[wx-open-launch-app] extinfo=", tag.getAttribute("extinfo"));
  947. } catch (eA) {}
  948. }
  949. function bindWeChatLaunchTagEvents() {
  950. var tag = document.getElementById("launch-btn");
  951. if (!tag || tag._wxLaunchBound) return;
  952. tag._wxLaunchBound = true;
  953. refreshWxLaunchTagAttrs();
  954. tag.addEventListener("launch", function () {
  955. console.log("[wx-open-launch-app] launch ok");
  956. });
  957. tag.addEventListener("error", function (e) {
  958. var detail = e && e.detail;
  959. var errMsg =
  960. detail && detail.errMsg
  961. ? String(detail.errMsg)
  962. : detail && detail.errmsg
  963. ? String(detail.errmsg)
  964. : "";
  965. console.warn(
  966. "[wx-open-launch-app]",
  967. detail,
  968. "extinfo=",
  969. tag.getAttribute("extinfo")
  970. );
  971. if (/launch:fail_check/i.test(errMsg)) {
  972. showAppOpenFailTip(
  973. "请用微信分享卡片进入,或确认已安装最新版「U店在哪」"
  974. );
  975. return;
  976. }
  977. if (
  978. /launch:fail/i.test(errMsg) &&
  979. !tag._wxLaunchBareRetried &&
  980. tag.getAttribute("extinfo") !== buildWeChatLaunchExtinfo(true)
  981. ) {
  982. tag._wxLaunchBareRetried = true;
  983. refreshWxLaunchTagAttrs(true);
  984. showFabToast("请再点一次「APP内打开」");
  985. return;
  986. }
  987. if (/launch:fail/i.test(errMsg) && !getWxShareEntryFrom()) {
  988. showAppOpenFailTip(
  989. "当前环境无法直接打开 App,请使用 App「分享到微信」后点分享卡片进入"
  990. );
  991. return;
  992. }
  993. showAppOpenFailTip(
  994. errMsg
  995. ? "未能打开 App:" + errMsg
  996. : "未能打开 App,请确认已安装最新版「U店在哪」"
  997. );
  998. });
  999. }
  1000. function initWeChatOpenLaunchApp(fromUserClick) {
  1001. if (!shouldFetchWxConfig(!!fromUserClick)) {
  1002. return Promise.resolve(false);
  1003. }
  1004. if (wxJssdkInitPromise && !fromUserClick) return wxJssdkInitPromise;
  1005. wxConfigSignRetriedBaseUrl = false;
  1006. wxInitLastError = "";
  1007. var htmlUrl = getWxConfigSignUrl();
  1008. bindWeChatLaunchTagEvents();
  1009. wxJssdkInitPromise = requestWeChatJssdkSignAndConfig(htmlUrl)
  1010. .then(function (ok) {
  1011. if (ok === true) return true;
  1012. if (!wxInitLastError) {
  1013. setWxInitError("wx.config 失败,可加 ?wxDebug=1 查看 htmlUrl");
  1014. }
  1015. return false;
  1016. })
  1017. .catch(function (e) {
  1018. var msg = e && e.message ? e.message : "getWxConfig 请求失败";
  1019. setWxInitError(msg);
  1020. console.warn("[wx] requestWeChatJssdkSignAndConfig failed", msg, "htmlUrl=", htmlUrl);
  1021. if (isWeChatInAppBrowser() && isWxDebugOn()) window.alert(msg);
  1022. return false;
  1023. })
  1024. .finally(function () {
  1025. if (!weChatJssdkConfigured) wxJssdkInitPromise = null;
  1026. });
  1027. return wxJssdkInitPromise;
  1028. }
  1029. function scheduleWeChatJssdkBootstrap() {
  1030. if (!shouldInitWeChatJssdkOnLoad()) return;
  1031. var attempts = 0;
  1032. function tick() {
  1033. attempts += 1;
  1034. if (weChatJssdkConfigured) return;
  1035. initWeChatOpenLaunchApp();
  1036. if (!weChatJssdkConfigured && attempts < 8 && typeof wx === "undefined") {
  1037. setTimeout(tick, 400);
  1038. }
  1039. }
  1040. if (isIOSWeChatBrowser()) {
  1041. setTimeout(tick, 350);
  1042. } else {
  1043. tick();
  1044. }
  1045. }
  1046. function showFabToast(msg, ms) {
  1047. var tip = String(msg || "").trim();
  1048. if (!tip) return;
  1049. var el = document.getElementById("openAppToast");
  1050. if (el) {
  1051. el.textContent = tip;
  1052. el.style.display = "block";
  1053. if (showFabToast._t) clearTimeout(showFabToast._t);
  1054. showFabToast._t = setTimeout(function () {
  1055. el.style.display = "none";
  1056. }, ms || 2800);
  1057. }
  1058. console.log("[openApp]", tip);
  1059. }
  1060. function showDownloadTip() {
  1061. var msg = "请到应用商店下载「U店在哪」";
  1062. if (typeof uni !== "undefined" && typeof uni.showToast === "function") {
  1063. uni.showToast({ title: msg, icon: "none", duration: 2500 });
  1064. } else {
  1065. window.alert(msg);
  1066. }
  1067. }
  1068. function showAppOpenFailTip(msg) {
  1069. var tip = msg || "未能打开 App,请确认已安装最新版「U店在哪」。";
  1070. if (typeof uni !== "undefined" && typeof uni.showToast === "function") {
  1071. uni.showToast({ title: msg, icon: "none", duration: 2800 });
  1072. } else if (isWeChatInAppBrowser()) {
  1073. window.alert(tip);
  1074. } else {
  1075. showFabToast(tip);
  1076. }
  1077. }
  1078. function launchAppDeepLink(deepLink) {
  1079. try {
  1080. var a = document.createElement("a");
  1081. a.href = deepLink;
  1082. a.setAttribute("target", "_self");
  1083. document.body.appendChild(a);
  1084. a.click();
  1085. document.body.removeChild(a);
  1086. } catch (e1) {}
  1087. try {
  1088. window.location.href = deepLink;
  1089. } catch (e2) {}
  1090. }
  1091. function tryOpenHBuilderAppViaScheme() {
  1092. var deepLink = buildAppDeepLink();
  1093. if (typeof plus !== "undefined" && plus.runtime) {
  1094. var installed = null;
  1095. try {
  1096. if (typeof plus.runtime.isApplicationExist === "function") {
  1097. installed = plus.runtime.isApplicationExist({
  1098. pname: APP_ANDROID_PACKAGE,
  1099. action: APP_IOS_URL_SCHEME,
  1100. });
  1101. }
  1102. } catch (e) {
  1103. console.warn(e);
  1104. }
  1105. if (installed === false) {
  1106. showDownloadTip();
  1107. return;
  1108. }
  1109. try {
  1110. plus.runtime.openURL(deepLink);
  1111. } catch (e2) {
  1112. console.warn(e2);
  1113. showDownloadTip();
  1114. }
  1115. return;
  1116. }
  1117. var done = false;
  1118. function finish() {
  1119. if (done) return;
  1120. done = true;
  1121. document.removeEventListener("visibilitychange", onVis);
  1122. window.removeEventListener("pagehide", onHide);
  1123. }
  1124. function onVis() {
  1125. if (document.visibilityState === "hidden") finish();
  1126. }
  1127. function onHide() {
  1128. finish();
  1129. }
  1130. document.addEventListener("visibilitychange", onVis);
  1131. window.addEventListener("pagehide", onHide);
  1132. try {
  1133. launchAppDeepLink(deepLink);
  1134. } catch (e3) {
  1135. finish();
  1136. showDownloadTip();
  1137. return;
  1138. }
  1139. window.setTimeout(function () {
  1140. finish();
  1141. }, 3200);
  1142. }
  1143. function tryFetchWxConfigOnPcClick() {
  1144. if (!isWxPcBrowser()) return Promise.resolve(false);
  1145. showFabToast("正在请求 getWxConfig…");
  1146. wxJssdkInitPromise = null;
  1147. return initWeChatOpenLaunchApp(true).then(function (ok) {
  1148. if (ok) {
  1149. showFabToast(
  1150. weChatJssdkConfigured
  1151. ? "getWxConfig 成功,wx.config 已就绪"
  1152. : "getWxConfig 成功"
  1153. );
  1154. } else {
  1155. showFabToast(wxInitLastError || "getWxConfig 失败");
  1156. }
  1157. return ok;
  1158. });
  1159. }
  1160. function tryOpenHBuilderApp() {
  1161. if (isWeChatInAppBrowser()) return;
  1162. tryFetchWxConfigOnPcClick().then(function () {
  1163. if (isWxConfigOnClickDebug() && !isWxForceDebug() && !isWxPcAutoDebugHost()) {
  1164. return;
  1165. }
  1166. tryOpenHBuilderAppViaScheme();
  1167. });
  1168. }
  1169. function boot() {
  1170. var launchTag = document.getElementById("launch-btn");
  1171. if (launchTag) launchTag.setAttribute("appid", WECHAT_OPEN_APP_ID);
  1172. bindWeChatLaunchTagEvents();
  1173. if (isWeChatInAppBrowser()) {
  1174. document.body.classList.add("is-wechat");
  1175. logWxEntryDiagnostics();
  1176. }
  1177. if (shouldInitWeChatJssdkOnLoad()) {
  1178. if (isWxPcBrowser() && (isWxForceDebug() || isWxPcAutoDebugHost())) {
  1179. document.body.classList.add("wx-pc-debug");
  1180. }
  1181. scheduleWeChatJssdkBootstrap();
  1182. }
  1183. document.addEventListener("WeixinOpenTagsError", function (e) {
  1184. console.warn("[WeixinOpenTagsError]", e && e.detail);
  1185. });
  1186. var openBtnWx = document.getElementById("openApp");
  1187. if (openBtnWx) {
  1188. if (isWeChatInAppBrowser()) {
  1189. openBtnWx.addEventListener("click", function () {
  1190. if (!weChatJssdkConfigured) {
  1191. showFabToast(
  1192. wxInitLastError || "微信 SDK 初始化中,请稍候再点底部按钮"
  1193. );
  1194. }
  1195. });
  1196. } else {
  1197. openBtnWx.addEventListener("click", tryOpenHBuilderApp);
  1198. }
  1199. }
  1200. render(parsePayload());
  1201. }
  1202. if (document.readyState === "complete") {
  1203. boot();
  1204. } else {
  1205. window.addEventListener("load", boot);
  1206. }
  1207. })();
  1208. </script>
  1209. </body>
  1210. </html>