使用云函数调用 security.imgSecCheck ,对图片进行鉴黄请求响应为:
result:{ errCode: 41005
|
云函数代码如下:
const cloud = require( 'wx-server-sdk' ) cloud.init(); // 云函数入口函数 exports.main = (event) => { console.log(event); return cloud.openapi.security .imgSecCheck({ media: { contentType: 'image/png' , value: event.img } }) .then(result => { return result; }) . catch (err => { return err; }) } |
调用代码如下:
uploadImg: function () { this .selectImg().then(img => { console.log(img); return this .imgSecCheck(img); }).then(res => { console.log( "success:" , res); }). catch (err => { console.log( "fail" , err); }) },
// 选择图片并转为 buffer selectImg: function () { return new Promise((resolve, reject) => { wx.chooseImage({ count: 1, sizeType: [ 'original' , 'compressed' ], success: function (res) { let params = { filePath: res.tempFilePaths[0] }; wx.getFileSystemManager() .readFile({ filePath: res.tempFilePaths[0], success: res => { console.log( "readSuccess:" , res); resolve(res.data); }, fail: err => { console.log( "readFail:" , err); reject(err); } }); }, }) }) }, // 调用云函数 imgSecCheck: function (img) { return wx.cloud.callFunction({ name: "imgSecCheck" , data: { img: img } }) }, |
虽然没有用云开发 https://mp.weixin.qq.com/wiki?t=resource/res_main&id=mp1433747234
参考微信返回码 应该是图片路径问题 检查检查路径吧