收藏
回答

云调用 openapi.security.imgSecCheck 报错 -501001

框架类型 问题类型 终端类型 AppID 基础库版本
小程序 Bug 工具 wx6cda482d190728e3 2.8.3

在调用 云调用 图片审核接口

错误代码 -501001

提示错误信息 openapi.security.imgSecCheck:fail source.on is not a function; at openapi.security.imgSecCheck api;


服务端代码

// 图片检查
async function imgSecCheck(event) {
 
  console.log("imgSecCheck:"+event.value)
 
  try {
    const res = await cloud.openapi.security.imgSecCheck({
      media: {
        header: {
          'Content-Type': 'application/octet-stream'
        },
        contentType: 'image/png',
        value: Buffer.from(event.value)
      }
    })
    return res;
     
  } catch (err) {
    return err;
  }
}


小程序页面 端

// 上传图片-审核
 checkUpload: function () {
   // 选择图片
   wx.chooseImage({
     count: 1,
     sizeType: ['compressed'],
     sourceType: ['album', 'camera'],
     success: function (res) {
 
       wx.showLoading({
         title: '上传中',
       })
 
       const filePath = res.tempFilePaths[0]
 
       // 上传图片
       const cloudPath = 'my-image' + filePath.match(/\.[^.]+?$/)[0]
 
       wx.getFileSystemManager().readFile({
         filePath: res.tempFilePaths[0],
         success: buffer => {
           wx.hideLoading()
           console.log(buffer);
           console.log(buffer.data)
           // 调用云调用
           wx.cloud.callFunction({
             name: 'openapi',
             data: {
               action:'imgSecCheck',
               value: buffer.data
             }
 
           }).then(imgRes => {
               console.log(imgRes);
               console.log(imgRes.result.errCode);
  
             if (imgRes.result.errCode == '87014') {
                 wx.showToast({
                   title: '图片含有违法违规内容',
                   icon: 'none'
                 })
                 return
               } else {
                 //图片正常
                 console.log("图片正常")
                 wx.showToast({
                   title: '图片正常',
                   icon: 'none'
                 })
               
               }
             }).catch(err => {
               // handle error
               console.log(err);
             })
 
         },fail: e => {
           console.error(e)
         }
       })
     }
   })
 }


求答疑,是我代码问题,还是 微信服务器问题?

回答关注问题邀请回答
收藏

2 个回答

登录 后发表内容
问题标签