Skip to content

Commit 48ccc82

Browse files
committed
Optimization code
add ArgusManager.php
1 parent c3ab8a3 commit 48ccc82

File tree

3 files changed

+101
-55
lines changed

3 files changed

+101
-55
lines changed

examples/pulpvideo.php

Lines changed: 28 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,19 +9,44 @@
99
$secretKey = getenv('QINIU_SECRET_KEY');
1010
$auth = new Auth($accessKey, $secretKey);
1111
$config = new \Qiniu\Config();
12-
$bucketManager = new \Qiniu\Storage\BucketManager($auth, $config);
12+
$ArgusManager = new \Qiniu\Storage\ArgusManager($auth, $config);
1313

1414
$reqBody = array();
15-
$reqBody['uri'] = "xxxxxxxx";
15+
$reqBody['uri'] = "xxxx";
16+
1617
$ops = array();
1718
$ops = array(
1819
array(
1920
'op' => 'pulp',
21+
'params' => array(
22+
'labels' => array(
23+
array(
24+
'label' => "1",
25+
'select' => 1,
26+
'score' => 2,
27+
),
28+
)
29+
)
2030
),
2131
);
2232

33+
$params = array();
34+
$params = array(
35+
'async' => false,
36+
'vframe' => array(
37+
'mode' => 1,
38+
'interval' => 8,
39+
)
40+
);
41+
42+
$req = array();
43+
$req['data'] = $reqBody;
44+
$req['ops'] = $ops;
45+
$req['params'] = $params;
46+
$body = json_encode($req);
47+
2348
$vid = "xxxx";
24-
list($ret, $err) = $bucketManager->pulpVideo($reqBody, $ops, $vid);
49+
list($ret, $err) = $ArgusManager->pulpVideo($body, $vid);
2550

2651
if ($err !== null) {
2752
var_dump($err);

src/Qiniu/Storage/ArgusManager.php

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
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/dora/manual/3674/kodo-product-introduction
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+
* @param $vid videoID
35+
*
36+
* @return mixed 成功返回NULL,失败返回对象Qiniu\Http\Error
37+
* @link https://developer.qiniu.com/dora/manual/4258/video-pulp
38+
*/
39+
public function pulpVideo($body, $vid)
40+
{
41+
$path = '/v1/video/' . $vid;
42+
43+
return $this->arPost($path, $body);
44+
}
45+
46+
private function getArHost()
47+
{
48+
$scheme = "http://";
49+
if ($this->config->useHTTPS == true) {
50+
$scheme = "https://";
51+
}
52+
return $scheme . Config::ARGUS_HOST;
53+
}
54+
55+
private function arPost($path, $body = null)
56+
{
57+
$url = $this->getArHost() . $path;
58+
return $this->post($url, $body);
59+
}
60+
61+
private function post($url, $body)
62+
{
63+
$headers = $this->auth->authorizationV2($url, 'POST', $body, 'application/json');
64+
$headers['Content-Type']='application/json';
65+
$ret = Client::post($url, $body, $headers);
66+
if (!$ret->ok()) {
67+
print($ret->statusCode);
68+
return array(null, new Error($url, $ret));
69+
}
70+
$r = ($ret->body === null) ? array() : $ret->json();
71+
return array($r, null);
72+
}
73+
}

src/Qiniu/Storage/BucketManager.php

Lines changed: 0 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -187,30 +187,6 @@ public function move($from_bucket, $from_key, $to_bucket, $to_key, $force = fals
187187
return $error;
188188
}
189189

190-
/**
191-
* 将资源从一个空间到另一个空间
192-
*
193-
* @param $reqBody 待操作资源所在空间
194-
* @param $from_key 待操作资源文件名
195-
* @param $to_bucket 目标资源空间名
196-
* @param $to_key 目标资源文件名
197-
*
198-
* @return mixed 成功返回NULL,失败返回对象Qiniu\Http\Error
199-
* @link https://developer.qiniu.com/dora/manual/4258/video-pulp
200-
*/
201-
public function pulpVideo($reqBody, $ops, $vid, $params = null)
202-
{
203-
$path = '/v1/video/' . $vid;
204-
$req = array();
205-
$req['data'] = $reqBody;
206-
$req['ops'] = $ops;
207-
if (isset($params)) {
208-
$req['params'] = $params;
209-
}
210-
$body = json_encode($req);
211-
return $this->arPost($path, $body);
212-
}
213-
214190
/**
215191
* 主动修改指定资源的文件类型
216192
*
@@ -383,15 +359,6 @@ private function getRsHost()
383359
return $scheme . Config::RS_HOST;
384360
}
385361

386-
private function getArHost()
387-
{
388-
$scheme = "http://";
389-
if ($this->config->useHTTPS == true) {
390-
$scheme = "https://";
391-
}
392-
return $scheme . Config::ARGUS_HOST;
393-
}
394-
395362
private function getApiHost()
396363
{
397364
$scheme = "http://";
@@ -419,12 +386,6 @@ private function rsGet($path)
419386
return $this->get($url);
420387
}
421388

422-
private function arPost($path, $body = null)
423-
{
424-
$url = $this->getArHost() . $path;
425-
return $this->pluPost($url, 'POST', $body);
426-
}
427-
428389
private function get($url)
429390
{
430391
$headers = $this->auth->authorization($url);
@@ -446,19 +407,6 @@ private function post($url, $body)
446407
return array($r, null);
447408
}
448409

449-
private function pluPost($url, $method, $body)
450-
{
451-
$headers = $this->auth->authorizationV2($url, $method, $body, 'application/json');
452-
$headers['Content-Type']='application/json';
453-
$ret = Client::post($url, $body, $headers);
454-
if (!$ret->ok()) {
455-
print($ret->statusCode);
456-
return array(null, new Error($url, $ret));
457-
}
458-
$r = ($ret->body === null) ? array() : $ret->json();
459-
return array($r, null);
460-
}
461-
462410
public static function buildBatchCopy($source_bucket, $key_pairs, $target_bucket, $force)
463411
{
464412
return self::twoKeyBatch('/copy', $source_bucket, $key_pairs, $target_bucket, $force);

0 commit comments

Comments
 (0)