云函数报错Cannot read property 'startsWith' of undefid?
根据网上的视频在做文字违规检测,代码写好以后在云函数日志里面报错了Cannot read property ‘startsWith’ of undefined。在网上也找不到有效的解决办法。小白一枚,还请大佬们指教
云函数内的代码如下:
const TOKEN_URL = "https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=" + APPID+ "&secret=" + APPSECRET
const CHECK_URL = "https://api.weixin.qq.com/wxa/msg_sec_check?access_token="
// 云函数入口函数
exports.main = async (event, context) => {
const content = event.content;
const author = event.author;
const location = event.location;
const images = event.images;
// 文字内容检测
const tokenResp =await got.post(TOKEN_URL);
const tokenBody = JSON.parse(tokenResp.body);
const token = tokenBody.access_token;
const checkResp = await got.post(CHECK_URL+token,{
body:JSON.stringify({
content:content,
location:location,
author:author
})
});
const checkBody = JSON.parse(checkResp.body);
console.log(checkBody);
const errcode = checkBody.errcode;
if(errcode == 0){
return await db.collection("weibo").add({
data:{
content:content,
location:location,
author:author
}
})
}
else{
return{"errcode":1,"errmsg":"您的文字内容有风险!请修改后发布!"}
}
}