失眠网,内容丰富有趣,生活中的好帮手!
失眠网 > 小程序内容审核违规过滤 在小程序使用security.msgSecCheck

小程序内容审核违规过滤 在小程序使用security.msgSecCheck

时间:2020-11-17 19:42:09

相关推荐

小程序内容审核违规过滤 在小程序使用security.msgSecCheck

使用微信提供的APIsecurity.msgSecCheck查看文档

1.开通云开发,创建云环境。

2.在云函数的目录中,创建一个云函数(ContentCheck),如果小程序代码没有云函数的目录,可以在 project.config.json 目录中配置目录,在云函数中使用security.msgSecCheck。

"cloudfunctionRoot": "cloudfunctions/",

3.在ContentCheck 的 config.json 中 配置security.msgSecCheck

{"permissions": {"openapi": ["security.msgSecCheck"]}}

4.云函数的 index.js 代码,编辑完,右键点击云函数目录,选择上传并部署云函数(云端按照依赖),然后右键index.js ,点击增量上传。

// 云函数入口文件const cloud = require('wx-server-sdk')cloud.init()// 云函数入口函数exports.main = async (event, context) => {return await cloud.openapi.security.msgSecCheck({content:event.txt})}

5.在小程序 app.json 添加配置

"permissions": {"openapi": ["security.msgSecCheck"]},

6.在小程序页面中调用

wx.cloud.callFunction({name: 'ContentCheck',data: {txt: "测试文字是否违规啊"},success(res) {console.log('ContentCheck-res',res)if (res.result.errCode == 87014) {console.log(res.errCode)wx.showToast({icon: 'none',title: '文字违规',})}else{msgList.push(item)that.update_msg_info(msgList)}},fail(err){console.log('ContentCheck-err',err)}})

如果觉得《小程序内容审核违规过滤 在小程序使用security.msgSecCheck》对你有帮助,请点赞、收藏,并留下你的观点哦!

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。