|
|
@@ -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();
|
|
|
}
|
|
|
});
|
|
|
}
|