sunshibo 1 неделя назад
Родитель
Сommit
c9e36dc27a

+ 56 - 27
HBuilderProjects/secondShareGoods.html

@@ -73,11 +73,12 @@
 			opacity: 1;
 		}
 
-		body.is-wechat.wx-jssdk-ready #launch-btn {
+		/* 仅分享卡片等场景展示开放标签;复制链接进入见 .wx-copy-link-entry */
+		body.is-wechat.wx-jssdk-ready.wx-open-tag-scene #launch-btn {
 			display: block;
 		}
 
-		body.is-wechat.wx-jssdk-ready #openApp {
+		body.is-wechat.wx-jssdk-ready.wx-open-tag-scene #openApp {
 			display: none !important;
 		}
 
@@ -796,39 +797,55 @@
 			return /MicroMessenger/i.test(navigator.userAgent || '');
 		}
 
+		function getWxShareEntryFrom() {
+			var from = q('from');
+			return from ? String(from).trim().toLowerCase() : '';
+		}
+
 		/**
-		 * 复制链接进入常无 from=;与点击分享卡片对齐,在拉 getWxConfig 前补 from=singlemessage(不刷新页面)。
+		 * wx-open-launch-app 仅在分享卡片等场景可用;复制链接打开会 launch:fail。
+		 * 勿在 getWxConfig 前改地址栏(iOS 微信按进入时 url 验签,replaceState 会导致签名无效)。
 		 */
-		function ensureWxShareFromQueryBeforeConfig() {
-			if (!isWeChatInAppBrowser()) return;
-			var from = String(q('from') || '').trim();
-			if (from) return;
-			try {
-				var u = new URL(location.href);
-				u.searchParams.set('from', 'singlemessage');
-				history.replaceState(null, '', u.pathname + u.search + (location.hash || ''));
-			} catch (eFrom) {
-				var sep = location.search && location.search.length > 1 ? '&' : '?';
-				history.replaceState(
-					null,
-					'',
-					location.pathname +
-						(location.search || '') +
-						sep +
-						'from=singlemessage' +
-						(location.hash || '')
-				);
+		function isWxOpenLaunchAppSceneSupported() {
+			if (!isWeChatInAppBrowser()) return false;
+			if (readQueryParam('wxOpenTag') === '1' || readQueryParam('wxForceOpenTag') === '1') {
+				return true;
 			}
+			var from = getWxShareEntryFrom();
+			return (
+				from === 'singlemessage' ||
+				from === 'groupmessage' ||
+				from === 'timeline'
+			);
+		}
+
+		function applyWxOpenLaunchSceneBodyClass() {
+			if (!isWeChatInAppBrowser()) return;
+			var ok = isWxOpenLaunchAppSceneSupported();
+			document.body.classList.toggle('wx-open-tag-scene', ok);
+			document.body.classList.toggle('wx-copy-link-entry', !ok);
 		}
 
 		function logWxEntryDiagnostics() {
 			if (!isWeChatInAppBrowser()) return;
 			console.log('[wx-entry]', {
-				entryFrom: q('from') || '(无)',
+				entryFrom: getWxShareEntryFrom() || '(无,多为复制链接进入)',
+				openLaunchTagScene: isWxOpenLaunchAppSceneSupported(),
 				signUrl: getWxConfigSignUrl()
 			});
 		}
 
+		function showWxCopyLinkEntryTip() {
+			showFabToast(
+				'当前为复制链接进入,微信不支持直接打开 App。请使用 App「分享到微信」发送卡片后,点卡片进入。'
+			);
+		}
+
+		function isIOSWeChatBrowser() {
+			var ua = navigator.userAgent || '';
+			return /MicroMessenger/i.test(ua) && /iPhone|iPad|iPod/i.test(ua);
+		}
+
 		function readQueryParam(name) {
 			return q(name);
 		}
@@ -1074,7 +1091,10 @@
 				wx.ready(function () {
 					weChatJssdkConfigured = true;
 					document.body.classList.add('wx-jssdk-ready');
-					refreshWxLaunchTagAttrs();
+					applyWxOpenLaunchSceneBodyClass();
+					if (isWxOpenLaunchAppSceneSupported()) {
+						refreshWxLaunchTagAttrs();
+					}
 					console.log('[wx.config] ready, htmlUrl=', htmlUrl);
 					resolve(true);
 				});
@@ -1140,7 +1160,6 @@
 			if (!shouldFetchWxConfig(!!fromUserClick)) {
 				return Promise.resolve(false);
 			}
-			ensureWxShareFromQueryBeforeConfig();
 			if (wxJssdkInitPromise && !fromUserClick) return wxJssdkInitPromise;
 			wxConfigSignRetriedBaseUrl = false;
 			wxInitLastError = '';
@@ -1178,7 +1197,12 @@
 					setTimeout(tick, 400);
 				}
 			}
