外部頁面跳轉微信 或者小程序 原理都是用Scheme
喚醒微信 最為簡單
location.href = 'weixin://';
喚醒小程序稍微復雜點,最近有個需求 是在H5落地頁 喚醒小程序鑲嵌的webview 頁面, 搭配微信雲開發使用。
喚醒小程序稍微復雜點,最近有個需求 是在H5落地頁 喚醒小程序鑲嵌的webview 頁面, 搭配微信雲開發使用。
async function test() {
var containerEl = document.getElementById('public-web-container')
containerEl.classList.remove('hidden') containerEl.classList.add('full', 'public-web-container') var c = new cloud.Cloud({ // 必填,表示是未登錄模式 identityless: true, // 小程序 AppID resourceAppid: '小程序 AppID', // <!-- replace --> // 雲開發環境 ID resourceEnv: '雲開發環境 ID', // <!-- replace --> }) await c.init() window.c = c var buttonEl = document.getElementById('public-web-jump-button') var buttonLoadingEl = document.getElementById('public-web-jump-button-loading') try { await openWeapp(() => { buttonEl.classList.remove('weui-btn_loading') buttonLoadingEl.classList.add('hidden') }) } catch (e) { buttonEl.classList.remove('weui-btn_loading') buttonLoadingEl.classList.add('hidden') throw e }
})
//生成Scheme 鏈接
async function openWeapp(onBeforeJump) { var c = window.c const res = await c.callFunction({ name: 'public', data: { action: 'getUrlScheme', }, }) console.warn(res) if (onBeforeJump) { onBeforeJump() } location.href = res.result.openlink }
其中 getUrlScheme 這個函數就需要放在小程序雲開發上。