shareAiConsult.html 42 KB

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