微信小程序使用云函数实现内容和图片安全审核API接口

≯℡__Kan透↙ 提交于 2020-01-24 21:26:44

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
        })
      }
    })
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!