微信浏览器内 h5 直接唤醒 app 之 微信开放标签 wx-open-launch-app
- wx.config({
- appId: '',
- debug: true,
- timestamp: '',
- nonceStr: '',
- signature: '',
- jsApiList: [
- 'onMenuShareTimeline', // 分享给好友
- 'onMenuShareAppMessage', // 分享到朋友圈
- ],
- openTagList: ['wx-open-launch-app’] // 获取开放标签权限
- });
- {errMsg: "config:ok”}
说明你已经接入JS-SDK成功了
遗憾的是截至2020年7月13号为止,微信开发者工具还是无法支持微信开放标签的调试功能,只能在手机上调试并且是在加了微信安全域名的服务器环境下调试,着实麻烦
- // 忽略自定义元素标签抛出的报错
- Vue.config.ignoredElements = [
- 'wx-open-launch-app',
- ];
- new Vue({
- el: '#app',
- template: '<app/>',
- components: { app }
- })
wx-open-launch-app 标签组件
- <wx-open-launch-app
- :id="id"
- class="launch-btn"
- :appid="appId"
- :extinfo="extinfoStr"
- >
- <script type="text/wxtag-template">
- <style>.btn {height: 96px;}</style>
- <div class="btn">打开app</div>
- </script>
- </wx-open-launch-app>
- mounted(){
- var btn = document.getElementById(this.id)
- btn.addEventListener('launch', e => {
- // 在此处可设置粘贴板内数据,数据是传递给 app 的参数进,
- console.log('success');
- });
- btn.addEventListener('error', e => {
- // 在此处可设置粘贴板内数据,数据是传递给 app 的参数进,
- console.log('fail', e.detail);
- // 唤醒失败的情况下,可用于降级处理比如在此处跳转到应用宝
- });
- }
7、如果微信版本低于7.0.12 开放标签是无法使用的,所以最好在开放标签外套一层 DIV 用于点击事件,在事件中断段微信版本号如果低于,则降级到应用宝之类的方案
- <div @click="launch">
- <wx-open-launch-app
- :id="id"
- class="launch-btn"
- :appid="appId"
- :extinfo="extinfoStr"
- >
- <script type="text/wxtag-template">
- <style>.btn {height: 96px;}</style>
- <div class="btn">打开app</div>
- </script>
- </wx-open-launch-app>
- </div>
- launch(){
- // 在此处可设置粘贴板内数据,数据是传递给 app 的参数进
- if(!this.enable){
- // 不支持标签降级处理
- }
- }
四、最后当然是封装成项目中的一个组件
- <template>
- <div @click="launch">
- <wx-open-launch-app
- :id="id"
- class="launch-btn"
- :appid="appId"
- :extinfo="extinfoStr"
- >
- <script type="text/wxtag-template">
- <style>.btn {height: 96px;}</style>
- <div class="btn">打开app</div>
- </script>
- </wx-open-launch-app>
- </div>
- </template>
- <script>
- import globalConfig from '@assets/js/config'
- import { copyToClipboard } from '@assets/js/utils'
- import { getWeixinVersion, onBridgeReady } from '@assets/js/weixin/weixin'
- let idIndex = 0
- export default {
- name: 'LaunchButton',
- props: {
- extinfo: {
- type: Object,
- default: ''
- },
- },
- watch: {
- extinfo: {
- handler(n){
- this.extinfoStr = JSON.stringify(n)
- },
- immediate: true
- }
- },
- data() {
- idIndex++
- return {
- id: 'wxopenLanchAppId' + idIndex,
- appId: globalConfig.WEIXIN_APP_ID,
- enable: false,
- extinfoStr: '',
- }
- },
- methods: {
- redirectToApp(){
- setTimeout(()=>{
- window.location.href = globalConfig.YING_YONG_BAO
- }, 400)
- },
- setClipboard(){
- console.log('start copy')
- let copyObject = {
- app: 'yogo'
- }
- for(var k in this.extinfo){
- copyObject[k] = this.extinfo[k]
- }
- copyObject = JSON.stringify(copyObject)
- copyToClipboard(copyObject)
- console.log('end copy')
- },
- launch(){
- this.setClipboard()
- if(!this.enable){
- this.redirectToApp()
- }
- }
- },
- created(){
- // 微信版本号大于 7.0.12 开放标签才可进行 唤醒 app 跳转
- const wxVersion = getWeixinVersion()
- if(wxVersion){
- let v = wxVersion.split('.')
- if(v[0]>=7){
- if(v[1]>=0){
- if(v[2]>=12){
- this.enable = true
- }
- }
- }
- }
- },
- mounted(){
- var btn = document.getElementById(this.id)
- btn.addEventListener('launch', e => {
- this.setClipboard()
- console.log('success');
- });
- btn.addEventListener('error', e => {
- console.log('fail', e.detail);
- this.setClipboard()
- this.redirectToApp()
- });
- }
- }
- </script>
- <style lang="scss" scoped>
- .launch-btn{
- position: absolute;
- left: 0;
- top: 0;
- width: 100%;
- height: 100%;
- z-index: 1;
- opacity: 0;
- // background: red;
- }
- </style>
注:转载请注明出处博客园:sheldon(willian12345@126.com)
https://github.com/willian12345
微信浏览器内 h5 直接唤醒 app 之 微信开放标签 wx-open-launch-app的更多相关文章
- 实现微信浏览器内打开App Store链接(已被和谐,失效了)
微信浏览器是不支持打开App Store 页面的,不知道微信为什么这么做.比如你页面写 <a href=”http://itunes.apple.com/us/app/id399608199″& ...
- 实现微信浏览器内打开App Store链接
http://www.ildsea.com/1781.html 微信浏览器是不支持打开App Store 页面的,不知道微信为什么这么做.比如你页面写 <a href=”http://itune ...
- [转]实现微信浏览器内打开App Store链接
微信浏览器是不支持打开App Store 页面的,不知道微信为什么这么做.比如你页面写 <a href=”http://itunes.apple.com/us/app/id399608199″& ...
- 解决微信浏览器内video全屏问题
前端离职,让我写个视频播放页面,木办法只有我来搞了. 默认用h5的 video标签 测试时候发现微信浏览器内访问video自动全屏播放. 搜了下 webkit-playsinline="tr ...
- 微信浏览器内置JavaScript 对象:WeixinJSBridge
微信公众平台开发 微信公众平台开发模式 企业微信公众平台 微信浏览器 分享到朋友圈 发送给好友 分享到腾讯微博 作者:方倍工作室 原文: http://www.cnblogs.com/txw1958/ ...
- Android 浏览器内 H5 电脑 Chrome 调试
Android 浏览器内 H5 调试 chrome://inspect 移动前端调试方案(Android + Chrome 实现远程调试) adb 相关资源 adb shell(ADB Kits)下载 ...
- 微信浏览器内建的WeixinJSBridge 实现“返回”操作
微信浏览器内建的WeixinJSBridge 实现“返回”操作 WeixinJSBridge.call('closeWindow');
- WeixinJSBridge:微信浏览器内置JavaScript 对象
微信公众平台开始支持前端网页,大家可能看到很多网页上都有分享到朋友圈,关注微信等按钮,点击它们都会弹出一个窗口让你分享和关注,这个是怎么实现的呢?今天就给大家讲解下如何在微信公众平台前端网页上添加分享 ...
- 微信h5跳转小程序wx-open-launch-weapp开放标签不显示(已解决)
前言: 前几天成功对接了跳转第三方小程序的功能,今天有个页面有需要对接.但是奇怪的是用的和上次一模一样的配置,但就是死活不显示wx-open-launch-weapp这个开放标签的按钮,看不到任何效果 ...
随机推荐
- unittest实现用例运行失败截图
把这个方法放到父类basecase(unittest.TestCase)就行了 #coding: utf-8 import unittest, random, os, traceback from s ...
- LR字符串处理函数-lr_save_var
int lr_save_var ("截取的字符串"+start,len,options,param_name) start:表示从第几位截取 len:表示截取长度 option ...
- 深入理解JVM(③)低延迟的Shenandoah收集器
前言 Shenandoah作为第一款不由Oracle(包括一起的Sun)公司的虚拟机团队所领导开发的HotSpot垃圾收集器.是只存在于OpenJDK当中的,最初由RedHat公司创建的,在2014年 ...
- 学员操作——制作5s关闭广告
<!DOCTYPE html><html> <head> <meta charset="utf-8"> <title>广 ...
- Python 程序报错崩溃后,如何倒回到崩溃的位置?
假设我们有一段程序,从 Redis 中读取数据,解析以后提取出里面的 name 字段: import json import redis client = redis.Redis() def read ...
- Redis持久性——RDB和AOF
Redis持久性 Redis提供了不同的持久性选项: RDB持久性以指定的时间间隔执行数据集的时间点快照. AOF持久性记录服务器接收的每个写入操作,将在服务器启动时再次播放,重建原始数据集.使用与R ...
- centos 6.5 dhcp桥接方式上网络设置
首先虚拟机和主机之间采用桥接模式 然后在虚拟机中进行设置,首先进入到目录 /etc/sysconfig/network-scripts/ [root@localhost ~]# cd /etc/sys ...
- trollcave解题
这是第一次完整地进行模拟渗透,前前后后一共花了一天时间,花了点时间写了个writeup. 博主是个菜鸡,如果有大神看到,请轻喷...... writeup下载:https://hrbeueducn-m ...
- python黑帽子之tcp客户端
在渗透测试过程中,我们经常会需要创建一个tcp客户端来连接服务,发送垃圾数据,进行模糊测试等任务,所以我们来用python创建一个简单的tcp客户端. import sockettarget_host ...
- MongoDB入门二
MongoDB配置 本地启动 c:\MongoDB\bin>mongod.exe --dbpath "C:\\MongoDB\data\db" --logpath " ...