-			tick();
+			/* iOS 微信分享卡片可能稍后才写入 from 等参数,过早验签会 invalid signature */
+			if (isIOSWeChatBrowser()) {
+				setTimeout(tick, 350);
+			} else {
+				tick();
+			}
 		}
 
 		function showFabToast(msg, ms) {
@@ -2106,7 +2130,7 @@
 			bindWeChatLaunchTagEvents();
 			if (isWeChatInAppBrowser()) {
 				document.body.classList.add('is-wechat');
-				ensureWxShareFromQueryBeforeConfig();
+				applyWxOpenLaunchSceneBodyClass();
 				logWxEntryDiagnostics();
 			}
 			if (shouldInitWeChatJssdkOnLoad()) {
@@ -2118,6 +2142,7 @@
 
 			document.addEventListener('WeixinOpenTagsError', function (e) {
 				console.warn('[WeixinOpenTagsError]', e && e.detail);
+				applyWxOpenLaunchSceneBodyClass();
 			});
 
 			if (isWeChatInAppBrowser()) {
@@ -2128,6 +2153,10 @@
 							showFabToast(
 								wxInitLastError || '微信 SDK 初始化中,请稍候再点底部按钮'
 							);
+							return;
+						}
+						if (!isWxOpenLaunchAppSceneSupported()) {
+							showWxCopyLinkEntryTip();
 						}
 					});
 				}

+ 51 - 26
HBuilderProjects/shareCheckIn.html

@@ -322,11 +322,11 @@
 			opacity: 1;
 		}
 
-		body.is-wechat.wx-jssdk-ready #launch-btn {
+		body.is-wechat.wx-jssdk-ready.wx-open-tag-scene #launch-btn {
 			display: block;
 		}
 
-		body.is-wechat.wx-jssdk-ready #openApp {
+		body.is-wechat.wx-jssdk-ready.wx-open-tag-scene #openApp {
 			display: none !important;
 		}
 
@@ -795,36 +795,51 @@
 			return /MicroMessenger/i.test(navigator.userAgent || '');
 		}
 
