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

网友投稿 736 2022-10-01

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

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

微信小程序审核拒绝,拒绝原因是用户上传图片可能存在违法违规问题,程序必须有审核机制。

解决方法如下(云开发):

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) } }) } }); },-

推荐教程:《微信小程序》

php入门到就业线上直播课:立即学习全程直播 + 实战授课 + 边学 + 边练 + 边辅导

版权声明:本文内容由网络用户投稿,版权归原作者所有,本站不拥有其著作权,亦不承担相应法律责任。如果您发现本站中有涉嫌抄袭或描述失实的内容,请联系我们jiasou666@gmail.com 处理,核实后本网站将在24小时内删除侵权内容。

上一篇:Could not find the required component ‘costmap_2d‘
下一篇:小程序画布canvas隐藏的问题解决(微信小程序canvas隐藏)
相关文章

 发表评论

暂时没有评论,来抢沙发吧~