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