sunshibo пре 1 недеља
родитељ
комит
b788ef1de4

+ 30 - 54
HBuilderProjects/secondShareGoods.html

@@ -73,12 +73,11 @@
 			opacity: 1;
 		}
 
-		/* 仅「分享卡片」等受支持场景展示开放标签;复制链接进入见 .wx-copy-link-entry */
-		body.is-wechat.wx-jssdk-ready.wx-open-tag-scene #launch-btn {
+		body.is-wechat.wx-jssdk-ready #launch-btn {
 			display: block;
 		}
 
-		body.is-wechat.wx-jssdk-ready.wx-open-tag-scene #openApp {
+		body.is-wechat.wx-jssdk-ready #openApp {
 			display: none !important;
 		}
 
@@ -797,51 +796,39 @@
 			return /MicroMessenger/i.test(navigator.userAgent || '');
 		}
 
-		/** 微信打开 H5 时的场景来源(分享卡片会带 from,复制链接通常没有) */
-		function getWxShareEntryFrom() {
-			var from = q('from');
-			return from ? String(from).trim().toLowerCase() : '';
-		}
-
 		/**
-		 * wx-open-launch-app 仅在部分微信场景可用(App/好友分享卡片、朋友圈卡片等)。
-		 * 复制链接粘贴打开一般无 from=,微信会报 launch:fail(当前场景不支持)。
+		 * 复制链接进入常无 from=;与点击分享卡片对齐,在拉 getWxConfig 前补 from=singlemessage(不刷新页面)。
 		 */
-		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() {
+		function ensureWxShareFromQueryBeforeConfig() {
 			if (!isWeChatInAppBrowser()) return;
-			var ok = isWxOpenLaunchAppSceneSupported();
-			document.body.classList.toggle('wx-open-tag-scene', ok);
-			document.body.classList.toggle('wx-copy-link-entry', !ok);
+			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 logWxEntryDiagnostics() {
 			if (!isWeChatInAppBrowser()) return;
 			console.log('[wx-entry]', {
-				entryFrom: getWxShareEntryFrom() || '(无,多为复制链接进入)',
-				openLaunchTagScene: isWxOpenLaunchAppSceneSupported(),
+				entryFrom: q('from') || '(无)',
 				signUrl: getWxConfigSignUrl()
 			});
 		}
 
-		function showWxCopyLinkEntryTip() {
-			showFabToast(
-				'当前为复制链接进入,微信不支持直接打开 App。请使用 App「分享到微信」发送卡片后,从卡片进入。'
-			);
-		}
-
 		function readQueryParam(name) {
 			return q(name);
 		}
@@ -1087,10 +1074,7 @@
 				wx.ready(function () {
 					weChatJssdkConfigured = true;
 					document.body.classList.add('wx-jssdk-ready');
-					applyWxOpenLaunchSceneBodyClass();
-					if (isWxOpenLaunchAppSceneSupported()) {
-						refreshWxLaunchTagAttrs();
-					}
+					refreshWxLaunchTagAttrs();
 					console.log('[wx.config] ready, htmlUrl=', htmlUrl);
 					resolve(true);
 				});
@@ -1146,10 +1130,6 @@
 							? String(detail.errmsg)
 							: '';
 				console.warn('[wx-open-launch-app]', detail);
-				if (/launch:fail/i.test(errMsg) && !isWxOpenLaunchAppSceneSupported()) {
-					showWxCopyLinkEntryTip();
-					return;
-				}
 				showAppOpenFailTip(
 					errMsg
 						? '未能唤起 App:' + errMsg
@@ -1162,6 +1142,7 @@
 			if (!shouldFetchWxConfig(!!fromUserClick)) {
 				return Promise.resolve(false);
 			}
+			ensureWxShareFromQueryBeforeConfig();
 			if (wxJssdkInitPromise && !fromUserClick) return wxJssdkInitPromise;
 			wxConfigSignRetriedBaseUrl = false;
 			wxInitLastError = '';
@@ -2009,12 +1990,12 @@
 			var launchTag = document.getElementById('launch-btn');
 			if (launchTag) launchTag.setAttribute('appid', WECHAT_OPEN_APP_ID);
 			bindWeChatLaunchTagEvents();
+			if (isWeChatInAppBrowser()) {
+				document.body.classList.add('is-wechat');
+				ensureWxShareFromQueryBeforeConfig();
+				logWxEntryDiagnostics();
+			}
 			if (shouldInitWeChatJssdkOnLoad()) {
-				if (isWeChatInAppBrowser()) {
-					document.body.classList.add('is-wechat');
-					applyWxOpenLaunchSceneBodyClass();
-					logWxEntryDiagnostics();
-				}
 				if (isWxPcBrowser() && (isWxForceDebug() || isWxPcAutoDebugHost())) {
 					document.body.classList.add('wx-pc-debug');
 				}
@@ -2023,7 +2004,6 @@
 
 			document.addEventListener('WeixinOpenTagsError', function (e) {
 				console.warn('[WeixinOpenTagsError]', e && e.detail);
-				applyWxOpenLaunchSceneBodyClass();
 			});
 
 			if (isWeChatInAppBrowser()) {
@@ -2034,10 +2014,6 @@
 							showFabToast(
 								wxInitLastError || '微信 SDK 初始化中,请稍候再点底部按钮'
 							);
-							return;
-						}
-						if (!isWxOpenLaunchAppSceneSupported()) {
-							showWxCopyLinkEntryTip();
 						}
 					});
 				}

+ 29 - 49
HBuilderProjects/shareCheckIn.html

@@ -322,11 +322,11 @@
 			opacity: 1;
 		}
 
