收藏
回答

示例代码里面getOpenData提示这个错误什么意思,公共库大于2.8,openapi已经上传?

{"errorCode":1,"errorMessage":"user code exception caught","stackTrace":"errCode: -501001 resource system error | errMsg: getOpenData:fail source.on is not a function; at getOpenData api; "}


{ action: 'getOpenData',

openData:

{ list:

[ '25_Rt-GB2xMTxJi5Hb_Z548eoBHqrtfPBCjXBy4UhJk5I7DVXxpSCBcNCzMUhM' ] },

userInfo:

{ appId: 'wx1e6acdbd04edfd2f',

openId: 'okH_90DrM3pIhNB8ennkCbNW4Gqs' } }

Error: errCode: -501001 resource system error | errMsg: getOpenData:fail source.on is not a function; at getOpenData api;

at new CloudSDKError (/var/user/node_modules/wx-server-sdk/index.js:6366:28)

at returnAsCloudSDKError (/var/user/node_modules/wx-server-sdk/index.js:6418:16)

at Object.returnAsFinalCloudSDKError (/var/user/node_modules/wx-server-sdk/index.js:6432:13)

at Cloud.<anonymous> (/var/user/node_modules/wx-server-sdk/index.js:2218:41)

at step (/var/user/node_modules/tslib/tslib.js:136:27)

at Object.throw (/var/user/node_modules/tslib/tslib.js:117:57)

at rejected (/var/user/node_modules/tslib/tslib.js:108:69)

at <anonymous>


最后一次编辑于  2019-09-29
回答关注问题邀请回答
收藏

4 个回答

  • 邓坤力
    邓坤力
    2019-10-11

    抱歉是 wx-server-sdk 的问题,请升级下 wx-server-sdk 到最新版(1.2.2)再试试呢?

    2019-10-11
    有用 2
    回复 1
    • 乘二
      乘二
      2019-10-30
      可以了,确实是,现在又有新的问题了。
      2019-10-30
      回复
  • Justan
    Justan
    2019-10-11

    看下这个 https://developers.weixin.qq.com/community/develop/doc/0008820af6c61820cd395b1e05b800?jumpto=comment&commentid=000ce4d9150dc8b1c439980325b4

    2019-10-11
    有用
    回复
  • Tang
    Tang
    2019-10-02

    我也有类似的问题:

    WAService.js:1 Uncaught (in promise) Error: errCode: -404011 cloud function execution error | errMsg: cloud.callFunction:fail requestID 1322129a-e4e6-11e9-b3ac-525400e8849e, cloud function service error code -504002, error message errCode: -501001 resource system error | errMsg: getOpenData:fail source.on is not a function; at getOpenData api; ; at cloud.callFunction api; 

        at new u (WAService.js:1)

        at d (WAService.js:1)

        at f (WAService.js:1)

        at Function.success (WAService.js:1)

        at WAService.js:1

        at C (WAService.js:1)

        at i.<anonymous> (WAService.js:1)

        at i.emit (WAService.js:1)

        at Rs (WAService.js:1)

        at WAService.js:1

    u @ WAService.js:1

    d @ WAService.js:1

    f @ WAService.js:1

    success @ WAService.js:1

    (anonymous) @ WAService.js:1

    C @ WAService.js:1

    (anonymous) @ WAService.js:1

    i.emit @ WAService.js:1

    Rs @ WAService.js:1

    (anonymous) @ WAService.js:1

    (anonymous) @ WAService.js:1

    n @ VM106 asdebug.js:1

    (anonymous) @ VM106 asdebug.js:1

    t.emit @ VM106 asdebug.js:1

    callback @ VM106 asdebug.js:1

    (anonymous) @ VM106 asdebug.js:1

    (anonymous) @ WAService.js:1

    (anonymous) @ WAService.js:1

    Promise.then (async)

    onGetUserInfo @ cloudid.js:48

    r.safeCallback @ WAService.js:1

    (anonymous) @ WAService.js:1

    r @ WAService.js:1

    (anonymous) @ WAService.js:1

    (anonymous) @ WAService.js:1

    n @ VM106 asdebug.js:1

    (anonymous) @ VM106 asdebug.js:1

    (anonymous) @ VM106 asdebug.js:1

    _ws.onmessage @ VM106 asdebug.js:1


    2019-10-02
    有用
    回复
  • 是小白啊
    是小白啊
    2019-09-29

    麻烦提供出现问题的具体机型、微信版本号、系统版本号,以及能复现问题的代码片段https://developers.weixin.qq.com/miniprogram/dev/devtools/minicode.html

    2019-09-29
    有用
    回复 1
    • 乘二
      乘二
      2019-09-29

      // 云函数入口文件

      const cloud = require('wx-server-sdk')


      cloud.init({

      // API 调用都保持和云函数当前所在环境一致

      env: cloud.DYNAMIC_CURRENT_ENV

      })


      // 云函数入口函数

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

      console.log('test')

      console.log(event)

      switch (event.action) {

      case 'sendTemplateMessage': {

      return sendTemplateMessage(event)

      }

      case 'getWXACode': {

      return getWXACode(event)

      }

      case 'getOpenData': {

      return getOpenData(event)

      }

      default: {

      return

      }

      }

      }


      async function sendTemplateMessage(event) {

      const { OPENID } = cloud.getWXContext()


      // 接下来将新增模板、发送模板消息、然后删除模板

      // 注意:新增模板然后再删除并不是建议的做法,此处只是为了演示,模板 ID 应在添加后保存起来后续使用

      const addResult = await cloud.openapi.templateMessage.addTemplate({

      id: 'AT0002',

      keywordIdList: [3, 4, 5]

      })


      const templateId = addResult.templateId


      const sendResult = await cloud.openapi.templateMessage.send({

      touser: OPENID,

      templateId,

      formId: event.formId,

      page: 'pages/openapi/openapi',

      data: {

      keyword1: {

      value: '未名咖啡屋',

      },

      keyword2: {

      value: '2019 年 1 月 1 日',

      },

      keyword3: {

      value: '拿铁',

      },

      }

      })


      await cloud.openapi.templateMessage.deleteTemplate({

      templateId,

      })


      return sendResult

      }


      async function getWXACode(event) {


      // 此处将获取永久有效的小程序码,并将其保存在云文件存储中,最后返回云文件 ID 给前端使用


      const wxacodeResult = await cloud.openapi.wxacode.get({

      path: 'pages/openapi/openapi',

      })


      const fileExtensionMatches = wxacodeResult.contentType.match(/\/([^\/]+)/)

      const fileExtension = (fileExtensionMatches && fileExtensionMatches[1]) || 'jpg'


      const uploadResult = await cloud.uploadFile({

      // 云文件路径,此处为演示采用一个固定名称

      cloudPath: `wxacode_default_openapi_page.${fileExtension}`,

      // 要上传的文件内容可直接传入图片 Buffer

      fileContent: wxacodeResult.buffer,

      })


      if (!uploadResult.fileID) {

      throw new Error(`upload failed with empty fileID and storage server status code ${uploadResult.statusCode}`)

      }


      return uploadResult.fileID

      }


      async function getOpenData(event) {

      // 需 wx-server-sdk >= 0.5.0

      console.log(cloud.getOpenData)

      return cloud.getOpenData({

      list: event.openData.list,

      })

      }


      应该就是最后这段代码出问题了,getOpenData(event)

      2019-09-29
      回复
登录 后发表内容
问题标签