public function qiniu(){
require_once CMF_ROOT.'/plugins/qiniu/vendor/autoload.php';
$accessKey = getenv('QINIU_KEY');
$secretKey = getenv('QINIU_SCREAT');
$body = [
'data'=>[
'uri'=>'https://qiniu.xsjyy8.cn/user/20221226/d052406c899eac7f20b9f9fd6487a790.jpg'
],
'params' => [
'scenes' => [
"pulp",
]
]
];
$body = json_encode($body);
$token = new Auth($accessKey,$secretKey);
$token = $token->authorizationV2("https://ai.qiniuapi.com/v3/image/censor",'POST',$body,'application/json');
$token = $token['Authorization'];
$return = $this->curl_post("https://ai.qiniuapi.com/v3/image/censor",$body,['Content-Type:application/json','Authorization:'.$token]);
$return = json_decode($return,1);
if($return['code'] == 200){
if(isset($return['result']['scenes']['pulp'])){
return \json(['code'=>1,'msg'=>'色情']);
}
}
return \json(['code'=>0,'msg'=>'正常']);
}
// $url 是請求的鏈接
// $postdata 是傳輸?shù)臄?shù)據(jù)机断,數(shù)組格式
function curl_post( $url, $postdata,$header = [] ) {
//初始化
$curl = curl_init();
//設(shè)置抓取的url
curl_setopt($curl, CURLOPT_URL, $url);
//設(shè)置頭文件的信息作為數(shù)據(jù)流輸出
curl_setopt($curl, CURLOPT_HEADER, 0);
//設(shè)置獲取的信息以文件流的形式返回肛宋,而不是直接輸出。
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
// 超時設(shè)置
curl_setopt($curl, CURLOPT_TIMEOUT, 10);
// 超時設(shè)置纽门,以毫秒為單位
// curl_setopt($curl, CURLOPT_TIMEOUT_MS, 500);
// 設(shè)置請求頭
curl_setopt($curl, CURLOPT_HTTPHEADER, $header);
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, FALSE );
curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, FALSE );
//設(shè)置post方式提交
curl_setopt($curl, CURLOPT_POST, 1);
curl_setopt($curl, CURLOPT_POSTFIELDS, $postdata);
//執(zhí)行命令
$data = curl_exec($curl);
// 顯示錯誤信息
if (curl_error($curl)) {
print "Error: " . curl_error($curl);
} else {
// 打印返回的內(nèi)容
curl_close($curl);
return $data;
}
}
七牛云sdk 自己引入就行了