其他分享
首页 > 其他分享> > TP5 七牛云图片审核

TP5 七牛云图片审核

作者:互联网

//先把七牛云下载下来
composer require qiniu/php-sdk
//引入必须要的类
use Qiniu\Auth;
use Qiniu\Http\Client;


public function image(){
$as = "";
$sk = "";//注册七牛云秘钥
$url = "http://ai.qiniuapi.com/v3/image/censor";
$method = "POST";
$host = "ai.qiniuapi.com";
$contentType = "application/json";
$image_url = "";//要审核的图片
$scenes = [
'censor'=>['pulp','terror','politician','ads'],
'pulp'=>['pulp'],
'terror'=>['terror'],
'politician'=>['politician'],
'ads'=>['ads']//验证的类型
];
$body = [
'data' =>['uri'=>$image_url],
'params'=>['scenes'=>$scenes['censor']]
];
$auth = new Auth($as,$sk);
$headers = $auth->authorizationV2($url,$method,json_encode($body),$contentType);
$headers['Content-Type'] = $contentType;
$headers['Host']= $host;
$response = Client::post($url,json_encode($body),$headers);
$responses = collection($response)->toArray();//对象转换为数组
$responses = json_decode($responses['body'],true);//解码 看情况而定
if ($responses['result']['suggestion'] == 'pass'){
     //进行图片上传
echo "通过";die;
}
echo "失败";die;
}

标签:body,七牛云,responses,url,image,json,headers,TP5,审核
来源: https://www.cnblogs.com/shaoxiong12/p/15623444.html