sunshibo vor 1 Woche
Ursprung
Commit
346dab0be2
1 geänderte Dateien mit 31 neuen und 15 gelöschten Zeilen
  1. 31 15
      HBuilderProjects/shareIndex.html

+ 31 - 15
HBuilderProjects/shareIndex.html

@@ -1018,10 +1018,10 @@
 		 * 请用本地 HTTP 打开(如 VS Code Live Server、npx serve)或让后端为 H5 域名配置 Access-Control-Allow-Origin。
 		 */
 		var API_BASE = 'https://test.ailien.shop/alienStore';
-		/** 公众号内 JS-SDK 签名:GET …/wx/getWxConfig?url=当前页地址(不含 #) */
-		var WX_CONFIG_API = 'https://test.ailien.shop/wx/getWxConfig';
-		/** 微信开放平台「移动应用」AppID;若 getWxConfig 未返回 launchAppId 等字段则使用此值 */
-		var WX_LAUNCH_APP_ID = '';
+		/** 公众号内 JS-SDK 签名:GET …/alienStore/wx/getWxConfig?url=当前页地址(不含 #) */
+		var WX_CONFIG_API = 'https://test.ailien.shop/alienStore/wx/getWxConfig';
+		/** 微信开放平台「移动应用」AppID(wx-open-launch-app 的 appid);接口未返回 launchAppId 时用此值 */
+		var WX_LAUNCH_APP_ID = 'wxf5f1efe3a9f5012e';
 
 		/**
 		 * 关店(businessStatus=99)更多推荐:POST …/ai/multimodal-services/api/v1/search/global/store-recommend
@@ -1199,13 +1199,17 @@
 				d.wxAppId ||
 				WX_LAUNCH_APP_ID ||
 				'';
-			if (!appId || !signature || timestamp == null || !nonceStr) return null;
+			if (!appId || !signature || timestamp == null || !nonceStr) {
+				console.warn('[getWxConfig] 签名字段缺失', d);
+				return null;
+			}
+			var launchId = String(launchAppId || WX_LAUNCH_APP_ID || '');
 			return {
 				appId: String(appId),
 				timestamp: Number(timestamp) || 0,
 				nonceStr: String(nonceStr),
 				signature: String(signature),
-				launchAppId: String(launchAppId || '')
+				launchAppId: launchId
 			};
 		}
 
@@ -1230,7 +1234,8 @@
 					resolve(cfg);
 				});
 				wx.error(function (err) {
-					reject(err || new Error('wx.config 失败'));
+					var detail = err && (err.errMsg || err.errmsg) ? String(err.errMsg || err.errmsg) : '';
+					reject(new Error('wx.config 失败' + (detail ? ':' + detail : '')));
 				});
 			});
 		}
@@ -1256,7 +1261,7 @@
 			if (wxLaunchMounted && host.querySelector('wx-open-launch-app')) return true;
 
 			var extinfo = escapeHtmlAttr(buildAppExtInfo());
-			var appid = "wxf5f1efe3a9f5012e";
+			var appid = escapeHtmlAttr(launchAppId);
 			host.innerHTML =
 				'<wx-open-launch-app id="wxOpenLaunchApp" appid="' +
 				appid +
@@ -1311,9 +1316,12 @@
 					return applyWxConfig(cfg);
 				})
 				.then(function (cfg) {
-					var launchId = (cfg && cfg.launchAppId) || wxLaunchAppIdCache;
+					var launchId =
+						(cfg && cfg.launchAppId) || wxLaunchAppIdCache || WX_LAUNCH_APP_ID || '';
 					if (!launchId) throw new Error('缺少移动应用 AppId');
-					mountWxOpenLaunchApp(launchId);
+					if (!mountWxOpenLaunchApp(launchId)) {
+						throw new Error('微信开放标签挂载失败');
+					}
 					return cfg;
 				});
 			return wxPreparePromise;
@@ -1332,15 +1340,23 @@
 					}
 				})
 				.catch(function (e) {
-					console.warn('[微信唤起App]', e);
+					console.warn('[微信唤起App]', e, {
+						signUrl: getWxSignPageUrl(),
+						wxConfigReady: wxConfigReady,
+						wxLaunchMounted: wxLaunchMounted
+					});
 					var msg = '暂时无法打开 App';
 					if (e && e.message) {
 						if (/HTTP 404/i.test(e.message)) {
-							msg = '微信配置接口不可用,请联系管理员';
+							msg = '微信配置接口 404,请确认接口为 /alienStore/wx/getWxConfig';
 						} else if (/缺少移动应用/i.test(e.message)) {
-							msg = '缺少移动应用 AppId,请在 getWxConfig 返回 launchAppId';
-						} else if (/getWxConfig|签名|wx\.config/i.test(e.message)) {
-							msg = '微信签名失败,请确认 JS 安全域名与页面 URL 一致';
+							msg = '缺少移动应用 AppId,请配置 WX_LAUNCH_APP_ID';
+						} else if (/getWxConfig 返回无效/i.test(e.message)) {
+							msg = 'getWxConfig 数据无效,请查看控制台 [getWxConfig]';
+						} else if (/wx\.config|签名/i.test(e.message)) {
+							msg = '微信签名失败:页面域名须与 JS 安全域名一致(' + getWxSignPageUrl() + ')';
+						} else if (/挂载失败/i.test(e.message)) {
+							msg = '开放标签挂载失败,请用微信打开并重试';
 						}
 					}
 					showWxLaunchTip(msg);