shareAiConsult.html 42 KB

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