调用内容安全API的MsgSecCheck真机调试没问题,上传至体验版就调用失败
调用内容安全API的MsgSecCheck用于过滤评论内容,在微信开发工具用真机调试都没问题,但是一旦上传至体验版本就一直调用失败,为了通过审核直接把评论功能删除了,都不知道要怎么debug了。
wx.cloud.init({
env: xxxxxx
})
const db = wx.cloud.database()
const id = db.collection("account")
onload:function(options){
id.doc("2eeeadaf-b64c-4ee7-abef-c9aa8f3e8f85").get().then(res=>{
wx.request({
url: 'https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=' + res.data.appid +"&secret="+res.data.secret,
success:res=>{
this.data.token = res.data.access_token
},
fail:res=>{console.log("获取access_token服务器繁忙")}
})
})
}
// 提交评论内容
referComment: function (e) {
var criticism = wx.getStorageSync('criticism')
var userInfo = wx.getStorageSync('userInfo')
var commentCreatTime = utils.formatTime(new Date())
criticism.push([userInfo.nickName, userInfo.avatarUrl, commentCreatTime, e.detail.value.comment])
if (e.detail.value.comment != '') {
var url = 'https://api.weixin.qq.com/wxa/msg_sec_check?access_token=' + this.data.token
console.log("token:"+this.data.token)
wx.request({
url: url,
method: 'POST',
data: { content: e.detail.value.comment },
success: res_check => {
if (res_check.data.errcode == 87014) {
wx.hideLoading()
wx.showModal({
title: '警告!',
content: '你发布的内容中含有违法违规内容,请修改好后再发布。',
showCancel: false
})
}
else{
wx.cloud.callFunction({
name: "comments",
data: {
comment: criticism,
pageID: this.data.pageID
},
success: res => {
this.setData({ criticism: criticism, content: '' })
wx.showToast({
title: '发送评论成功!',
})
wx.setStorageSync('criticism', criticism)
},
fail: res => {
console.log('comments', '调用失败')
}
})
}
},
// 一直执行这块代码
fail: res_check => {
console.log("res_check" + res_check)
wx.showToast({
title: '服务器忙请稍后',
icon:"loading"
})
}
})
}
else {
wx.showToast({
title: '你还没有输入评论内容',
icon:'none'
})
}
},