更新:问题的原因自己找到了
参照这个帖子:安卓微信调用云函数时有bug
https://developers.weixin.qq.com/community/develop/doc/00086e8ec34c7032b0098a88e59c00?highLine=%25E4%25BA%2591%25E5%2587%25BD%25E6%2595%25B0%2520%25E8%25B6%2585%25E6%2597%25B6
尝试用用极小图片,发现能够正常进入检测。但是用大一点的图片(当然是小于文档要求的1M)就返回-404010。
这个图片检测功能目前形同虚设。期待它尽快康复。
=======================================
如题。
在开发者工具中调试一切正常,可以正确识别违规图片,但是上传体验版,真机端无响应,提示-404010
微信版本和基础库版本都是最新的。
感谢!
下面是云函数代码
// 云函数入口文件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; }} |

下面是客户端代码:
for(let i = 0; i < res.tempFilePaths.length; i++) {wx.getFileSystemManager().readFile({filePath: res.tempFilePaths[i],success: buffer => {wx.showLoading({title:'智能检测图片',})wx.cloud.callFunction({name:'imgSecCheck',data: {value: buffer.data}}).then(res=> {if(res.result.errCode === 87014) {wx.showToast({title:'图片含有违法违规内容',icon:'none',duration: 2000})console.log('图片非法')}else{//图片正常wx.hideLoading();console.log('图片正常')thisImgList = thisImgList.concat(res.tempFilePaths[i])currPage.setData({imgList: thisImgList,hasNewImage:true})}}).catch(err => {console.log('智能检测图片失败:', err)wx.hideLoading();thisImgList = thisImgList.concat(res.tempFilePaths[i])currPage.setData({imgList: thisImgList,hasNewImage:true})})},fail: err => {},})}求助!
提供代码片段。
https://developers.weixin.qq.com/miniprogram/dev/devtools/minicode.html