微信小程序图片鉴黄

因小程序不允许添加qq.com域名,故需要nginx转发

上传链接

https://check.com/wxa/img_sec_check?api=img_sec_check&access_token=XXXX

nginx转发

location / {
    if ( $arg_api = img_sec_check ){
        # 图片鉴黄
        proxy_pass https://api.weixin.qq.com;
        break;
    }
    try_files $uri $uri/ /index.php$is_args$args;
}

上传图片

 wx.chooseImage({
      count: 2,
      sizeType: ['original', 'compressed'],
      sourceType: ['album', 'camera'],
      success(res) {
        console.log(res);
        var filePaths = res.tempFilePaths;
        var filePath = '';//声明图片地址
        for (var i = 0; i < filePaths.length; i++) {
              filePath = filePaths[i];
              wx.uploadFile({
                url: "https://check.com\/wxa\/img_sec_check?access_token=24_XcPpQe4zMVLjwZKlTCUfatVklKpbMP0pUnohQ1_om28oAgLIzhDCE45glcf3lM9-58jxPgp9I0ecGMDXadoJLG626DKOS6KbrHLMBneDpd65a1IfwSh0g6AimKEMYWcAHASEC
                filePath: filePath,
                name: 'file',
                formData: {},
                success(res_2) {
                  console.log(filePath);
                  var json = JSON.parse(res_2.data);
                  console.log(json)
                  if (json.errcode === 0) {
                    console.log('通过');
                  } else {
                    console.log('未通过');
                  }
                }
              })
            }
      }
    })

你可能感兴趣的:(php,前端,nginx)