在用一个msgCheck的云函数时遇到以下问题:
云函数日志的报错记录为下:
返回结果
{"errorCode":1,"errorMessage":"user code exception caught","stackTrace":"Cannot destructure property `Resolver` of 'undefined' or 'null'."}
日志
START RequestId: a5c2e9eb-8a17-11ea-80b7-52540084e83a
Event RequestId: a5c2e9eb-8a17-11ea-80b7-52540084e83a
ERROR RequestId:a5c2e9eb-8a17-11ea-80b7-52540084e83a Result:{"errorCode":1,"errorMessage":"user code exception caught","stackTrace":"Cannot destructure property `Resolver` of 'undefined' or 'null'."}
以下是云函数的代码
const cloud = require('wx-server-sdk')
cloud.init()
const got =require("got")
const APPID =""
const APPSECRET =""
//id与秘钥均无问题
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 tokenResp = await got(TOKEN_URL);
const tokenBody =JSON.parse(tokenResp.body);
const token =tokenBody.access_token;
const checkResp =await got(CHECK_URL+token,{
body:JSON.stringify({
content:content
})
});
const checkBody =JSON.parse(checkResp.body);
console.log(checkBody);
}
以下是调用云函数的js代码:
wx.cloud.callFunction({
name:"wweibo",
data:{
content:content,
location:location,
author:author
},
success:res =>{
console.log(res);
},
fail:err=>{
console.log("fail");
}
})
遇到相同问题的小伙伴,直接用云调用吧。多快好省