-		function ensureWxShareFromQueryBeforeConfig() {
-			if (!isWeChatInAppBrowser()) return;
-			var from = String(q('from') || '').trim();
-			if (from) return;
-			try {
-				var u = new URL(location.href);
-				u.searchParams.set('from', 'singlemessage');
-				history.replaceState(null, '', u.pathname + u.search + (location.hash || ''));
-			} catch (eFrom) {
-				var sep = location.search && location.search.length > 1 ? '&' : '?';
-				history.replaceState(
-					null,
-					'',
-					location.pathname +
-						(location.search || '') +
-						sep +
-						'from=singlemessage' +
-						(location.hash || '')
-				);
+		function getWxShareEntryFrom() {
+			var from = q('from');
+			return from ? String(from).trim().toLowerCase() : '';
+		}
+
+		function isWxOpenLaunchAppSceneSupported() {
+			if (!isWeChatInAppBrowser()) return false;
+			if (readQueryParam('wxOpenTag') === '1' || readQueryParam('wxForceOpenTag') === '1') {
+				return true;
 			}
+			var from = getWxShareEntryFrom();
+			return (
+				from === 'singlemessage' ||
+				from === 'groupmessage' ||
+				from === 'timeline'
+			);
+		}
+
+		function applyWxOpenLaunchSceneBodyClass() {
+			if (!isWeChatInAppBrowser()) return;
+			var ok = isWxOpenLaunchAppSceneSupported();
+			document.body.classList.toggle('wx-open-tag-scene', ok);
+			document.body.classList.toggle('wx-copy-link-entry', !ok);
+		}
+
+		function isIOSWeChatBrowser() {
+			var ua = navigator.userAgent || '';
+			return /MicroMessenger/i.test(ua) && /iPhone|iPad|iPod/i.test(ua);
 		}
 
 		function logWxEntryDiagnostics() {
 			if (!isWeChatInAppBrowser()) return;
 			console.log('[wx-entry]', {
-				entryFrom: q('from') || '(无)',
+				entryFrom: getWxShareEntryFrom() || '(无,多为复制链接进入)',
+				openLaunchTagScene: isWxOpenLaunchAppSceneSupported(),
 				signUrl: getWxConfigSignUrl()
 			});
 		}
 
+		function showWxCopyLinkEntryTip() {
+			showFabToast(
+				'当前为复制链接进入,微信不支持直接打开 App。请使用 App「分享到微信」发送卡片后,点卡片进入。'
+			);
+		}
+
 		function readQueryParam(name) {
 			return q(name);
 		}
@@ -1070,7 +1085,10 @@
 				wx.ready(function () {
 					weChatJssdkConfigured = true;
 					document.body.classList.add('wx-jssdk-ready');
-					refreshWxLaunchTagAttrs();
+					applyWxOpenLaunchSceneBodyClass();
+					if (isWxOpenLaunchAppSceneSupported()) {
+						refreshWxLaunchTagAttrs();
+					}
 					console.log('[wx.config] ready, htmlUrl=', htmlUrl);
 					resolve(true);
 				});
@@ -1136,7 +1154,6 @@
 			if (!shouldFetchWxConfig(!!fromUserClick)) {
 				return Promise.resolve(false);
 			}
-			ensureWxShareFromQueryBeforeConfig();
 			if (wxJssdkInitPromise && !fromUserClick) return wxJssdkInitPromise;
 			wxConfigSignRetriedBaseUrl = false;
 			wxInitLastError = '';
@@ -1174,7 +1191,11 @@
 					setTimeout(tick, 400);
 				}
 			}
-			tick();
+			if (isIOSWeChatBrowser()) {
+				setTimeout(tick, 350);
+			} else {
+				tick();
+			}
 		}
 
 		function showFabToast(msg, ms) {
@@ -2436,7 +2457,7 @@
 			bindWeChatLaunchTagEvents();
 			if (isWeChatInAppBrowser()) {
 				document.body.classList.add('is-wechat');
-				ensureWxShareFromQueryBeforeConfig();
+				applyWxOpenLaunchSceneBodyClass();
 				logWxEntryDiagnostics();
 			}
 			if (shouldInitWeChatJssdkOnLoad()) {
@@ -2448,6 +2469,7 @@
 
 			document.addEventListener('WeixinOpenTagsError', function (e) {
 				console.warn('[WeixinOpenTagsError]', e && e.detail);
+				applyWxOpenLaunchSceneBodyClass();
 			});
 
 			fetchGetDeleteFlagByIdIfId().then(function (res) {
@@ -2473,6 +2495,9 @@
 							);
 							return;
 						}
+						if (!isWxOpenLaunchAppSceneSupported()) {
+							showWxCopyLinkEntryTip();
+						}
 					});
 				}
 			} else {

+ 51 - 26
HBuilderProjects/shareCheckInUndefined.html

@@ -211,11 +211,11 @@
 			opacity: 1;
 		}
 
-		body.is-wechat.wx-jssdk-ready #launch-btn {
+		body.is-wechat.wx-jssdk-ready.wx-open-tag-scene #launch-btn {
 			display: block;
 		}
 
-		body.is-wechat.wx-jssdk-ready #openApp {
+		body.is-wechat.wx-jssdk-ready.wx-open-tag-scene #openApp {
 			display: none !important;
 		}
 
@@ -550,36 +550,51 @@
 			return /MicroMessenger/i.test(navigator.userAgent || '');
 		}
 
