wx.chooseImage({
count:'1',
sizeType: ['compressed'],
sourceType: ['album', 'camera']
}).then((res)=>{
wx.showLoading();
let opt= {src:res.tempFilePaths[0], quality:5}
return wx.compressImage(opt);
}).then((res)=>{
let cdnUrl=wx.cloud.CDN({
type: 'filePath',
filePath: res.tempFilePath,
});
let opt={
name:'imgSecCheck',
data:{
imgcontent: cdnUrl
}
};
return wx.cloud.callFunction(opt)
}).then((res)=>{
wx.hideLoading();
if (res.result.errCode == 0) {
wx.showModal({
title: '提醒',
content: '检查成功!',
showCancel: false
})
}else{
wx.showModal({
title: '提醒',
content: '违规图片!',
showCancel: false
})
}
}).catch((err)=>{
console.error(err);
wx.hideLoading();
if(err.errMsg!='chooseImage:fail cancel'){
wx.showModal({
title: '提醒',
content: '出错了请稍后再试!',
showCancel: true
})
}
});
const cloud = require('wx-server-sdk')
const axios = require('axios');
cloud.init()
exports.main = async (event, context) => {
let buffer=null;
await axios({
method: 'get',
url: event.imgcontent,
responseType: 'arraybuffer'
}).then(res => {
buffer=res.data;
})
try{
return await cloud.openapi.security.imgSecCheck({
media: {
contentType: 'image/png',
value:buffer
}
})
}catch(e){
return e;
}
}