1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Qiniu\Storage; |
4
|
|
|
|
5
|
|
|
use Qiniu\Auth; |
6
|
|
|
use Qiniu\Config; |
7
|
|
|
use Qiniu\Zone; |
8
|
|
|
use Qiniu\Http\Client; |
9
|
|
|
use Qiniu\Http\Error; |
10
|
|
|
use Qiniu\Http\Proxy; |
11
|
|
|
|
12
|
|
|
/** |
13
|
|
|
* 主要涉及了内容审核接口的实现,具体的接口规格可以参考 |
14
|
|
|
* |
15
|
|
|
* @link https://developer.qiniu.com/censor/api/5620/video-censor |
16
|
|
|
*/ |
17
|
|
|
final class ArgusManager |
18
|
|
|
{ |
19
|
|
|
private $auth; |
20
|
|
|
private $config; |
21
|
|
|
private $proxy; |
22
|
|
|
|
23
|
|
|
public function __construct( |
24
|
|
|
Auth $auth, |
25
|
|
|
Config $config = null, |
26
|
|
|
$proxy = null, |
27
|
|
|
$proxy_auth = null, |
28
|
|
|
$proxy_user_password = null |
29
|
|
|
) { |
30
|
|
|
$this->auth = $auth; |
31
|
|
|
if ($config == null) { |
32
|
|
|
$this->config = new Config(); |
33
|
|
|
} else { |
34
|
|
|
$this->config = $config; |
35
|
|
|
} |
36
|
|
|
$this->proxy = new Proxy($proxy, $proxy_auth, $proxy_user_password); |
37
|
|
|
} |
38
|
|
|
|
39
|
|
|
/** |
40
|
|
|
* 视频审核 |
41
|
|
|
* |
42
|
|
|
* @param string $body body信息 |
43
|
|
|
* |
44
|
|
|
* @return array 成功返回NULL,失败返回对象Qiniu\Http\Error |
45
|
|
|
* @link https://developer.qiniu.com/censor/api/5620/video-censor |
46
|
|
|
*/ |
47
|
|
|
public function censorVideo($body) |
48
|
|
|
{ |
49
|
|
|
$path = '/v3/video/censor'; |
50
|
|
|
|
51
|
|
|
return $this->arPost($path, $body); |
52
|
|
|
} |
53
|
|
|
|
54
|
|
|
|
55
|
|
|
/** |
56
|
|
|
* 图片审核 |
57
|
|
|
* |
58
|
|
|
* @param string $body |
59
|
|
|
* |
60
|
|
|
* @return array 成功返回NULL,失败返回对象Qiniu\Http\Error |
61
|
|
|
* @link https://developer.qiniu.com/censor/api/5588/image-censor |
62
|
|
|
*/ |
63
|
|
|
public function censorImage($body) |
64
|
|
|
{ |
65
|
|
|
$path = '/v3/image/censor'; |
66
|
|
|
|
67
|
|
|
return $this->arPost($path, $body); |
68
|
|
|
} |
69
|
|
|
|
70
|
|
|
/** |
71
|
|
|
* 查询视频审核结果 |
72
|
|
|
* |
73
|
|
|
* @param string $jobid 任务ID |
74
|
|
|
* @return array |
75
|
|
|
* @link https://developer.qiniu.com/censor/api/5620/video-censor |
76
|
|
|
*/ |
77
|
|
|
public function censorStatus($jobid) |
78
|
|
|
{ |
79
|
|
|
$scheme = "http://"; |
80
|
|
|
|
81
|
|
|
if ($this->config->useHTTPS === true) { |
82
|
|
|
$scheme = "https://"; |
83
|
|
|
} |
84
|
|
|
$url = $scheme . Config::ARGUS_HOST . "/v3/jobs/video/$jobid"; |
85
|
|
|
$response = $this->get($url); |
86
|
|
|
if (!$response->ok()) { |
87
|
|
|
return array(null, new Error($url, $response)); |
88
|
|
|
} |
89
|
|
|
return array($response->json(), null); |
90
|
|
|
} |
91
|
|
|
|
92
|
|
|
private function getArHost() |
93
|
|
|
{ |
94
|
|
|
$scheme = "http://"; |
95
|
|
|
if ($this->config->useHTTPS === true) { |
96
|
|
|
$scheme = "https://"; |
97
|
|
|
} |
98
|
|
|
return $scheme . Config::ARGUS_HOST; |
99
|
|
|
} |
100
|
|
|
|
101
|
|
|
private function arPost($path, $body = null) |
102
|
|
|
{ |
103
|
|
|
$url = $this->getArHost() . $path; |
104
|
|
|
return $this->post($url, $body); |
105
|
|
|
} |
106
|
|
|
|
107
|
|
|
private function get($url) |
108
|
|
|
{ |
109
|
|
|
$headers = $this->auth->authorizationV2($url, 'GET'); |
110
|
|
|
|
111
|
|
|
return Client::get($url, $headers, $this->proxy->makeReqOpt()); |
112
|
|
|
} |
113
|
|
|
|
114
|
|
|
private function post($url, $body) |
115
|
|
|
{ |
116
|
|
|
$headers = $this->auth->authorizationV2($url, 'POST', $body, 'application/json'); |
117
|
|
|
$headers['Content-Type'] = 'application/json'; |
118
|
|
|
$ret = Client::post($url, $body, $headers, $this->proxy->makeReqOpt()); |
119
|
|
|
if (!$ret->ok()) { |
120
|
|
|
return array(null, new Error($url, $ret)); |
121
|
|
|
} |
122
|
|
|
$r = ($ret->body === null) ? array() : $ret->json(); |
123
|
|
|
if (strstr($url, "video")) { |
124
|
|
|
$jobid = $r['job']; |
125
|
|
|
return array($jobid, null); |
126
|
|
|
} |
127
|
|
|
return array($r, null); |
128
|
|
|
} |
129
|
|
|
} |
130
|
|
|
|