1.使用composer安装七牛云插件
composer require qiniu/php-sdk
也可参考七牛云官网给出的安装方案
参考链接
PHP SDK_SDK 下载_对象存储 - 七牛开发者中心 (qiniu.com)
2.控制器编写图片审核方法
? 1.先引入需要的命名空间
use Qiniu\http\Client; use Qiniu\Auth;
function imageCheck()
{
// 用于签名的公钥和私钥
$ak ="";//这里填写你的ak
$sk ="";//这里填写你的sk
$image_url='https://img-home.csdnimg.cn/images/20211129024917.jpg';//这里是图片地址
$host = 'ai.qiniuapi.com';
$uri = 'http://ai.qiniuapi.com/v3/image/censor';//请求接口
$contentType = 'application/json';
$method='POST';
//审核类型scenes与相应的label/group(值)
$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($ak,$sk);
$headers = $auth->authorizationV2($uri, $method, json_encode($body), $contentType);
$headers['Content-Type'] = $contentType;
$headers['Host'] = $host;
$res = Client::post($uri, json_encode($body), $headers);//需要引入命名空间
$res = $res->body;
$res = json_decode($res,true);
$res = $res['result']['scenes']['pulp']['suggestion'];
if($res=='pass')//鉴定结果通过 ,无色请
{
// 可以添加入库,这里自由发挥即可
}
}
|