获取二维码返回不正确?
发布于 5 年前 作者 xiulancheng 7837 次浏览 来自 官方Issues

//index.js

//获取应用实例

const app = getApp()


Page({

onLoad: function () {

wx.request({

url: 'https://api.weixin.qq.com/cgi-bin/token',

header: { 'content-type': 'application/json' },

data: {

grant_type: 'client_credential',

appid: 'XXXXX',

secret: '秘钥'

},

success(res) {

var accessToken = res.data.access_token

wx.request({

url: 'https://api.weixin.qq.com/wxa/getwxacode?access_token=' + accessToken,

method: 'POST',

responseType: 'arraybuffer',

data: {

"path": 'pages/index/index',

"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)

},

})

}

})

}

})

--------------------------------------------------

运行后返回的accessToken有问题

ArrayBuffer(112) {}

eyJlcnJjb2RlIjo0MDAwMSwiZXJybXNnIjoiaW52YWxpZCBjcmVkZW50aWFsLCBhY2Nlc3NfdG9rZW4gaXMgaW52YWxpZCBvciBub3QgbGF0ZXN0IGhpbnRzOiBbaEtmQ0tuQUNlLXJTVG9fIV0ifQ==

data:image/PNG;base64,eyJlcnJjb2RlIjo0MDAwMSwiZXJybXNnIjoiaW52YWxpZCBjcmVkZW50aWFsLCBhY2Nlc3NfdG9rZW4gaXMgaW52YWxpZCBvciBub3QgbGF0ZXN0IGhpbnRzOiBbaEtmQ0tuQUNlLXJTVG9fIV0ifQ==


1 回复

https://developers.weixin.qq.com/miniprogram/dev/api-backend/open-api/qr-code/wxacode.createQRCode.html#method-cloud

云调用不香吗? buffer长度这么点,那是因为接口报错了,把它转为字符串就知道报什么错了

回到顶部