1.在openapi里的config.json内配置
"openapi": [
"security.imgSecCheck",
"security.msgSecCheck"
]
2.在cloudfunctions下创建云函数msgcheck和imgcheck
3.msgcheck的index.js内容
// 云函数入口文件
const cloud = require('wx-server-sdk')
//可配置环境
cloud.init()
// 云函数入口函数
exports.main = async (event, context) => {
try{
const res=await cloud.openapi.security.msgSecCheck({
content:event.content
})
return res;
}catch(err){
return err;
}
}
imgcheck的index.js内容
// 云函数入口文件
const cloud = require('wx-server-sdk')
cloud.init()
// 云函数入口函数
exports.main = async (event, context) => {
try {
const res = await cloud.openapi.security.imgSecCheck({
imgcontent: event.content
})
return res;
} catch (err) {
return err;
}
}
4.调用
// 内容检测
wx.cloud.callFunction({
name: 'msgcheck',
name: 'imgcheck',
data: {
content: this.data.message,
imgcontent: this.data.images
}
}).then(ckres => {
if (ckres.result.errCode == 0) {
//这里输入审核通过后的内容
} else {
wx.hideLoading();
wx.showModal({
title: '提醒',
content: '请注意言论',
showCancel: false
})
}
})
来源:CSDN
作者:异知空间
链接:https://blog.csdn.net/sinat_39629506/article/details/104060627