微信浏览器内 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这个开放标签的按钮,看不到任何效果 ...
随机推荐
- 大厂面试过程复盘(微信/阿里/头条均拿offer,附答案篇)
背景 本人前端,3年经验,由于个人的原因,决定跳槽,于是大概3月开始找工作,总历时大概2个月,面试了微信/阿里/头条,三家都拿到了offer,来分享一下面经. 问题比较多,而且很多面试题都是跟个人项目 ...
- .Net Core微服务入门全纪录(三)——Consul-服务注册与发现(下)
前言 上一篇[.Net Core微服务入门全纪录(二)--Consul-服务注册与发现(上)]已经成功将我们的服务注册到Consul中,接下来就该客户端通过Consul去做服务发现了. 服务发现 同样 ...
- mysql HAVING用法
原文链接:https://www.cnblogs.com/mr-wuxiansheng/p/11188733.html having字句可以让我们筛选分组之后的各种数据,where字句在聚合前先筛选记 ...
- 深入理解 EF Core:EF Core 读取数据时发生了什么?
阅读本文大概需要 11 分钟. 原文:https://bit.ly/2UMiDLb 作者:Jon P Smith 翻译:王亮 声明:我翻译技术文章不是逐句翻译的,而是根据我自己的理解来表述的.其中可能 ...
- 红米手机 android4.4.4 root之路
第一步: 进入360root官网下载apk安装包: http://root.360.cn/index.html 说明:不是所有的机型都能root, 一般android5.0 以下的系统root的成功 ...
- SQLSTATE[42000]: Syntax error or access violation: 1253 COLLATION 'utf8mb4_unicode_ci' is not valid for CHARACTER SET 'binary'
SQLSTATE[42000]: Syntax error or access violation: 1253 COLLATION 'utf8mb4_unicode_ci' is not valid ...
- 用一杯茶时间搭建Gitea服务器
一.简单介绍 Gitea搭建局域网内的基于git的代码托管服务器,可以实现的功能包括:组织管理.团队管理.组织仓库设定.团队仓库分配.组织及团队权限分配管理.仓库添加PC协作者.仓库添加组织团队.分 ...
- 常用电子邮件协议服务POP3/IMAP/SMTP/Exchange
标题: 常用电子邮件协议服务POP3/IMAP/SMTP/Exchange 作者: 梦幻之心星 347369787@QQ.com 标签: [电子邮件, 服务, 协议] 目录: [客户端] 日期: 20 ...
- Freemarker在replace替换是对NULL值的处理
freemarker的对象调用内建函数时,比如userInfo对象的birthDay函数,页面${userInfo.birthDay}调用,当我想将birthDay值中的“-”替换为“/”时,${us ...
- Validate日期校验
public class Validate { private static Regex RegNumber = new Regex("^[0-9]+$"); private st ...