-		function ensureWxShareFromQueryBeforeConfig() {
-			if (!isWeChatInAppBrowser()) return;
-			var from = String(q('from') || '').trim();
-			if (from) return;
-			try {
-				var u = new URL(location.href);
-				u.searchParams.set('from', 'singlemessage');
-				history.replaceState(null, '', u.pathname + u.search + (location.hash || ''));
-			} catch (eFrom) {
-				var sep = location.search && location.search.length > 1 ? '&' : '?';
-				history.replaceState(
-					null,
-					'',
-					location.pathname +
-						(location.search || '') +
-						sep +
-						'from=singlemessage' +
-						(location.hash || '')
-				);
+		function getWxShareEntryFrom() {
+			var from = q('from');
+			return from ? String(from).trim().toLowerCase() : '';
+		}
+
+		function isWxOpenLaunchAppSceneSupported() {
+			if (!isWeChatInAppBrowser()) return false;
+			if (readQueryParam('wxOpenTag') === '1' || readQueryParam('wxForceOpenTag') === '1') {
+				return true;
 			}
+			var from = getWxShareEntryFrom();
+			return (
+				from === 'singlemessage' ||
+				from === 'groupmessage' ||
+				from === 'timeline'
+			);
+		}
+
+		function applyWxOpenLaunchSceneBodyClass() {
+			if (!isWeChatInAppBrowser()) return;
+			var ok = isWxOpenLaunchAppSceneSupported();
+			document.body.classList.toggle('wx-open-tag-scene', ok);
+			document.body.classList.toggle('wx-copy-link-entry', !ok);
+		}
+
+		function isIOSWeChatBrowser() {
+			var ua = navigator.userAgent || '';
+			return /MicroMessenger/i.test(ua) && /iPhone|iPad|iPod/i.test(ua);
 		}
 
 		function logWxEntryDiagnostics() {
 			if (!isWeChatInAppBrowser()) return;
 			console.log('[wx-entry]', {
-				entryFrom: q('from') || '(无)',
+				entryFrom: getWxShareEntryFrom() || '(无,多为复制链接进入)',
+				openLaunchTagScene: isWxOpenLaunchAppSceneSupported(),
 				signUrl: getWxConfigSignUrl()
 			});
 		}
 
+		function showWxCopyLinkEntryTip() {
+			showFabToast(
+				'当前为复制链接进入,微信不支持直接打开 App。请使用 App「分享到微信」发送卡片后,点卡片进入。'
+			);
+		}
+
 		function readQueryParam(name) {
 			return q(name);
 		}
@@ -825,7 +840,10 @@
 				wx.ready(function () {
 					weChatJssdkConfigured = true;
 					document.body.classList.add('wx-jssdk-ready');
-					refreshWxLaunchTagAttrs();
+					applyWxOpenLaunchSceneBodyClass();
+					if (isWxOpenLaunchAppSceneSupported()) {
+						refreshWxLaunchTagAttrs();
+					}
 					console.log('[wx.config] ready, htmlUrl=', htmlUrl);
 					resolve(true);
 				});
@@ -892,7 +910,6 @@
 				console.log('[wx] 未调用 getWxConfig');
 				return Promise.resolve(false);
 			}
-			ensureWxShareFromQueryBeforeConfig();
 			if (isWxPcBrowser()) {
 				console.warn(
 					'[wx] PC:请求 getWxConfig' + (fromUserClick ? '(按钮)' : '(进页)')
@@ -936,7 +953,11 @@
 					setTimeout(tick, 400);
 				}
 			}
-			tick();
+			if (isIOSWeChatBrowser()) {
+				setTimeout(tick, 350);
+			} else {
+				tick();
+			}
 		}
 
 		function showFabToast(msg, ms) {
@@ -1307,7 +1328,7 @@
 			bindWeChatLaunchTagEvents();
 			if (isWeChatInAppBrowser()) {
 				document.body.classList.add('is-wechat');
-				ensureWxShareFromQueryBeforeConfig();
+				applyWxOpenLaunchSceneBodyClass();
 				logWxEntryDiagnostics();
 			}
 			if (shouldInitWeChatJssdkOnLoad()) {
@@ -1319,6 +1340,7 @@
 
 			document.addEventListener('WeixinOpenTagsError', function (e) {
 				console.warn('[WeixinOpenTagsError]', e && e.detail);
+				applyWxOpenLaunchSceneBodyClass();
 			});
 
 			applyEmptyHeroState();
@@ -1334,6 +1356,9 @@
 							);
 							return;
 						}
