以上代码看明白了,谢谢。 然后我再去文档中的security.imgSecCheck时,要在config.json要进行配置(如当前云函数文件没有config.json,可以自己新建一个),详情点这个链接(https://developers.weixin.qq.com/miniprogram/dev/wxcloud/guide/openapi/openapi.html#%E4%BA%91%E8%B0%83%E7%94%A8) { "permissions": { "openapi": [ "security.imgSecCheck" ] } } 在云函数中使用云调用时,首先云函数中需要使用版本号至少 0.4.0 的 wx-server-sdk,建议 wx-server-sdk 始终保持最新,保证云函数目录下的 package.json 的 wx-server-sdk 字段为 latest,如本地安装依赖,请执行 npm install --save wx-server-sdk@latest。 最后把云函数进行上传,结果执行成功,返回以下内容: success: {errMsg: "cloud.callFunction:ok", result: {…}, requestID: "..."} errMsg: "cloud.callFunction:ok" requestID: "..." result: errCode: 0 errMsg: "openapi.security.imgSecCheck:ok"
云开发 security.imgSecCheck 调用响应错误使用云函数调用 security.imgSecCheck ,对图片进行鉴黄请求响应为: [代码]{[代码] [代码]errMsg: [代码][代码]"cloud.callFunction:ok",[代码] [代码]result:{[代码][代码] errCode: 41005[代码][代码] errMsg: [代码][代码]"openapi.security.imgSecCheck:fail media data missing hint: [9ZGoCA02628622]" [代码] [代码] }[代码] [代码]}[代码] 云函数代码如下: [代码]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[代码][代码] [代码][代码]}[代码][代码] [代码][代码]})[代码][代码] [代码][代码]},[代码]
2020-02-23