-		body.is-wechat.wx-jssdk-ready.wx-open-tag-scene #launch-btn {
+		body.is-wechat.wx-jssdk-ready #launch-btn {
 			display: block;
 		}
 
-		body.is-wechat.wx-jssdk-ready.wx-open-tag-scene #openApp {
+		body.is-wechat.wx-jssdk-ready #openApp {
 			display: none !important;
 		}
 
@@ -795,46 +795,36 @@
 			return /MicroMessenger/i.test(navigator.userAgent || '');
 		}
 
-		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() {
+		function ensureWxShareFromQueryBeforeConfig() {
 			if (!isWeChatInAppBrowser()) return;
-			var ok = isWxOpenLaunchAppSceneSupported();
-			document.body.classList.toggle('wx-open-tag-scene', ok);
-			document.body.classList.toggle('wx-copy-link-entry', !ok);
+			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 logWxEntryDiagnostics() {
 			if (!isWeChatInAppBrowser()) return;
 			console.log('[wx-entry]', {
-				entryFrom: getWxShareEntryFrom() || '(无,多为复制链接进入)',
-				openLaunchTagScene: isWxOpenLaunchAppSceneSupported(),
+				entryFrom: q('from') || '(无)',
 				signUrl: getWxConfigSignUrl()
 			});
 		}
 
-		function showWxCopyLinkEntryTip() {
-			showFabToast(
-				'当前为复制链接进入,微信不支持直接打开 App。请使用 App「分享到微信」发送卡片后,从卡片进入。'
-			);
-		}
-
 		function readQueryParam(name) {
 			return q(name);
 		}
@@ -1080,10 +1070,7 @@
 				wx.ready(function () {
 					weChatJssdkConfigured = true;
 					document.body.classList.add('wx-jssdk-ready');
-					applyWxOpenLaunchSceneBodyClass();
-					if (isWxOpenLaunchAppSceneSupported()) {
-						refreshWxLaunchTagAttrs();
-					}
+					refreshWxLaunchTagAttrs();
 					console.log('[wx.config] ready, htmlUrl=', htmlUrl);
 					resolve(true);
 				});
@@ -1139,10 +1126,6 @@
 							? String(detail.errmsg)
 							: '';
 				console.warn('[wx-open-launch-app]', detail);
-				if (/launch:fail/i.test(errMsg) && !isWxOpenLaunchAppSceneSupported()) {
-					showWxCopyLinkEntryTip();
-					return;
-				}
 				showAppOpenFailTip(
 					errMsg
 						? '未能唤起 App:' + errMsg
@@ -1155,6 +1138,7 @@
 			if (!shouldFetchWxConfig(!!fromUserClick)) {
 				return Promise.resolve(false);
 			}
+			ensureWxShareFromQueryBeforeConfig();
 			if (wxJssdkInitPromise && !fromUserClick) return wxJssdkInitPromise;
 			wxConfigSignRetriedBaseUrl = false;
 			wxInitLastError = '';
@@ -2452,12 +2436,12 @@
 			var launchTag = document.getElementById('launch-btn');
 			if (launchTag) launchTag.setAttribute('appid', WECHAT_OPEN_APP_ID);
 			bindWeChatLaunchTagEvents();
+			if (isWeChatInAppBrowser()) {
+				document.body.classList.add('is-wechat');
+				ensureWxShareFromQueryBeforeConfig();
+				logWxEntryDiagnostics();
+			}
 			if (shouldInitWeChatJssdkOnLoad()) {
-				if (isWeChatInAppBrowser()) {
-					document.body.classList.add('is-wechat');
-					applyWxOpenLaunchSceneBodyClass();
-					logWxEntryDiagnostics();
-				}
 				if (isWxPcBrowser() && (isWxForceDebug() || isWxPcAutoDebugHost())) {
 					document.body.classList.add('wx-pc-debug');
 				}
@@ -2466,7 +2450,6 @@
 
 			document.addEventListener('WeixinOpenTagsError', function (e) {
 				console.warn('[WeixinOpenTagsError]', e && e.detail);
-				applyWxOpenLaunchSceneBodyClass();
 			});
 
 			fetchGetDeleteFlagByIdIfId().then(function (res) {
@@ -2492,9 +2475,6 @@
 							);
 							return;
 						}
-						if (!isWxOpenLaunchAppSceneSupported()) {
-							showWxCopyLinkEntryTip();
-						}
 					});
 				}
 			} else {

+ 29 - 49
HBuilderProjects/shareCheckInUndefined.html

@@ -211,11 +211,11 @@
 			opacity: 1;
 		}
 
