zoukankan      html  css  js  c++  java
  • 云开发检验图片是否有违规内容

    客户端

    mIsImg() {
    var that = this
    wx.chooseImage({
    count: 1,
    sourceType: ['album'],
    success: function(res) {
    if (!res.tempFilePaths[0]) {
    return;
    }
    console.log(JSON.stringify(res))
    if (res.tempFiles[0] && res.tempFiles[0].size > 1024 * 1024) {
    wx.showToast({
    title: '图片不能大于1M',
    icon: 'none'
    })
    return;
    }
    wx.getFileSystemManager().readFile({
    filePath: res.tempFilePaths[0],
    success: buffer => {
    console.log(buffer.data)
    wx.cloud.callFunction({
    name: 'imgCheck',
    data: {
    value: buffer.data
    }
    }).then(
    imgRes => {
    console.log(JSON.stringify(imgRes))
    if (imgRes.result.errorCode == '87014') {
    wx.showToast({
    title: '图片含有违法违规内容',
    icon: 'none'
    })
    return
    } else {
    that.$store.state.isImg = res.tempFilePaths[0]
    //图片正常
    }
    
    }
    )
    },
    fail: err => {
    console.log(err)
    }
    })
    }
    })
    },

    云函数

    config.json

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

    js

    const cloud = require('wx-server-sdk')
    cloud.init({
      env: 'test-vc0ep' // 你的环境ID
    })
    exports.main = async (event, context) => {
      const { value } = event;
      try {
        const res = await cloud.openapi.security.imgSecCheck({
          media: {
            header: {
            'Content-Type': 'application/octet-stream'},
              contentType: 'image/png',
              value: Buffer.from(value)
            }
          })
        return res;
      } catch (err) {
        return err;
      }
    }
  • 相关阅读:
    POJ 1458 Common Subsequence 【最长公共子序列】
    Codeforces Round #283 (Div. 2) A
    HDU 1009 FatMouse' Trade【贪心】
    HDU 2037 今年暑假不AC【贪心】
    Codeforces Round #282 (Div. 2) A
    HDU 2955 Robberies【01背包】
    bzoj4811
    bzoj2243
    bzoj2325
    bzoj3531
  • 原文地址:https://www.cnblogs.com/zwyboom/p/11330128.html
Copyright © 2011-2022 走看看