微信小程序-生成二维码-如何在本地js中调试调用

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/sinat_36146776/article/details/81112975

官方链接

        let appId = 'wxbf338********361';
        let secret = 'ce5e6c73*********************8a';

        let getUrl = 'https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=appid&secret=secret';
        wx.request({
            url: getUrl, 
            data: {
                x: '' ,
                y: ''
            },
            header: {
                'content-type': 'application/json' // 默认值
            },
            method:'GET',
            dataType:'json',
            success: function(res) {
                let getUrl = 'https://api.weixin.qq.com/wxa/getwxacodeunlimit?access_token='+res.data.access_token;

                wx.request({
                    url: getUrl, //仅为示例,并非真实的接口地址
                    data: {
                        width:400,//生成二维码图片大小,越大,越清晰
                        scene:'38,0',//值视项目而定
                        page:'pages/wechat'

                    },
                    header: {
                        'content-type': 'application/octet-stream' // 默认值
                    },
                    method:'POST',
                    dataType:'json',
                    responseType:'arraybuffer',
                    success: function(res2) {
                        let base64Image = 'data:image/png;base64,' + wx.arrayBufferToBase64(res2.data);
                        if (res2.statusCode == 200) {
                            that.setData ({
                                QRImage: base64Image,  // data 为接口返回的base64字符串,直接添加到image的src中可显示,在canvas上绘图,模拟器显示,但是真机不显示(待解)
                            })
                        }
                    }
                })
            }
        })

猜你喜欢

转载自blog.csdn.net/sinat_36146776/article/details/81112975