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;
}
上一篇:vue项目:前端根据后端需要添加token请求头


下一篇:vue向后端传参会加个等号