下面的代码可以保存生成的二维码图片,但打不开,不论是jpg,png,jpeg都不行
const createCodeBar = co(function* (){
const postRequest = promisify(request.post, { multiArgs: true,'json': true });
let token = 'h3-Oda1A05Nit6EEZEkFqvgemQPCpRj1rmwYCp3puMahUH_a4rMXbYlS2NoMsjYiVhci0uDbe-VNlQAui1Ljp-fyFi8PqrGYZEsUMA0G88xmob-fheZ2c_85Jw8tnMx-NFSbAHACUH';
console.log('token:' + token);
let form = {
'path':'page/bookflow/pages/sharegroup/sharegroup?groupId=279&introducer=1686&fromBarcode=true'
}
form = JSON.stringify(form);
console.log(form);
let result= yield postRequest({url:'https://api.weixin.qq.com/wxa/getwxacode?access_token=' + token,form:form});
fs.writeFile('d:/mybar.png', result[0].body, function(err) {
if (err) {
console.log('出现错误!')
}
});
console.log('result:' + result[1]);
})
请求回来的数据自动编码了,设置encoding : null就行,详见:https://segmentfault.com/a/1190000002787763
还写了一个博客,https://blog.csdn.net/uikoo9/article/details/86088028
哪位大侠帮回复一下啊