使用微信开发者工具可以成功调用,但是切到真机调试报错:
Error: errCode: -404011 cloud function execution error | errMsg: cloud.callFunction:fail requestID , cloud function service error code -504002, error message Unexpected token { (callid 1593863088871-0.13276541170994327); at cloud.callFunction api;
云函数代码:
// 云函数入口文件
const cloud = require('wx-server-sdk')
cloud.init()
// 云函数入口函数
exports.main = async (event, context) => {
try {
let result = await cloud.openapi.security.msgSecCheck({
content: event.content
});
return result;
}
catch{
return { errMsg: "openapi.security.msgSecCheck:fail", errCode: 1 };
}
}
云函数调用权限config.json:
{
"permissions": {
"openapi": [
"security.msgSecCheck",
"security.imgSecCheck"
]
}
}
调用代码:
wx.cloud.callFunction({
name: 'secCheck',
data: {
content: 'teste'
},
success: resp => {
console.log('contentValidate==>', resp);
},
fail: console.error
});
云函数在本地调试也可以通过,但是在云端调试也会报错:
user code exception caught, stackTrace:"Unexpected token {"
你云函数try catch写错了。。。这里修改下 就行了