-		body.is-wechat.wx-jssdk-ready.wx-open-tag-scene #launch-btn {
+		body.is-wechat.wx-jssdk-ready #launch-btn {
 			display: block;
 		}
 
-		body.is-wechat.wx-jssdk-ready.wx-open-tag-scene #openApp {
+		body.is-wechat.wx-jssdk-ready #openApp {
 			display: none !important;
 		}
 
@@ -550,46 +550,36 @@
 			return /MicroMessenger/i.test(navigator.userAgent || '');
 		}
 
-		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() {
+		function ensureWxShareFromQueryBeforeConfig() {
 			if (!isWeChatInAppBrowser()) return;
-			var ok = isWxOpenLaunchAppSceneSupported();
-			document.body.classList.toggle('wx-open-tag-scene', ok);
-			document.body.classList.toggle('wx-copy-link-entry', !ok);
+			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 logWxEntryDiagnostics() {
 			if (!isWeChatInAppBrowser()) return;
 			console.log('[wx-entry]', {
-				entryFrom: getWxShareEntryFrom() || '(无,多为复制链接进入)',
-				openLaunchTagScene: isWxOpenLaunchAppSceneSupported(),
+				entryFrom: q('from') || '(无)',
 				signUrl: getWxConfigSignUrl()
 			});
 		}
 
-		function showWxCopyLinkEntryTip() {
-			showFabToast(
-				'当前为复制链接进入,微信不支持直接打开 App。请使用 App「分享到微信」发送卡片后,从卡片进入。'
-			);
-		}
-
 		function readQueryParam(name) {
 			return q(name);
 		}
@@ -835,10 +825,7 @@
 				wx.ready(function () {
 					weChatJssdkConfigured = true;
 					document.body.classList.add('wx-jssdk-ready');
-					applyWxOpenLaunchSceneBodyClass();
-					if (isWxOpenLaunchAppSceneSupported()) {
-						refreshWxLaunchTagAttrs();
-					}
+					refreshWxLaunchTagAttrs();
 					console.log('[wx.config] ready, htmlUrl=', htmlUrl);
 					resolve(true);
 				});
@@ -894,10 +881,6 @@
 							? String(detail.errmsg)
 							: '';
 				console.warn('[wx-open-launch-app]', detail);
-				if (/launch:fail/i.test(errMsg) && !isWxOpenLaunchAppSceneSupported()) {
-					showWxCopyLinkEntryTip();
-					return;
-				}
 				showAppOpenFailTip(
 					errMsg
 						? '未能唤起 App:' + errMsg
@@ -911,6 +894,7 @@
 				console.log('[wx] 未调用 getWxConfig');
 				return Promise.resolve(false);
 			}
+			ensureWxShareFromQueryBeforeConfig();
 			if (isWxPcBrowser()) {
 				console.warn(
 					'[wx] PC:请求 getWxConfig' + (fromUserClick ? '(按钮)' : '(进页)')
@@ -1323,12 +1307,12 @@
 			var launchTag = document.getElementById('launch-btn');
 			if (launchTag) launchTag.setAttribute('appid', WECHAT_OPEN_APP_ID);
 			bindWeChatLaunchTagEvents();
+			if (isWeChatInAppBrowser()) {
+				document.body.classList.add('is-wechat');
+				ensureWxShareFromQueryBeforeConfig();
+				logWxEntryDiagnostics();
+			}
 			if (shouldInitWeChatJssdkOnLoad()) {
-				if (isWeChatInAppBrowser()) {
-					document.body.classList.add('is-wechat');
-					applyWxOpenLaunchSceneBodyClass();
-					logWxEntryDiagnostics();
-				}
 				if (isWxPcBrowser() && (isWxForceDebug() || isWxPcAutoDebugHost())) {
 					document.body.classList.add('wx-pc-debug');
 				}
@@ -1337,7 +1321,6 @@
 
 			document.addEventListener('WeixinOpenTagsError', function (e) {
 				console.warn('[WeixinOpenTagsError]', e && e.detail);
-				applyWxOpenLaunchSceneBodyClass();
 			});
 
 			applyEmptyHeroState();
@@ -1353,9 +1336,6 @@
 							);
 							return;
 						}
-						if (!isWxOpenLaunchAppSceneSupported()) {
-							showWxCopyLinkEntryTip();
-						}
 					});
 				}
 			} else {

+ 29 - 49
HBuilderProjects/shareDynamic.html

@@ -512,11 +512,11 @@
 			opacity: 1;
 		}
 
