ArgusManager.php 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. <?php
  2. namespace Qiniu\Storage;
  3. use Qiniu\Auth;
  4. use Qiniu\Config;
  5. use Qiniu\Zone;
  6. use Qiniu\Http\Client;
  7. use Qiniu\Http\Error;
  8. /**
  9. * 主要涉及了鉴黄接口的实现,具体的接口规格可以参考
  10. *
  11. * @link https://developer.qiniu.com/dora/manual/3674/kodo-product-introduction
  12. */
  13. final class ArgusManager
  14. {
  15. private $auth;
  16. private $config;
  17. public function __construct(Auth $auth, Config $config = null)
  18. {
  19. $this->auth = $auth;
  20. if ($config == null) {
  21. $this->config = new Config();
  22. } else {
  23. $this->config = $config;
  24. }
  25. }
  26. /**
  27. * 视频鉴黄
  28. *
  29. * @param $body body信息
  30. * @param $vid videoID
  31. *
  32. * @return mixed 成功返回NULL,失败返回对象Qiniu\Http\Error
  33. * @link https://developer.qiniu.com/dora/manual/4258/video-pulp
  34. */
  35. public function pulpVideo($body, $vid)
  36. {
  37. $path = '/v1/video/' . $vid;
  38. return $this->arPost($path, $body);
  39. }
  40. private function getArHost()
  41. {
  42. $scheme = "http://";
  43. if ($this->config->useHTTPS == true) {
  44. $scheme = "https://";
  45. }
  46. return $scheme . Config::ARGUS_HOST;
  47. }
  48. private function arPost($path, $body = null)
  49. {
  50. $url = $this->getArHost() . $path;
  51. return $this->post($url, $body);
  52. }
  53. private function post($url, $body)
  54. {
  55. $headers = $this->auth->authorizationV2($url, 'POST', $body, 'application/json');
  56. $headers['Content-Type']='application/json';
  57. $ret = Client::post($url, $body, $headers);
  58. if (!$ret->ok()) {
  59. print($ret->statusCode);
  60. return array(null, new Error($url, $ret));
  61. }
  62. $r = ($ret->body === null) ? array() : $ret->json();
  63. return array($r, null);
  64. }
  65. }