一、首先,这是使用官方提供的方法去生成的,所以你需要准备好APPID 和 小程序秘钥,并且会小程序的简单开发
二、在小程序中,写入如下方法,调用一下即可获得base64格式的图片,然后将base64转换成图片格式保存好即可:
wx.request({
url: 'https://api.weixin.qq.com/cgi-bin/token',
header: { 'content-type': 'application/json'},
data: {
grant_type: 'client_credential',
appid:'你的小程序APPID放这里',
secret: '你的小程序secret key 放这里'
},
success(res) {
var accessToken = res.data.access_token
wx.request({
//url: ‘https://api.weixin.qq.com/wxa/getwxacodeunlimit?access_token=‘+accessToken,
url: 'https://api.weixin.qq.com/wxa/getwxacode?access_token='+accessToken,
method: 'POST',
responseType: 'arraybuffer',
data: {
"path": '你想要扫描二维码后,跳转小程序的地址,如:goodsPages/pages/productList/productList?searchKey=单道可调移液器',
"width": 430,
},
success(res) {
console.log(res.data)
let base64 = wx.arrayBufferToBase64(res.data)
console.log(base64)
let codeImg= 'data:image/PNG;base64,' + base64
console.log(codeImg)
_this.sdd = codeImg
},
})
}
})