-		body.is-wechat.wx-jssdk-ready.wx-open-tag-scene #launch-btn {
+		body.is-wechat.wx-jssdk-ready #launch-btn {
 			display: block;
 		}
 
-		body.is-wechat.wx-jssdk-ready.wx-open-tag-scene #openApp {
+		body.is-wechat.wx-jssdk-ready #openApp {
 			display: none !important;
 		}
 
@@ -1359,10 +1359,7 @@
 				wx.ready(function () {
 					weChatJssdkConfigured = true;
 					document.body.classList.add('wx-jssdk-ready');
-					applyWxOpenLaunchSceneBodyClass();
-					if (isWxOpenLaunchAppSceneSupported()) {
-						refreshWxLaunchTagAttrs();
-					}
+					refreshWxLaunchTagAttrs();
 					console.log('[wx.config] ready, htmlUrl=', htmlUrl);
 					resolve(true);
 				});
@@ -1418,10 +1415,6 @@
 							? String(detail.errmsg)
 							: '';
 				console.warn('[wx-open-launch-app]', detail);
-				if (/launch:fail/i.test(errMsg) && !isWxOpenLaunchAppSceneSupported()) {
-					showWxCopyLinkEntryTip();
-					return;
-				}
 				showAppOpenFailTip(
 					errMsg
 						? '未能唤起 App:' + errMsg
@@ -1439,6 +1432,7 @@
 			if (!shouldFetchWxConfig(!!fromUserClick)) {
 				return Promise.resolve(false);
 			}
+			ensureWxShareFromQueryBeforeConfig();
 			if (wxJssdkInitPromise && !fromUserClick) return wxJssdkInitPromise;
 
 			wxConfigSignRetriedBaseUrl = false;
@@ -1530,46 +1524,36 @@
 			return /MicroMessenger/i.test(navigator.userAgent || '');
 		}
 
