云调用
云调用是小程序·云开发提供的在云函数中调用微信开放接口的能力,需要在云函数中通过 wx-server-sdk 使用。
接口方法
openapi.security.msgSecCheck
需在 config.json 中配置 security.msgSecCheck API 的权限,
{
"permissions": {
"openapi": [
"security.msgSecCheck"
]
}
}
云函数msgcheck写法
const cloud = require('wx-server-sdk')
cloud.init()
exports.main = async (event, context) => {
console.log('event',event);
const { content } = event;
try {
const res = await cloud.openapi.security.msgSecCheck({
content: event.content,
scene:3,
})
return res;
} catch (err) {
return err;
}
}
本地函数调用和回调写法
async submit() {
const contentres = await this._requestCloudMsgCheck(this.data.requestParams.content)
console.log('检测的结果', contentres);
if (contentres.result.errCode == 87014) return wx.showToast({
title: '内容有敏感词请修改',
icon: 'none'
})
const cellNameres = await this._requestCloudMsgCheck(this.data.requestParams.cellName)
if (cellNameres.result.errCode == 87014) return wx.showToast({
title: '小区名称有敏感词请修改',
icon: 'none'
})
}
调用函数
_requestCloudMsgCheck(textareaVal) {
console.log('内容检测', textareaVal);
return wx.cloud.callFunction({
name: 'securityCheck',
data: {
type: 'msgSecCheck',
content: textareaVal
}
}).then(res => {
console.log('结果', res);
return res
}).catch(err => {
console.error('err', err);
})
}
测试用例
特3456书yuuo莞6543李zxcz蒜7782法fgnv级
完2347全dfji试3726测asad感3847知qwez到
开发者可使用以上两段文本进行测试,若接口errcode返回87014(内容含有违法违规内容),则对接成功。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)