调用云函数生成小程序码不返回结果
发布于 6 年前 作者 gchen 8465 次浏览 来自 问答

云函数调用小程序生成api,function name:getNewQrCode

const cloud = require(‘wx-server-sdk’)

cloud.init()

exports.main = async (event, context) => {

  try {

    const result = await cloud.openapi.wxacode.getUnlimited({

      scene: event.scene,

      page: event.path

    })

    return result

  } catch (err) {

    return err

  }

}


小程序端调用代码:

wx.cloud.callFunction({

      name: ‘getNewQrCode’,

      data: param

    }).then(res => {

        let data

        if (res.result.errCode == 0) {

          if (dataType == ‘base64’) {

            data = `data:image/jpeg;base64,${wx.arrayBufferToBase64(res.result.buffer)}`

          }

          if (dataType == ‘buffer’) {

            data = res.result.buffer

          }

          if (data) {

            resolve(data)

          } else {

            reject(‘unknow data type’)

          }

        } else {

          reject(res.result.errMsg)

        }

    }).catch(err => {

      console.log(‘云端错误:’, err)

      reject(err)

    })


大部分用户能返回正确结果,但是,一旦一个用户不能返回正确结果,那他的返回的结果,永远都是

(大概4/5的用户正确,1/5的用户永远不正确)

Error: errCode:
-404012 error while waiting for the result
errMsg: cloud.callFunction:fail error while waiting for the result; at cloud.callFunction api;
    at new u (VM135 [publib]:1)
    at d (VM135 [publib]:1)
    at Object.t.returnAsFinalCloudSDKError (VM135 [publib]:1)
    at Function.<anonymous> (VM135 [publib]:1)
    at VM135 [publib]:1
    at Timeout._onTimeout (VM135 [publib]:1)
    at listOnTimeout (internal/timers.js:535)
    at processTimers (internal/timers.js:479)

查看云函数日志:

2019-05-13T06:04:43.431Z  生成了二维码数据: { contentType: ‘image/jpeg’,

  buffer: <Buffer ff d8 ff e0 00 10 4a 46 49 46 00 01 01 00 00 01 00 01 00 00 ff db 00 43 00 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 … >,

  errMsg: ‘openapi.wxacode.getUnlimited:ok’,

  errCode: 0 }

执行时间: 379.85ms内存使用: 2.38 MB

也就是说云端是执行成功的,也返回结果的

错误信息:fail error while waiting for the result

但是这个用户永远也等不到返回的结果,最后超时后抛错

是云开发平台的问题还是其他设置方面的问题呢?

不知道有没有遇到同样问题的?

3 回复

遇到同样问题,测试的一台安卓机(三星S9+)一直报这个错,我的安卓机就正常。云函数返回的json也不大,根本没到600k

感谢反馈,这是安卓 7.0.4 版本优化引入的 bug,云函数回包过大(约超过600K)时会出现报错的情况,我们将会尽快修复。

遇到同样的问题,开发工具中正常,真机就报错了

回到顶部