shareAiConsult.html 43 KB

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