+						if (!isWxOpenLaunchAppSceneSupported()) {
+							showWxCopyLinkEntryTip();
+						}
 					});
 				}
 			} else {

+ 51 - 26
HBuilderProjects/shareDynamic.html

@@ -512,11 +512,11 @@
 			opacity: 1;
 		}
 
-		body.is-wechat.wx-jssdk-ready #launch-btn {
+		body.is-wechat.wx-jssdk-ready.wx-open-tag-scene #launch-btn {
 			display: block;
 		}
 
-		body.is-wechat.wx-jssdk-ready #openApp {
+		body.is-wechat.wx-jssdk-ready.wx-open-tag-scene #openApp {
 			display: none !important;
 		}
 
@@ -1359,7 +1359,10 @@
 				wx.ready(function () {
 					weChatJssdkConfigured = true;
 					document.body.classList.add('wx-jssdk-ready');
-					refreshWxLaunchTagAttrs();
+					applyWxOpenLaunchSceneBodyClass();
+					if (isWxOpenLaunchAppSceneSupported()) {
+						refreshWxLaunchTagAttrs();
+					}
 					console.log('[wx.config] ready, htmlUrl=', htmlUrl);
 					resolve(true);
 				});
@@ -1430,7 +1433,6 @@
 			if (!shouldFetchWxConfig(!!fromUserClick)) {
 				return Promise.resolve(false);
 			}
-			ensureWxShareFromQueryBeforeConfig();
 			if (wxJssdkInitPromise && !fromUserClick) return wxJssdkInitPromise;
 
 			wxConfigSignRetriedBaseUrl = false;
@@ -1471,7 +1473,11 @@
 					setTimeout(tick, 400);
 				}
 			}
-			tick();
+			if (isIOSWeChatBrowser()) {
+				setTimeout(tick, 350);
+			} else {
+				tick();
+			}
 		}
 
 		function showFabToast(msg, ms) {
@@ -1522,36 +1528,51 @@
 			return /MicroMessenger/i.test(navigator.userAgent || '');
 		}
 
-		function ensureWxShareFromQueryBeforeConfig() {
-			if (!isWeChatInAppBrowser()) return;
-			var from = String(q('from') || '').trim();
-			if (from) return;
-			try {
-				var u = new URL(location.href);
-				u.searchParams.set('from', 'singlemessage');
-				history.replaceState(null, '', u.pathname + u.search + (location.hash || ''));
-			} catch (eFrom) {
-				var sep = location.search && location.search.length > 1 ? '&' : '?';
-				history.replaceState(
-					null,
-					'',
-					location.pathname +
-						(location.search || '') +
-						sep +
-						'from=singlemessage' +
-						(location.hash || '')
-				);
+		function getWxShareEntryFrom() {
+			var from = q('from');
+			return from ? String(from).trim().toLowerCase() : '';
+		}
+
+		function isWxOpenLaunchAppSceneSupported() {
+			if (!isWeChatInAppBrowser()) return false;
+			if (readQueryParam('wxOpenTag') === '1' || readQueryParam('wxForceOpenTag') === '1') {
+				return true;
 			}
+			var from = getWxShareEntryFrom();
+			return (
+				from === 'singlemessage' ||
+				from === 'groupmessage' ||
+				from === 'timeline'
+			);
+		}
+
+		function applyWxOpenLaunchSceneBodyClass() {
+			if (!isWeChatInAppBrowser()) return;
+			var ok = isWxOpenLaunchAppSceneSupported();
+			document.body.classList.toggle('wx-open-tag-scene', ok);
+			document.body.classList.toggle('wx-copy-link-entry', !ok);
+		}
+
+		function isIOSWeChatBrowser() {
+			var ua = navigator.userAgent || '';
+			return /MicroMessenger/i.test(ua) && /iPhone|iPad|iPod/i.test(ua);
 		}
 
 		function logWxEntryDiagnostics() {
 			if (!isWeChatInAppBrowser()) return;
 			console.log('[wx-entry]', {
-				entryFrom: q('from') || '(无)',
+				entryFrom: getWxShareEntryFrom() || '(无,多为复制链接进入)',
+				openLaunchTagScene: isWxOpenLaunchAppSceneSupported(),
 				signUrl: getWxConfigSignUrl()
 			});
 		}
 
+		function showWxCopyLinkEntryTip() {
+			showFabToast(
+				'当前为复制链接进入,微信不支持直接打开 App。请使用 App「分享到微信」发送卡片后,点卡片进入。'
+			);
+		}
+
 		/** 微信内置浏览器、iOS:OSS 截图/封面易因 Referer 被拒;video 首帧不可靠 */
 		function preferStaticStillOverVideo() {
 			return isIOSVideoEnv() || isWeChatInAppBrowser();
@@ -3128,7 +3149,7 @@
 			bindWeChatLaunchTagEvents();
 			if (isWeChatInAppBrowser()) {
 				document.body.classList.add('is-wechat');
-				ensureWxShareFromQueryBeforeConfig();
+				applyWxOpenLaunchSceneBodyClass();
 				logWxEntryDiagnostics();
 			}
 			if (shouldInitWeChatJssdkOnLoad()) {
@@ -3140,6 +3161,7 @@
 
 			document.addEventListener('WeixinOpenTagsError', function (e) {
 				console.warn('[WeixinOpenTagsError]', e && e.detail);
+				applyWxOpenLaunchSceneBodyClass();
 			});
 
 			fetchGetDeleteFlagByIdIfId().then(function (res) {
@@ -3167,6 +3189,9 @@
 							);
 							return;
 						}
+						if (!isWxOpenLaunchAppSceneSupported()) {
+							showWxCopyLinkEntryTip();
+						}
 					});
 				}
 			} else {

+ 51 - 26
HBuilderProjects/shareIndex.html

@@ -496,11 +496,11 @@
 			opacity: 1;
 		}
 
