h5页面打开app,微信开放标签的使用教程。
发布于 3 年前 作者 xia50 1020 次浏览 来自 分享

<wx-open-launch-app id=“launch-btn-2” appid=“您的appid”>
<template>
<style>.btn { padding: 12px }</style>
<button class=“btn”>App内查看</button>
</template>
</wx-open-launch-app>

&lt;script&gt;
     let url = window.location.href;
        if(url.indexOf("#")&gt;0){
            url = url.split('#')[0];
        }
        $.ajax({
            method: "get",
            url: '获取tocken等url,是后台人员提供的',   
            data: {
                
            },
            contentType: false,
            // 告诉jQuery不要去设置Content-Type请求头
            processData: false,
            // 告诉jQuery不要去处理发送的数据
        })
        .done(function( res ) {
            console.log(res);
            if(res.code==1){
                var res_data = res.data;
                console.log(res_data);
                wx.config({
                    debug: true, // 开启调试模式,调用的所有api的返回值会在客户端alert出来,若要查看传入的参数,可以在pc端打开,参数信息会通过log打出,仅在pc端时才会打印。
                    appId: res_data.appId, // 必填,公众号的唯一标识
                    timestamp: res_data.timestamp, // 必填,生成签名的时间戳
                    nonceStr: res_data.nonceStr, // 必填,生成签名的随机串
                    signature: res_data.signature,// 必填,签名
                    jsApiList: [
                       
                        "menuItem:share:facebook"
                    ], // 必填,需要使用的JS接口列表
                    openTagList: ['wx-open-launch-app'] // 可选,需要使用的开放标签列表,例如['wx-open-launch-app']
                });
               
                
            }else{
                // _this.$toast("请用在微信中打开");
               alert(res+"123");
            }
        });

        wx.ready(function () {
            wx.checkJsApi({
                jsApiList: ['wx-open-launch-app'], // 需要检测的JS接口列表,所有JS接口列表见附录2,
                success: function (res) {
                    console.log('可用')
                },
                fail: (err) =&gt; {
                    console.log(err, '不可用')
                }
            });
            var btn = document.getElementById('launch-btn-2');
            btn.addEventListener('ready', function (e) {
                console.log('ready');
            });
            //点击立即使用按钮
            btn.addEventListener('launch',  (e)=&gt; {
                console.log('launch');   
            });
            btn.addEventListener('error', function (e) {
                console.log('error');
            });
            // config信息验证后会执行ready方法,所有接口调用都必须在config接口获得结果之后,config是一个客户端的异步操作,所以如果需要在页面加载时就调用相关接口,则须把相关接口放在ready函数中调用来确保正确执行。对于用户触发时才调用的接口,则可以直接调用,不需要放在ready函数中
        });
        
        
        
        
        
        
        
        
        //如果是vue,上面的标签部分,则可以用这个:
        &lt;wx-open-launch-app id="launch-btn" appid="您的appid"&gt;
        &lt;script type="text/wxtag-template"&gt;
            &lt;style&gt;
                .bottom-btn{
                    -webkit-user-select:none; 
                    font-weight:bold;
                }
                .bottom-btn:link,.bottom-btn:visited{color:#fff;}
                .bottom-btn:active{color:#fff; background:linear-gradient(90deg,rgba(255,82,59,1) 0%,rgba(255,176,69,1) 100%);}

            &lt;/style&gt;
            &lt;a class="bottom-btn"&gt;立即使用&lt;/a&gt;
        &lt;/script&gt;
    &lt;/wx-open-launch-app&gt;
        
        
        
        
        如果有问题,可联系我:13241108634,加微信即可。
1 回复

如果出现是空白页附载h5上面,是客户端没有finish。

回到顶部