html52.com
我爱小程序-开发者交流社区

云函数 调用imgSecCheck图片内容审核api问题,返回结果一直为null,怎么回事?



云函数 调用imgSecCheck图片内容审核api问题。返回结果一直为空 resultnull


如下所示:

  1. {errMsg: "cloud.callFunction:ok", result: null, requestID: "4525eb0c-7fb2-11ea-9880-525400e7bfe4"}
  2. errMsg"cloud.callFunction:ok"
  3. requestID"4525eb0c-7fb2-11ea-9880-525400e7bfe4"
  4. resultnull
  5. __proto__: Object

请平台技术大神、开发者大神帮忙检查一哈。到底是什么问题?代码如下:

【云函数代码】

// 云函数入口文件 msgSecCheck 检测文本是否含有违法违规内容

const cloud = require('wx-server-sdk')

// 云函数入口函数

exports.main = async (event, context) => {

//初始化云函数

cloud.init({

env: event.env

})


try {

return await cloud.openapi.security.imgSecCheck({

media: {

contentType: event.image, //图片路径 'image/png'

value: event.imageBuffer

}

})

} catch (err) {

// 错误处理

// err.errCode !== 0

}

}


【小程序代码】

//【选择图片】

chooseImage() {

var that = this

//使手机发生较短时间的振动

wx.vibrateShort()

wx.showActionSheet({

itemList: ['拍照', '相册',],

success(res) {

console.log(res.tapIndex)

//拍照vounDemo

if (res.tapIndex == 0) {

//看选择相册那个代码,下面

}

//手机相册 vounShow

else if (res.tapIndex == 1) {

wx.chooseImage({

count: 1,

sizeType: ['original', 'compressed'],

sourceType: ['album'],

success(res) {

// tempFilePath可以作为img标签的src属性显示图片

// const tempFilePaths = res.tempFilePaths[0]

console.log('打印取到的图片')

console.log(res)

var imgFileURL = res.tempFilePaths[0]

wx.getFileSystemManager().readFile({ //读取文件信息

filePath: res.tempFilePaths[0],

encoding: 'base64',

success(res){

console.log('打印getFileSystemManager返回结果base64为')

console.log(res.data)

var base64 = res.data

var arrayBuffer = wx.base64ToArrayBuffer(base64)

console.log('打印图片本地文件ArrayBuffer内容')

console.log(arrayBuffer)

that.imgSecCheck(imgFileURL, arrayBuffer) //图片智能鉴黄

}

})

}

})

}

},

fail(res) {

console.log(res.errMsg)

}

})

},




//【图片智能鉴黄】

imgSecCheck: function (imgFileURL, arrayBuffer){

console.log('开始imgSecCheck方法')

wx.showLoading({

title: '图片鉴黄检测中', //正在内容安全检测

})

//初始化云开发及设置其环境

wx.cloud.init({

env: app.globalData.env,

traceUser: true

})

wx.cloud.callFunction({

// 要调用的云函数名称

name: 'imgSecCheckPro',

// 传递给云函数的event参数

data: {

image: imgFileURL,

imageBuffer: arrayBuffer

}

}).then(res => {

// output: res.result === 3

console.log('打印云函数imgSecCheck返回结果为')

console.log(res)

wx.hideLoading()//隐藏 loading 提示框

if (res.result.errMsg == "openapi.security.imgSecCheck:ok"){

//内容正常

wx.navigateTo({

url: './../vounShow/vounShow?comeFromPAGE=' + 'introduction' + '&tempFilePaths=' + imgFileURL,

})

}

else{

//内容检测结果为不安全

this.showModal()

}

}).catch(err => {

//错误

console.log('打印err结果为 错误')

console.log(err)

wx.hideLoading() //隐藏 loading 提示框

//this.showModal()

})

},


请平台技术大神、开发者大神帮忙检查一哈。到底是什么问题?


网友回复

undefined:

打印下err看看是啥啊

打印下err看看是啥啊

评论 抢沙发

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址

真正的个人免签约支付接口

云免签H5支付