-		body.is-wechat.wx-jssdk-ready #launch-btn {
+		body.is-wechat.wx-jssdk-ready.wx-open-tag-scene #launch-btn {
 			display: block;
 		}
 
-		body.is-wechat.wx-jssdk-ready #openApp {
+		body.is-wechat.wx-jssdk-ready.wx-open-tag-scene #openApp {
 			display: none !important;
 		}
 
@@ -1237,36 +1237,51 @@
 			return /MicroMessenger/i.test(navigator.userAgent || '');
 		}
 
-		function ensureWxShareFromQueryBeforeConfig() {
-			if (!isWeChatInAppBrowser()) return;
-			var from = String(readQueryParam('from') || '').trim();
-			if (from) return;
-			try {
-				var u = new URL(location.href);
-				u.searchParams.set('from', 'singlemessage');
-				history.replaceState(null, '', u.pathname + u.search + (location.hash || ''));
-			} catch (eFrom) {
-				var sep = location.search && location.search.length > 1 ? '&' : '?';
-				history.replaceState(
-					null,
-					'',
-					location.pathname +
-						(location.search || '') +
-						sep +
-						'from=singlemessage' +
-						(location.hash || '')
-				);
+		function getWxShareEntryFrom() {
+			var from = readQueryParam('from');
+			return from ? String(from).trim().toLowerCase() : '';
+		}
+
+		function isWxOpenLaunchAppSceneSupported() {
+			if (!isWeChatInAppBrowser()) return false;
+			if (readQueryParam('wxOpenTag') === '1' || readQueryParam('wxForceOpenTag') === '1') {
+				return true;
 			}
+			var from = getWxShareEntryFrom();
+			return (
+				from === 'singlemessage' ||
+				from === 'groupmessage' ||
+				from === 'timeline'
+			);
+		}
+
+		function applyWxOpenLaunchSceneBodyClass() {
+			if (!isWeChatInAppBrowser()) return;
+			var ok = isWxOpenLaunchAppSceneSupported();
+			document.body.classList.toggle('wx-open-tag-scene', ok);
+			document.body.classList.toggle('wx-copy-link-entry', !ok);
+		}
+
+		function isIOSWeChatBrowser() {
+			var ua = navigator.userAgent || '';
+			return /MicroMessenger/i.test(ua) && /iPhone|iPad|iPod/i.test(ua);
 		}
 
 		function logWxEntryDiagnostics() {
 			if (!isWeChatInAppBrowser()) return;
 			console.log('[wx-entry]', {
-				entryFrom: readQueryParam('from') || '(无)',
+				entryFrom: getWxShareEntryFrom() || '(无,多为复制链接进入)',
+				openLaunchTagScene: isWxOpenLaunchAppSceneSupported(),
 				signUrl: getWxConfigSignUrl()
 			});
 		}
 
+		function showWxCopyLinkEntryTip() {
+			showFabToast(
+				'当前为复制链接进入,微信不支持直接打开 App。请使用 App「分享到微信」发送卡片后,点卡片进入。'
+			);
+		}
+
 		function readQueryParam(name) {
 			try {
 				var v = new URLSearchParams(location.search || '').get(name);
@@ -1573,7 +1588,10 @@
 				wx.ready(function () {
 					weChatJssdkConfigured = true;
 					document.body.classList.add('wx-jssdk-ready');
-					refreshWxLaunchTagAttrs();
+					applyWxOpenLaunchSceneBodyClass();
+					if (isWxOpenLaunchAppSceneSupported()) {
+						refreshWxLaunchTagAttrs();
+					}
 					console.log('[wx.config] ready, htmlUrl=', htmlUrl);
 					resolve(true);
 				});
@@ -1640,7 +1658,6 @@
 				console.log('[wx] 未调用 getWxConfig');
 				return Promise.resolve(false);
 			}
-			ensureWxShareFromQueryBeforeConfig();
 			if (isWxPcBrowser()) {
 				console.warn(
 					'[wx] PC:请求 getWxConfig' + (fromUserClick ? '(按钮)' : '(进页)')
@@ -1687,7 +1704,11 @@
 					setTimeout(tick, 400);
 				}
 			}
-			tick();
+			if (isIOSWeChatBrowser()) {
+				setTimeout(tick, 350);
+			} else {
+				tick();
+			}
 		}
 
 		function showFabToast(msg, ms) {
@@ -2978,7 +2999,7 @@
 			bindWeChatLaunchTagEvents();
 			if (isWeChatInAppBrowser()) {
 				document.body.classList.add('is-wechat');
-				ensureWxShareFromQueryBeforeConfig();
+				applyWxOpenLaunchSceneBodyClass();
 				logWxEntryDiagnostics();
 			}
 			if (shouldInitWeChatJssdkOnLoad()) {
@@ -2990,6 +3011,7 @@
 
 			document.addEventListener('WeixinOpenTagsError', function (e) {
 				console.warn('[WeixinOpenTagsError]', e && e.detail);
+				applyWxOpenLaunchSceneBodyClass();
 			});
 
 			if (isWeChatInAppBrowser()) {
@@ -3002,6 +3024,9 @@
 							);
 							return;
 						}
+						if (!isWxOpenLaunchAppSceneSupported()) {
+							showWxCopyLinkEntryTip();
+						}
 					});
 				}
 			} else {

+ 52 - 26
HBuilderProjects/shareUndefined.html

@@ -458,12 +458,12 @@
 		}
 
 		/* 与 secondShareGoods 一致:wx 就绪后仅显示开放标签(叠在 openApp 之上) */
