求助: 开放标签wx-open-launch-app不渲染(wx.config已成功)?
发布于 5 年前 作者 xiawei 9211 次浏览 来自 问答

问题描述: 真机测试, wx.config已执行成功, 但是开放标签wx-open-launch-app没有渲染.

线上地址: https://wap.sc.10086.cn/mmplatClientWap/actWapNew/wx-zt-test/wx-zt-test/index.html

版本: 安卓7.0, 微信8.0.3

前置条件:

  1. 服务号已认证, JS接口安全域名也已填写
  2. "网页跳转移动应用"已关联了要跳转的移动应用APP

代码片段:


    
    
    

    document.addEventListener('WeixinOpenTagsError'function (e{
        console.log(e);                 //该事件没有执行
        console.error(e.detail.errMsg); // 无法使用开放标签的错误原因,需回退兼容。仅无法使用开发标签,JS-SDK其他功能不受影响
    });
    wxInit();
    function wxInit(){
        var url=window.location.href;
        var indexOfSharp=url.indexOf('#');
        if(indexOfSharp>0){
            url=url.substring(0,indexOfSharp);
        }
        $.ajax({
            url:"获取签名的后端接口地址",
            type:"POST",
            dataType:'JSON',
            data: {"url": url},
            success : function(data){
                if(data && data.result.code == "0"){
                    var obj = data.result.obj;
                    appId = "服务号的APPID";
                    timestamp = obj.timestamp.toString();
                    nonceStr = obj.noncestr;
                    signature = obj.signature;
                    wx.config({
                        debugtrue,
                        appId: appId,
                        timestamp: timestamp,
                        nonceStr: nonceStr,
                        signature: signature,
                        jsApiList: ['onMenuShareTimeline',
                            'onMenuShareAppMessage',
                            'onMenuShareQQ',
                            'onMenuShareWeibo',
                            'onMenuShareQZone',
                            'hideMenuItems'
                        ],
                        openTagList: ['wx-open-launch-app']
                    });
                }
            }
        });
    }
    wx.ready(function () {
        // config信息验证后会执行ready方法,所有接口调用都必须在config接口获得结果之后,
        //config是一个客户端的异步操作,所以如果需要在页面加载时就调用相关接口,
        //则须把相关接口放在ready函数中调用来确保正确执行。对于用户触发时才调用的接口,则可以直接调用,不需要放在ready函数中
        alert('wx.config成功');//wx.ready执行了
    });
    wx.error(function (res{
        // config信息验证失败会执行error函数,如签名过期导致验证失败,具体错误信息可以打开config的debug模式查看,
        //也可以在返回的res参数中查看,对于SPA可以在这里更新签名
        alert('wx.config失败');//wx.error没有执行
        alert(res);
    });
    var btn = document.getElementById('launch-btn');
    btn.addEventListener('ready'function (e{
        alert('可以点击按钮拉起掌厅了');
    });
    btn.addEventListener('launch'function (e{
        console.log('拉起掌厅成功');
    });
    btn.addEventListener('error'function (e{
        console.log('拉起掌厅失败, 错误消息: ');
        console.log(e);
    });


回到顶部