8***@qq.com
8***@qq.com
  • 发布:2019-04-04 16:04
  • 更新:2019-04-07 17:24
  • 阅读:2646

H5扫一扫怎么弄的?是用web-view加载h5页面用微信公众号的方法吗?

分类:HTML5+
<web-view v-if="url!=''" :src="https://mini.yanhangtec.com/smallwechart/wechat/wechatLoginApi/getScanCode"></web-view>  

<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<script src="https://code.jquery.com/jquery-3.1.1.min.js"></script>
<script type="text/javascript" src="//js.cdn.aliyun.dcloud.net.cn/dev/uni-app/uni.webview.0.1.52.js"></script>
<script src="https://res.wx.qq.com/open/js/jweixin-1.0.0.js"></script>
<script type="text/javascript">
alert('0')
$.ajax({
type: "get",
url: "/smallwechart/wechat/wechatLoginApi/scanQRCode",//自己填写请求地址
data: {url: window.location.href},
success: function (result) {
console.log(JSON.stringify(result),'result....')
wx.config({
// 开启调试模式,调用的所有api的返回值会在客户端alert出来,若要查看传入的参数,可以在pc端打开,参数信息会通过log打出,仅在pc端时才会打印。
debug: true,
// 必填,公众号的唯一标识
appId: result.data.appId,
// 必填,生成签名的时间戳
timestamp: "" + result.data.timestamp,
// 必填,生成签名的随机串
nonceStr: "" + result.data.nonceStr,
// 必填,签名,见附录1
signature: result.data.signature,
// 必填,需要使用的JS接口列表,所有JS接口列表见附录2
jsApiList: result.data.jsApiList
});
}
})

    wx.error(function (res) {  
        alert("出错了:" + res.errMsg);//这个地方的好处就是wx.config配置错误,会弹出窗口哪里错误,然后根据微信文档查询即可。  
    });  

    wx.ready(function () {  
        wx.checkJsApi({  
            jsApiList: ['scanQRCode'],  
            success: function (res) {  

            }  
        });  
        wx.scanQRCode({  
            needResult: 1, // 默认为0,扫描结果由微信处理,1则直接返回扫描结果,  
            scanType: ["qrCode", "barCode"], // 可以指定扫二维码还是一维码,默认二者都有  
            success: function (res) {  
                var scanCode = res.resultStr; // 当needResult 为 1 时,扫码返回的结果  
                alert(scanCode)  
                document.addEventListener('UniAppJSBridgeReady', function() {  
                    uni.reLauch({  
                        url: '/pages/tabbar/component/component?scanCode='+scanCode  
                    })  
                });  

            }  
        });  

    });  

</script>  
<style type="text/css">  
    * {  
        -webkit-user-select: none;  
    }  

    html,  
    body {  
        margin: 0px;  
        padding: 0px;  
        height: 100%;  
    }  
</style>  

</head>
<body>
sddfgh
</body>
</html>

2019-04-04 16:04 负责人:无 分享
已邀请:
DCloud_heavensoft

DCloud_heavensoft

http://ask.dcloud.net.cn/article/35380

该问题目前已经被锁定, 无法添加新回复