您好,欢迎来到三六零分类信息网!老站,搜索引擎当天收录,欢迎发信息

微信小程序调用图片安全API

2024/3/6 12:12:55发布19次查看
微信小程序审核拒绝,拒绝原因是用户上传图片可能存在违法违规问题,程序必须有审核机制。
解决方法如下(云开发):
config.json
{  permissions: {    openapi: [      security.imgseccheck    ]  }}
云函数
const cloud = require('wx-server-sdk')cloud.init() 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;  }}
js
chooseimage() {    wx.chooseimage({      count: 1,       sizetype: ['original', 'compressed'],       sourcetype: ['album'],       success: (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: 'checkimg',              data: {                value: buffer.data              }            }).then(              imgres => {                if (imgres.result.errcode == '87014') {                  wx.showtoast({                    title: '图片含有违法违规内容',                    icon: 'none'                  })                  return                } else {                  //图片正常                  if (this.data.imglist.length != 0) {                    this.setdata({                      imglist: this.data.imglist.concat(res.tempfilepaths)                    })                  } else {                    this.setdata({                      imglist: res.tempfilepaths                    })                  }                }              }            )          },          fail: err => {            console.log(err)          }        })      }    });  },
推荐教程:《微信小程序》
以上就是微信小程序调用图片安全api的详细内容。
该用户其它信息

VIP推荐

免费发布信息,免费发布B2B信息网站平台 - 三六零分类信息网 沪ICP备09012988号-2
企业名录 Product