我调用的是服务端API cloud.openapi.security.mediaCheckAsync,直接调用后msgResult里没有东西。我以为是函数前没有await,也就是说函数没执行完,但我加上await后,云函数报错SyntaxError: await is only valid in async functions and the top level bodies of modules。另外,我的回调函数已调通。就是云函数中获得不到trace_id
let msgResult = cloud.openapi.security.mediaCheckAsync({
"openid": openid,
"scene": 4,
"version": 2,
"media_url": element,
"media_type": 2
})
console.log("检查图片:" +msgResult);
这样运行,msgResult中没东西
在cloud.openapi前面加上await,又报错SyntaxError: await is only valid in async functions and the top level bodies of modules
已经解决了,是因为没用await,而之所以不能用await是因为用了隐藏的函数,其实被包在了父函数里面,后来用了for循环去除了父函数就好了。
array.forEach(element => {
try {
const imgResult = await cloud.openapi.security.mediaCheckAsync({
"openid": openid,
"scene": 4,
"version": 2,
"media_url": usedobject.imageList[i],
"media_type": 2
})
console.log("检查图片:" +imgResult.traceId);
console.log(imgResult.errCode);
});