收藏
回答

第三方平台获取到的体验版二维码无法打开?已解决

官方接口:https://developers.weixin.qq.com/doc/oplatform/Third-party_Platforms/Mini_Programs/code/get_qrcode.html

云函数代码:

输出:

body:

buffer:

云存储结果:文件大小10K

请求成功的代码:

//获取体验版二维码

function getQrCode(access_token,appId) {

  return new Promise((resolve, reject) => {

      request({

          url: `https://api.weixin.qq.com/wxa/get_qrcode?access_token=${access_token}`,

          headers: {

            'Accept-Encoding': 'gzip, deflate'

          },

          encoding: null

      }, (error, response, body) => {

          if (error) {

            console.log('getQrCode失败:',error);

            reject(error);   

          }

          const fileExtension = 'jpeg';

          cloud.uploadFile({

            cloudPath: `${appId}.${fileExtension}`,

            fileContent: body

          }).then(res=>{

            if (!res.fileID) {

reject(res)

            }

            resolve(res.fileID);

          })

      });

  });

}

最后一次编辑于  2021-01-14
回答关注问题邀请回答
收藏

1 个回答

  • 王马利
    王马利
    2021-01-14

    请求里添加参数:

              headers: {

                'Accept-Encoding': 'gzip, deflate'

              },

              encoding: null

    2021-01-14
    有用
    回复
登录 后发表内容
问题标签