美文网首页
15.关于获取小程序码的理解

15.关于获取小程序码的理解

作者: 陈情令 | 来源:发表于2021-11-15 16:04 被阅读0次

1.首先得根据appid 和秘钥获取 access_token

地址:https://mp.weixin.qq.com/debug/cgi-bin/apiinfo?t=index&type=%E5%9F%BA%E7%A1%80%E6%94%AF%E6%8C%81&form=%E8%8E%B7%E5%8F%96access_token%E6%8E%A5%E5%8F%A3%20/token

2.获取到access_token 可以生成小程序码

但是要在注意一点 由于前端这边不好将 api添加到后台 只有在小程序取消勾选 不效验合法域名 

代码:  

getQrcode(){

    wx.request({

       url: "https://api.weixin.qq.com/wxa/getwxacodeunlimit?access_token=51_UmM1XK02jcyRF6RGFD_6q5sgqysNWkXQiLv1SJ4eASMd5wi1AgfI3BoCDHcA8yWfSgP2ihvuPkIKeP7mSw4enFx7vhpyP6iRrfIgKcFHeltmmtyiTq7vWH3ezz7",//域名省略

       data: JSON.stringify({

        page:"pages/login/login",

        scene: "a=1",

        // check_path: true,

        // env_version: "release",

        width:300

       }),

       responseType: 'arraybuffer', //关键是这里

       header: {

        'Accept': "*/*",

        "Content-Type": "application/x-www-form-urlencoded",

      },

       method: 'POST',

       dataType: 'json',

       success: function(res){

         console.log(res,"res");

        let qrcodeUrl=res.data;//服务器小程序码地址

        console.log(qrcodeUrl,"res");

       },

       fail: function(){},

      //  complete: options.complete || function(){}

     })

   },

将api给后端进行处理

相关文章

网友评论

      本文标题:15.关于获取小程序码的理解

      本文链接:https://www.haomeiwen.com/subject/nasqtrtx.html