-		body.is-wechat.wx-jssdk-ready #launch-btn {
+		body.is-wechat.wx-jssdk-ready.wx-open-tag-scene #launch-btn {
 			display: block;
 			pointer-events: auto;
 		}
 
-		body.is-wechat.wx-jssdk-ready #openApp {
+		body.is-wechat.wx-jssdk-ready.wx-open-tag-scene #openApp {
 			display: none !important;
 		}
 
@@ -862,36 +862,51 @@
 			return /MicroMessenger/i.test(navigator.userAgent || '');
 		}
 
-		function ensureWxShareFromQueryBeforeConfig() {
-			if (!isWeChatInAppBrowser()) return;
-			var from = String(q('from') || '').trim();
-			if (from) return;
-			try {
-				var u = new URL(location.href);
-				u.searchParams.set('from', 'singlemessage');
-				history.replaceState(null, '', u.pathname + u.search + (location.hash || ''));
-			} catch (eFrom) {
-				var sep = location.search && location.search.length > 1 ? '&' : '?';
-				history.replaceState(
-					null,
-					'',
-					location.pathname +
-						(location.search || '') +
-						sep +
-						'from=singlemessage' +
-						(location.hash || '')
-				);
+		function getWxShareEntryFrom() {
+			var from = q('from');
+			return from ? String(from).trim().toLowerCase() : '';
+		}
+
+		function isWxOpenLaunchAppSceneSupported() {
+			if (!isWeChatInAppBrowser()) return false;
+			if (readQueryParam('wxOpenTag') === '1' || readQueryParam('wxForceOpenTag') === '1') {
+				return true;
 			}
+			var from = getWxShareEntryFrom();
+			return (
+				from === 'singlemessage' ||
+				from === 'groupmessage' ||
+				from === 'timeline'
+			);
+		}
+
+		function applyWxOpenLaunchSceneBodyClass() {
+			if (!isWeChatInAppBrowser()) return;
+			var ok = isWxOpenLaunchAppSceneSupported();
+			document.body.classList.toggle('wx-open-tag-scene', ok);
+			document.body.classList.toggle('wx-copy-link-entry', !ok);
+		}
+
+		function isIOSWeChatBrowser() {
+			var ua = navigator.userAgent || '';
+			return /MicroMessenger/i.test(ua) && /iPhone|iPad|iPod/i.test(ua);
 		}
 
 		function logWxEntryDiagnostics() {
 			if (!isWeChatInAppBrowser()) return;
 			console.log('[wx-entry]', {
-				entryFrom: q('from') || '(无)',
+				entryFrom: getWxShareEntryFrom() || '(无,多为复制链接进入)',
+				openLaunchTagScene: isWxOpenLaunchAppSceneSupported(),
 				signUrl: getWxConfigSignUrl()
 			});
 		}
 
+		function showWxCopyLinkEntryTip() {
+			showFabToast(
+				'当前为复制链接进入,微信不支持直接打开 App。请使用 App「分享到微信」发送卡片后,点卡片进入。'
+			);
+		}
+
 		function readQueryParam(name) {
 			return q(name);
 		}
@@ -1137,7 +1152,10 @@
 				wx.ready(function () {
 					weChatJssdkConfigured = true;
 					document.body.classList.add('wx-jssdk-ready');
-					refreshWxLaunchTagAttrs(false);
+					applyWxOpenLaunchSceneBodyClass();
+					if (isWxOpenLaunchAppSceneSupported()) {
+						refreshWxLaunchTagAttrs(false);
+					}
 					console.log('[wx.config] ready, htmlUrl=', htmlUrl);
 					resolve(true);
 				});
@@ -1242,7 +1260,6 @@
 				console.log('[wx] 未调用 getWxConfig');
 				return Promise.resolve(false);
 			}
-			ensureWxShareFromQueryBeforeConfig();
 			if (isWxPcBrowser()) {
 				console.warn(
 					'[wx] PC:请求 getWxConfig' + (fromUserClick ? '(按钮)' : '(进页)')
@@ -1293,7 +1310,11 @@
 					setTimeout(tick, 400);
 				}
 			}
-			tick();
+			if (isIOSWeChatBrowser()) {
+				setTimeout(tick, 350);
+			} else {
+				tick();
+			}
 		}
 
 		function showFabToast(msg, ms) {
@@ -1933,7 +1954,7 @@
 			bindWeChatLaunchTagEvents();
 			if (isWeChatInAppBrowser()) {
 				document.body.classList.add('is-wechat');
-				ensureWxShareFromQueryBeforeConfig();
+				applyWxOpenLaunchSceneBodyClass();
 				logWxEntryDiagnostics();
 			}
 			if (shouldInitWeChatJssdkOnLoad()) {
@@ -1945,6 +1966,7 @@
 
 			document.addEventListener('WeixinOpenTagsError', function (e) {
 				console.warn('[WeixinOpenTagsError]', e && e.detail);
+				applyWxOpenLaunchSceneBodyClass();
 				var d = e && e.detail;
 				var em =
 					d && d.errMsg
@@ -1966,6 +1988,10 @@
 								wxInitLastError || '微信 SDK 初始化中,请稍候再点底部按钮'
 							);
 							initWeChatOpenLaunchApp(true);
+							return;
+						}
+						if (!isWxOpenLaunchAppSceneSupported()) {
+							showWxCopyLinkEntryTip();
 						}
 					});
 				}