微信公众号扫码

1、需要引入js

<script src="http://res.wx.qq.com/open/js/jweixin-1.2.0.js"></script>

2、扫码

    wx.config({
        debug: false, // 开启调试模式,调用的所有api的返回值会在客户端alert出来,若要查看传入的参数,可以在pc端打开,参数信息会通过log打出,仅在pc端时才会打印。
        appId: appId, // 必填,公众号的唯一标识
        timestamp: timestamp, // 必填,生成签名的时间戳    <%= Html.Encode(ViewData["timestamp" ]) %>
        nonceStr: nonceStr, // 必填,生成签名的随机串
        signature:signature, // 必填,签名
        jsApiList: ['scanQRCode'] // 必填,需要使用的JS接口列表, 这里只需要调用扫一扫
    });

    wx.ready(function() {
        wx.checkJsApi({
            jsApiList: ['scanQRCode'],
            success: function(res) {
                console.log('wx.ready', res)
            }
        });
        wx.scanQRCode({
            needResult: 1, // 默认为0,扫描结果由微信处理,1则直接返回扫描结果,
            scanType: ["qrCode"], // 可以指定扫二维码还是一维码,默认二者都有
            success: function(res) {
                // 扫码成功,跳转到二维码指定页面(res.resultStr为扫码返回的结果)
     
            },
            error: function(res) {
                console.log('扫码error', res);
                if (res.errMsg.indexOf('function_not_exist') > 0) {
                   console.log('当前版本过低,请进行升级');
                }
            }
        });

    });

 

posted @ 2022-03-04 15:17  (⊙o⊙)买噶  阅读(220)  评论(0编辑  收藏  举报