shareAiConsult.html 42 KB

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