-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathCheckPicture.php
64 lines (50 loc) · 1.72 KB
/
CheckPicture.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
<?php
/**
* picture check with ali sdk on composer lib
*/
include_once 'aliyun-php-sdk-core/Config.php';
use Green\Request\V20160308 as Green;
class CheckPicture
{
private $client;
private $request;
public function __construct($accessKey, $secretKey)
{
$iClientProfile = DefaultProfile::getProfile("cn-hangzhou", $accessKey, $secretKey);
$this->client = new DefaultAcsClient($iClientProfile);
// 图片检测
$this->request = new Green\ImageDetectionRequest ();
}
public function check($url)
{
//设置参数
//设置为同步调用
$this->request->setAsync("false");
//设置图片链接
//同步只支持单张图片
$this->request->setImageUrl(json_encode(array($url)));
//设置检测的场景
//porn: 黄图检测
//ocr: 图文识别
$this->request->setScene(json_encode(array("porn")));
try {
$response = $this->client->getAcsResponse($this->request);
//print_r($response);
//返回状态值成功时进行处理
if ("Success" == $response->Code) {
$imageResults = $response->ImageResults->ImageResult;
foreach ($imageResults as $imageResult) {
//黄图结果处理
$pornResult = $imageResult->PornResult;
return [
'rate' => $pornResult->Rate,
'label' => $pornResult->Label,
];
}
}
} catch (Exception $e) {
return false;
// print_r($e);
}
}
}