-		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() {
+		function ensureWxShareFromQueryBeforeConfig() {
 			if (!isWeChatInAppBrowser()) return;
-			var ok = isWxOpenLaunchAppSceneSupported();
-			document.body.classList.toggle('wx-open-tag-scene', ok);
-			document.body.classList.toggle('wx-copy-link-entry', !ok);
+			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 logWxEntryDiagnostics() {
 			if (!isWeChatInAppBrowser()) return;
 			console.log('[wx-entry]', {
-				entryFrom: getWxShareEntryFrom() || '(无,多为复制链接进入)',
-				openLaunchTagScene: isWxOpenLaunchAppSceneSupported(),
+				entryFrom: q('from') || '(无)',
 				signUrl: getWxConfigSignUrl()
 			});
 		}
 
-		function showWxCopyLinkEntryTip() {
-			showFabToast(
-				'当前为复制链接进入,微信不支持直接打开 App。请使用 App「分享到微信」发送卡片后,从卡片进入。'
-			);
-		}
-
 		/** 微信内置浏览器、iOS:OSS 截图/封面易因 Referer 被拒;video 首帧不可靠 */
 		function preferStaticStillOverVideo() {
 			return isIOSVideoEnv() || isWeChatInAppBrowser();
@@ -3144,12 +3128,12 @@
 			var launchTag = document.getElementById('launch-btn');
 			if (launchTag) launchTag.setAttribute('appid', WECHAT_OPEN_APP_ID);
 			bindWeChatLaunchTagEvents();
+			if (isWeChatInAppBrowser()) {
+				document.body.classList.add('is-wechat');
+				ensureWxShareFromQueryBeforeConfig();
+				logWxEntryDiagnostics();
+			}
 			if (shouldInitWeChatJssdkOnLoad()) {
-				if (isWeChatInAppBrowser()) {
-					document.body.classList.add('is-wechat');
-					applyWxOpenLaunchSceneBodyClass();
-					logWxEntryDiagnostics();
-				}
 				if (isWxPcBrowser() && (isWxForceDebug() || isWxPcAutoDebugHost())) {
 					document.body.classList.add('wx-pc-debug');
 				}
@@ -3158,7 +3142,6 @@
 
 			document.addEventListener('WeixinOpenTagsError', function (e) {
 				console.warn('[WeixinOpenTagsError]', e && e.detail);
-				applyWxOpenLaunchSceneBodyClass();
 			});
 
 			fetchGetDeleteFlagByIdIfId().then(function (res) {
@@ -3186,9 +3169,6 @@
 							);
 							return;
 						}
-						if (!isWxOpenLaunchAppSceneSupported()) {
-							showWxCopyLinkEntryTip();
-						}
 					});
 				}
 			} else {

+ 28 - 51
HBuilderProjects/shareIndex.html

@@ -496,11 +496,11 @@
 			opacity: 1;
 		}
 
-		body.is-wechat.wx-jssdk-ready.wx-open-tag-scene #launch-btn {
+		body.is-wechat.wx-jssdk-ready #launch-btn {
 			display: block;
 		}
 
-		body.is-wechat.wx-jssdk-ready.wx-open-tag-scene #openApp {
+		body.is-wechat.wx-jssdk-ready #openApp {
 			display: none !important;
 		}
 
@@ -1237,49 +1237,36 @@
 			return /MicroMessenger/i.test(navigator.userAgent || '');
 		}
 
-		function getWxShareEntryFrom() {
-			var from = '';
+		function ensureWxShareFromQueryBeforeConfig() {
+			if (!isWeChatInAppBrowser()) return;
+			var from = String(readQueryParam('from') || '').trim();
+			if (from) return;
 			try {
-				from = new URLSearchParams(location.search || '').get('from') || '';
-			} catch (eFrom) {}
-			return from ? String(from).trim().toLowerCase() : '';
-		}
-
-		function isWxOpenLaunchAppSceneSupported() {
-			if (!isWeChatInAppBrowser()) return false;
-			if (readQueryParam('wxOpenTag') === '1' || readQueryParam('wxForceOpenTag') === '1') {
-				return true;
+				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 || '')
+				);
 			}
