Open yanyue404 opened 2 years ago
在微信小程序后台配置生成,得到 Scheme 链接可以在外部浏览器环境打开小程序。
# 输入: - 小程序页面路径: pages/home/home - 启动 query 参数: fromId=72472 # 输出: weixin://dl/business/?t=ccxxxxxx
<wx-open-launch-weapp>
说明:
微信开放标签使用步骤与微信 JS-SDK 类似,需要引入 JS 文件等步骤,并通过 config 接口注入权限验证配置并申请所需的开放标签。
参数:
用例示例:
<wx-open-launch-weapp id="launch-btn" username="gh_xxxxxxxx" path="pages/home/index?user=123&action=abc" > <script type="text/wxtag-template"> <style>.btn { padding: 12px }</style> <button class="btn">打开小程序</button> </script> </wx-open-launch-weapp> <script> var btn = document.getElementById('launch-btn'); btn.addEventListener('launch', function (e) { console.log('success'); }); btn.addEventListener('error', function (e) { console.log('fail', e.detail); }); </script>
wx.miniProgram.switchTab
wx.miniProgram.navigateTo
const toMiniProgram = () => { const tabBar = [ "pages/home/home", "pages/productList/productList", "pages/mine/mine", ]; let url = this.path; let [path, query = ""] = url.split("?"); if (tabBar.includes(path) || url === "") { console.log("跳 tab", url || "pages/home/home"); wx.miniProgram.switchTab({ url: url ? "/" + url : "/pages/home/home", }); } else { console.log("跳 navigateTo", url); wx.miniProgram.navigateTo({ url: "/" + url, }); } };
打开链接:https://xxx.cn/sms-to-miniprogram/#/?url=weixin%3A%2F%2Fdl%2Fbusiness%2F%3Ft%3DJLL3qb69Bid&path=pages%2Fhome%2Fhome
3.9 日微信发布新规则,自 2022 年 4 月 11 日起,URL Scheme 和 URL Link (以下统称为 “链接” )接口能力规则将进行以下调整:
对业务的影响:
实现思路
生成设备 deviceId 的方案
import FingerprintJS from "@fingerprintjs/fingerprintjs"; const createVisitorId = async () => { const fp = await FingerprintJS.load({ screen_resolution: true }); const result = await fp.get(); const visitorId = result.visitorId; return visitorId; };
改版后的打开链接:https://xxx.cn/sms-to-miniprogram/#/?path=pages%2Fhome%2Fhome
if (!this.isWeixin && !this.isMiniProgram) { const schema = await this.getSchemaURL(this.path); this.schema = schema; location.href = schema; } else { // 微信环境下打开微信公众号的新版链接适配,? 后参数需转义 let params = this.path.match(/https:\/\/mp\.weixin\.qq\.com\/s\?(.*)/); if (params && params[1]) { this.path = "pages/web-page/web-page?url=https://mp.weixin.qq.com/s?" + encodeURIComponent(params[1]); } }
怎样在各个环境打开微信小程序
在微信小程序后台配置生成,得到 Scheme 链接可以在外部浏览器环境打开小程序。
<wx-open-launch-weapp>
说明:
微信开放标签使用步骤与微信 JS-SDK 类似,需要引入 JS 文件等步骤,并通过 config 接口注入权限验证配置并申请所需的开放标签。
参数:
用例示例:
wx.miniProgram.switchTab
和wx.miniProgram.navigateTo
打开链接:https://xxx.cn/sms-to-miniprogram/#/?url=weixin%3A%2F%2Fdl%2Fbusiness%2F%3Ft%3DJLL3qb69Bid&path=pages%2Fhome%2Fhome
微信小程序 URL Scheme 生成规则调整
3.9 日微信发布新规则,自 2022 年 4 月 11 日起,URL Scheme 和 URL Link (以下统称为 “链接” )接口能力规则将进行以下调整:
对业务的影响:
实现思路
生成设备 deviceId 的方案
改版后的打开链接:https://xxx.cn/sms-to-miniprogram/#/?path=pages%2Fhome%2Fhome
微信小程序支持打开新版微信公众号 webview
参考