这是一个用户自定义图片的功能,就怕用户用一些色情或者其它图片。然后用这张图片分享出去,怕被举报封掉我的小程序。
// 判断图片是否合法,不含有色情,等内容。
checkImg: function(img){
var that = this
wx.getFileSystemManager().readFile({
encoding: ‘ucs2’,
filePath: img,
success: res => {
console.log(res,‘大小’)
var buffer = res.data;
wx.cloud.callFunction({
name: ‘imgSecCheck’,
data: {
value: buffer
},
success: res => {
wx.hideLoading();
console.log(res, ‘云函数返回’)
if(res.result.errCode == 0){
that.setData({
imgSrc: img
})
}
if (res.result.errCode == 87014) {
wx.showToast({
title: ‘图片含有违法违规内容!’,
icon: ‘none’
});
}
},
fail: err => {
wx.hideLoading();
console.log(err, ‘err返回’)
wx.showToast({
title: ‘加载失败!’,
icon: ‘none’
});
}
})
}, fail: err => {
wx.hideLoading();
console.log(err, ‘fail’)
wx.showToast({
title: ‘加载失败~’,
icon: ‘none’
});
}
})
},
-----------------------------云函数分割线---------------------------------------------------
// 云函数入口函数
exports.main = async (event, context) => {
console.log(event)
try {
const imgResult = await cloud.openapi.security.imgSecCheck({
media: {
header: { ‘Content-Type’: ‘application/octet-stream’ },
contentType: ‘image/png’,
value: Buffer.from(event.value)
}
})
return imgResult;
} catch (err) {
return err;
}
}