关于调用getUnlimitedAPI生成无限量带参二维码扫码后不能拿到参数的问题?

小程序 文章 2021-03-17 11:01 57 0 全屏看文

关于调用getUnlimitedAPI生成无限量带参二维码扫码后不能拿到参数的问题?About calling getUnlimitedAPI to generate an unlimited number of QR codes with parameters, the parameters cannot be obtained after scanning the code?

关于调用getUnlimitedAPI生成无限量带参二维码扫码后不能拿到参数的问题?
// 云函数入口文件//openapi.wxacode.createQRCode可以正常拿到传递过来的参数,但是用getUnlimitedAPI这个方法就拿不到参数const cloud = require('wx-server-sdk')cloud.init({  env: cloud.DYNAMIC_CURRENT_ENV,}) const uploadfile = async function(arraybuffer,path){   //console.log('我被调用了');   let {fileID} = await cloud.uploadFile({     cloudPath:path,     fileContent:arraybuffer   })   return fileID }// 云函数入口函数exports.main = async (event, context) => {      try {        const result = await cloud.openapi.wxacode.createQRCode({            path'pages/index/index?a=1',            width430          })          console.log(result);          fileID = await uploadfile(result.buffer, 'my.jpg')          return fileID      }         catch (err) {        return err  }     }


下面这种就拿不到要传递的参数

// 云函数入口文件const cloud = require('wx-server-sdk')cloud.init({  env: cloud.DYNAMIC_CURRENT_ENV,}) const uploadfile = async function(arraybuffer,path){   console.log('我被调用了');   let {fileID} = await cloud.uploadFile({     cloudPath:path,     fileContent:arraybuffer   })   return fileID }// 云函数入口函数exports.main = async (event, context) => {  //根据渠道名称进行数据库查询,如果存在(即二次点击),则返回文件艾迪    // console.log(event.namevalue);         //数据库查询不到该渠道,二维码即是第一次输入           try {        const result = await cloud.openapi.wxacode.getUnlimited({          scene'a=1'        })         // console.log(result);          fileID = await uploadfile(result.buffer, 'my.jpg')          return fileID      }         catch (err) {        return err  }     }

//Cloud function entry file// openapi.wxacode.createQRCode You can get the passed parameters normally, but you can't get the parameter const cloud = require ('wx server SDK ') by using the getunlimited API cloud.init ({  env:  cloud.DYNAMIC_ CURRENT_ ENV,}) const uploadfile = async function(arraybuffer,path){   // console.log ('I was called '); let {fileid} = await cloud.uploadFile ({      cloudPath:path ,     fi leContent:arraybuffer }) return fileid} / / cloud function entry function exports.main  = async (event,  context) => {      try {        const result = await  cloud.openapi.wxacode .createQRCode({            path: 'pages/index/index?a=1',            width: 430          })           console.log (result);          fileID = await uploadfile( result.buffer ,  ' my.jpg 'return 'fileid} catch (ERR) {return' err}} you can't get the parameters to pass / / the cloud function entry file const cloud = require ('wx server SDK ') cloud.init ({  env:  cloud.DYNAMIC_ CURRENT_ ENV,}) const uploadfile = async function(arraybuffer,path){    console.log ('I was called '); let {fileid} = await cloud.uploadFile ({      cloudPath:path ,     fi leContent:arraybuffer }) return fileid} / / cloud function entry function exports.main  = async (event, Context) = > {/ / query the database according to the channel name. If it exists (i.e. second click), the file Eddie / / will be returned console.log ( event.namevalue ); / / the channel cannot be found in the database, QR code is the first time to enter {try {const} result = await cloud.openapi.wxacode .getUnlimited({          scene: 'a=1'        })         //  console.log (result);          fileID = await uploadfile( result.buffer ,  ' my.jpg ')          return fileID      }         catch (err) {        return err  }     }

回答:

半吨先生:
onLoad(options) {    if (!options.scene) {      this.setData({        ak: options.ak || app.globalData.query.ak || '',      })    } else {      var getQueryString = {}      var strs = decodeURIComponent(options.scene).split('&') //以&分割      //取得全部并赋值      for (var i = 0; i < strs.length; i++) {        getQueryString[strs[i].split('=')[0]] = unescape(strs[i].split('=')[1])      }      this.setData({        ak: getQueryString['ak'] || ''      })    }  }
peng:

参数获取使用options.query.scene 获得的值是a=1,自己拿到这个字符串后处理。

。:我用getUnlimitedAPI这个生成扫码后拿到的 options是个空对象
。:

上图是通过上面的第一种方法可以拿到参数a = 1

下图是通过上面的第二种方法拿不到参数a=1

-EOF-