-			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: getWxShareEntryFrom() || '(无,多为复制链接进入)',
-				openLaunchTagScene: isWxOpenLaunchAppSceneSupported(),
+				entryFrom: readQueryParam('from') || '(无)',
 				signUrl: getWxConfigSignUrl()
 			});
 		}
 
-		function showWxCopyLinkEntryTip() {
-			showFabToast(
-				'当前为复制链接进入,微信不支持直接打开 App。请使用 App「分享到微信」发送卡片后,从卡片进入。'
-			);
-		}
-
 		function readQueryParam(name) {
 			try {
 				var v = new URLSearchParams(location.search || '').get(name);
@@ -1586,10 +1573,7 @@
 				wx.ready(function () {
 					weChatJssdkConfigured = true;
 					document.body.classList.add('wx-jssdk-ready');
-					applyWxOpenLaunchSceneBodyClass();
-					if (isWxOpenLaunchAppSceneSupported()) {
-						refreshWxLaunchTagAttrs();
-					}
+					refreshWxLaunchTagAttrs();
 					console.log('[wx.config] ready, htmlUrl=', htmlUrl);
 					resolve(true);
 				});
@@ -1645,10 +1629,6 @@
 							? String(detail.errmsg)
 							: '';
 				console.warn('[wx-open-launch-app]', detail);
-				if (/launch:fail/i.test(errMsg) && !isWxOpenLaunchAppSceneSupported()) {
-					showWxCopyLinkEntryTip();
-					return;
-				}
 				showAppOpenFailTip(
 					errMsg
 						? '未能唤起 App:' + errMsg
@@ -1662,6 +1642,7 @@
 				console.log('[wx] 未调用 getWxConfig');
 				return Promise.resolve(false);
 			}
+			ensureWxShareFromQueryBeforeConfig();
 			if (isWxPcBrowser()) {
 				console.warn(
 					'[wx] PC:请求 getWxConfig' + (fromUserClick ? '(按钮)' : '(进页)')
@@ -2997,12 +2978,12 @@
 			var launchTag = document.getElementById('launch-btn');
 			if (launchTag) launchTag.setAttribute('appid', WECHAT_OPEN_APP_ID);
 			bindWeChatLaunchTagEvents();
+			if (isWeChatInAppBrowser()) {
+				document.body.classList.add('is-wechat');
+				ensureWxShareFromQueryBeforeConfig();
+				logWxEntryDiagnostics();
+			}
 			if (shouldInitWeChatJssdkOnLoad()) {
-				if (isWeChatInAppBrowser()) {
-					document.body.classList.add('is-wechat');
-					applyWxOpenLaunchSceneBodyClass();
-					logWxEntryDiagnostics();
-				}
 				if (isWxPcBrowser() && (isWxForceDebug() || isWxPcAutoDebugHost())) {
 					document.body.classList.add('wx-pc-debug');
 				}
@@ -3011,7 +2992,6 @@
 
 			document.addEventListener('WeixinOpenTagsError', function (e) {
 				console.warn('[WeixinOpenTagsError]', e && e.detail);
-				applyWxOpenLaunchSceneBodyClass();
 			});
 
 			if (isWeChatInAppBrowser()) {
@@ -3024,9 +3004,6 @@
 							);
 							return;
 						}
-						if (!isWxOpenLaunchAppSceneSupported()) {
-							showWxCopyLinkEntryTip();
-						}
 					});
 				}
 			} else {

+ 29 - 50
HBuilderProjects/shareUndefined.html

@@ -457,11 +457,11 @@
 			opacity: 1;
 		}
 
-		body.is-wechat.wx-jssdk-ready.wx-open-tag-scene #launch-btn {
+		body.is-wechat.wx-jssdk-ready #launch-btn {
 			display: block;
 		}
 
