const cloud = require('wx-server-sdk')
cloud.init()
exports.main = async (event, context) => {
try {
const result = await cloud.openapi.wxacode.getUnlimited({
scene: event.type+"&"+event.did + "&" + event.data+"&"+event.value
})
console.log(result)
return result
} catch (err) {
console.log(err)
return err
}
}
异常报错 604101错误 说没有权限,这个小程序码生成函数是一定要发布了才可以调用吗
2019-06-07T03:42:40.285Z 4c410274-88d6-11e9-8e18-5254005d5fdb { Error: errCode: -604101 function has no permission to call this API | errMsg: system error: error code: -604101
at new CloudSDKError (/var/user/node_modules/wx-server-sdk/index.js:6173:28)
at Object.<anonymous> (/var/user/node_modules/wx-server-sdk/index.js:479:39)
at step (/var/user/node_modules/tslib/tslib.js:133:27)
at Object.next (/var/user/node_modules/tslib/tslib.js:114:57)
at fulfilled (/var/user/node_modules/tslib/tslib.js:104:62)
at <anonymous>
at process._tickCallback (internal/process/next_tick.js:188:7)
errCode: -604101,
errMsg: 'system error: error code: -604101' }
需要在云函数目录下的
config.json 配置文件中,声明云函数需要使用的接口,具体请参考文档:
https://developers.weixin.qq.com/miniprogram/dev/wxcloud/guide/openapi/openapi.html#%E4%BA%91%E8%B0%83%E7%94%A8
非常感谢,我增加了config.json还是报这个错,还可能是什么原因吗?没发布吗?而且等了十分钟后调用还不行。
config.json
{
"permissions": {
"openapi": [
"wxacode.getUnlimited"
]
}
}
///////////////////////////////////////////////////////////////////
日志:
START RequestId: 9dd6c402-8e6e-11e9-b245-525400681fe1
Event RequestId: 9dd6c402-8e6e-11e9-b245-525400681fe1
2019-06-14T06:35:36.528Z 9dd6c402-8e6e-11e9-b245-525400681fe1 { Error: errCode: -604101 function has no permission to call this API | errMsg: system error: error code: -604101
at new CloudSDKError (/var/user/node_modules/wx-server-sdk/index.js:6173:28)
at Object.<anonymous> (/var/user/node_modules/wx-server-sdk/index.js:479:39)
at step (/var/user/node_modules/tslib/tslib.js:136:27)
at Object.next (/var/user/node_modules/tslib/tslib.js:117:57)
at fulfilled (/var/user/node_modules/tslib/tslib.js:107:62)
at <anonymous>
at process._tickCallback (internal/process/next_tick.js:188:7)
errCode: -604101,
errMsg: 'system error: error code: -604101' }
END RequestId: 9dd6c402-8e6e-11e9-b245-525400681fe1
Report RequestId: 9dd6c402-8e6e-11e9-b245-525400681fe1 Duration:118ms Memory:256MB MaxMemoryUsed:13.546875MB
工具版本是多少呢,是不是最新版的工具?增加了配置后有没有重新上传?
v1.02.1905151版本,有重新点上传并部署。只是我还没有发布。其他我想不到什么问题。
config.json 是放在了 cloudfunctionRoot 下还是这个云函数的目录下?