vue开发微信公众号网页,在ios上没法调起扫一扫功能,安卓正常,有人遇到并解决了吗?
发布于 6 年前 作者 xiabai 696 次浏览 来自 问答
<script type="text/javascript" src="http://res2.wx.qq.com/open/js/jweixin-1.6.0.js"></script>
methods:{
                wxconfigInit() {
            const urlValue = (window.location.href).split('#')[0// 动态获取当前页的#之前的url地址,这个是有https:// 或者http://的
            console.log("uuuuuuu " + urlValue);
            let params = {
                url: urlValue 
            };
            getSignature(params).then(res => {
                console.log("sign : " + JSON.stringify(res));
                if (res != null) {
                    this.sign.appId = res.appid;
                    this.sign.timestamp = res.timestamp;
                    this.sign.nonceStr = res.nonceStr;
                    this.sign.signature = res.signature;
                    console.log(this.sign);
                    // 调用后端接口返回,配置需要的结果
                    wx.config({
                        debugtrue// 开启调试模式,
                        appId: res.appid, // 必填,企业号的唯一标识,此处填写企业号corpid
                        timestamp: res.timestamp, // 必填,生成签名的时间戳
                        nonceStr: res.nonceStr, // 必填,生成签名的随机串
                        signature: res.signature, // 必填,签名,见附录1
                        jsApiList: [ 'checkJsApi',  'scanQRCode' ] // 必填,需要使用的JS接口列表,所有JS接口列表见附录2
                    })
                }
            })
            .catch(err => {
                console.log(err.msg)
            })

        },
        //扫码获取合同号
        handleScan() { //获取服务器签名
            let _this = this
            wx.error(function(res{
                alert("出错了:" + JSON.stringify(res));//这个地方的好处就是wx.config配置错误,会弹出窗口哪里错误,然后根据微信文档查询即可。
            });
            wx.ready(function(){
                wx.checkJsApi({   //这个配置检查也是显示正确
                    jsApiList: ['scanQRCode'],   //检查是否有扫描有二维码权限
                    successfunction (res{
                        if (res.checkResult.scanQRCode === true) {
                            wx.scanQRCode({
                                needResult : 1// 默认为0,扫描结果由微信处理,1则直接返回扫描结果,
                                // scanType : [ "qrCode"], // 可以指定扫二维码还是一维码,默认二者都有
                                success : function(res{
                                    alert(JSON.stringify(res)+'success')
                                    let result
                                    if(res.resultStr.indexOf(',')!=-1){
                                        result = res.resultStr.split(',')[1]; // 当needResult 为 1 时,扫码返回的结果
                                    }else{
                                        result = res.resultStr
                                    }
                                    _this.formData.contractNum = result
                                },
                                failfunction(error{
                                    alert('fail' + res)
                                },
                                error : function(error){
                                    alert('error',error)
                                }
                            });
                        } else {
                            alert('抱歉,当前客户端版本不支持扫一扫')
                        }
                    },
                    failfunction(res// 检测getNetworkType该功能失败时处理
                        alert('fail' + res)
                    }
                });
                
            })
        },
}
created(){
        this.wxconfigInit()
    },
2 回复

有报错信息吗?

经确认,开发者自行修复以下问题即可:
1. https的网页不能引用http的jweixin.js,改为https资源即可。
2. url在签名过程中,&变成了&amp;,请排查修复即可。

——————————————————————

你好,请先确认是否走到了wx.config的逻辑,确认后麻烦尽快回复下哈,我这边会协助排查。
回到顶部