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