-		body.is-wechat.wx-jssdk-ready.wx-open-tag-scene #openApp {
+		body.is-wechat.wx-jssdk-ready #openApp {
 			display: none !important;
 		}
 
@@ -833,46 +833,36 @@
 			return /MicroMessenger/i.test(navigator.userAgent || '');
 		}
 
-		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() {
+		function ensureWxShareFromQueryBeforeConfig() {
 			if (!isWeChatInAppBrowser()) return;
-			var ok = isWxOpenLaunchAppSceneSupported();
-			document.body.classList.toggle('wx-open-tag-scene', ok);
-			document.body.classList.toggle('wx-copy-link-entry', !ok);
+			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 logWxEntryDiagnostics() {
 			if (!isWeChatInAppBrowser()) return;
 			console.log('[wx-entry]', {
-				entryFrom: getWxShareEntryFrom() || '(无,多为复制链接进入)',
-				openLaunchTagScene: isWxOpenLaunchAppSceneSupported(),
+				entryFrom: q('from') || '(无)',
 				signUrl: getWxConfigSignUrl()
 			});
 		}
 
-		function showWxCopyLinkEntryTip() {
-			showFabToast(
-				'当前为复制链接进入,微信不支持直接打开 App。请使用 App「分享到微信」发送卡片后,从卡片进入。'
-			);
-		}
-
 		function readQueryParam(name) {
 			return q(name);
 		}
@@ -1118,10 +1108,7 @@
 				wx.ready(function () {
 					weChatJssdkConfigured = true;
 					document.body.classList.add('wx-jssdk-ready');
-					applyWxOpenLaunchSceneBodyClass();
-					if (isWxOpenLaunchAppSceneSupported()) {
-						refreshWxLaunchTagAttrs(false);
-					}
+					refreshWxLaunchTagAttrs(false);
 					console.log('[wx.config] ready, htmlUrl=', htmlUrl);
 					resolve(true);
 				});
@@ -1190,11 +1177,6 @@
 					return;
 				}
 
-				if (/launch:fail/i.test(errMsg) && !isWxOpenLaunchAppSceneSupported()) {
-					showWxCopyLinkEntryTip();
-					return;
-				}
-
 				if (
 					/launch:fail/i.test(errMsg) &&
 					!tag._wxLaunchBareRetried &&
@@ -1219,6 +1201,7 @@
 				console.log('[wx] 未调用 getWxConfig');
 				return Promise.resolve(false);
 			}
+			ensureWxShareFromQueryBeforeConfig();
 			if (isWxPcBrowser()) {
 				console.warn(
 					'[wx] PC:请求 getWxConfig' + (fromUserClick ? '(按钮)' : '(进页)')
@@ -1895,12 +1878,12 @@
 			var launchTag = document.getElementById('launch-btn');
 			if (launchTag) launchTag.setAttribute('appid', WECHAT_OPEN_APP_ID);
 			bindWeChatLaunchTagEvents();
+			if (isWeChatInAppBrowser()) {
+				document.body.classList.add('is-wechat');
+				ensureWxShareFromQueryBeforeConfig();
+				logWxEntryDiagnostics();
+			}
 			if (shouldInitWeChatJssdkOnLoad()) {
-				if (isWeChatInAppBrowser()) {
-					document.body.classList.add('is-wechat');
-					applyWxOpenLaunchSceneBodyClass();
-					logWxEntryDiagnostics();
-				}
 				if (isWxPcBrowser() && (isWxForceDebug() || isWxPcAutoDebugHost())) {
 					document.body.classList.add('wx-pc-debug');
 				}
@@ -1909,7 +1892,6 @@
 
 			document.addEventListener('WeixinOpenTagsError', function (e) {
 				console.warn('[WeixinOpenTagsError]', e && e.detail);
-				applyWxOpenLaunchSceneBodyClass();
 			});
 
 			run();
@@ -1924,9 +1906,6 @@
 							);
 							return;
 						}
-						if (!isWxOpenLaunchAppSceneSupported()) {
-							showWxCopyLinkEntryTip();
-						}
 					});
 				}
 			} else {