video_fanwe.php 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  1. <?php
  2. class VideoFanwe
  3. {
  4. private $m_config = null;
  5. private $fwyun_access_key;
  6. private $fwyun_secret_key;
  7. function __construct($m_config)
  8. {
  9. $this->m_config = $m_config;
  10. $this->fwyun_access_key = $this->m_config['fwyun_access_key'];
  11. $this->fwyun_secret_key = $this->m_config['fwyun_secret_key'];
  12. if ($this->fwyun_secret_key == '' || $this->fwyun_access_key == '') {
  13. if(intval(FANWE_DEBUG)){
  14. log_file('fwyun_access_key','video_fanwe');
  15. log_file( $this->fwyun_access_key,'video_fanwe');
  16. log_file('fwyun_secret_key','video_fanwe');
  17. log_file($this->fwyun_secret_key,'video_fanwe');
  18. }
  19. ajax_return(array(
  20. 'status' => 0,
  21. 'error' => '方维云账号未配置!',
  22. ));
  23. }
  24. }
  25. public function Create($user_id, $video_id)
  26. {
  27. $result = $this->invoke(array(
  28. 'act' => 'create',
  29. ));
  30. if (!$result['status']) {
  31. ajax_return(array(
  32. 'status' => 0,
  33. 'error' => $result['error'],
  34. ));
  35. }
  36. if(intval(FANWE_DEBUG)){
  37. log_file('Create','video_fanwe');
  38. log_file($result,'video_fanwe');
  39. }
  40. $data = $result['data'];
  41. return array(
  42. 'channel_id' => $data['stream_id'],
  43. 'upstream_address' => $data['push_rtmp'],
  44. 'downstream_address' => array(
  45. 'rtmp' => $data['play_rtmp'],
  46. 'flv' => $data['play_flv'],
  47. 'hls' => $data['play_hls'],
  48. ),
  49. );
  50. }
  51. public function Query($stream_id)
  52. {
  53. $result = $this->invoke(array(
  54. 'act' => 'query',
  55. 'stream_id' => $stream_id,
  56. ));
  57. if (!$result['status']) {
  58. return array(
  59. 'status' => 0,
  60. 'error' => $result['error'],
  61. );
  62. }
  63. if(intval(FANWE_DEBUG)){
  64. log_file('Query','video_fanwe');
  65. log_file($result,'video_fanwe');
  66. }
  67. $data = $result['data'];
  68. return array(
  69. 'channel_id' => $stream_id,
  70. 'status' => $data['stream_status'],
  71. );
  72. }
  73. public function Stop($stream_id)
  74. {
  75. $result = $this->invoke(array(
  76. 'act' => 'stop',
  77. 'stream_id' => $stream_id,
  78. ));
  79. if (!$result['status']) {
  80. return array(
  81. 'status' => 0,
  82. 'error' => $result['error'],
  83. );
  84. }
  85. if(intval(FANWE_DEBUG)){
  86. log_file('Stop','video_fanwe');
  87. log_file($result,'video_fanwe');
  88. }
  89. return $result['data'];
  90. }
  91. //查询查询
  92. public function GetRecord($stream_id)
  93. {
  94. $result = $this->invoke(array(
  95. 'act' => 'get_record',
  96. 'stream_id' => $stream_id,
  97. ));
  98. if (!$result['status']) {
  99. return array(
  100. 'status' => 0,
  101. 'error' => $result['error'],
  102. );
  103. }
  104. if(intval(FANWE_DEBUG)){
  105. log_file('GetRecord','video_fanwe');
  106. log_file($result,'video_fanwe');
  107. }
  108. return array('totalCount' => $result['data']['totalCount'], 'filesInfo' => $result['data']['filesInfo'], 'urls' => $result['data']['file_list']);
  109. }
  110. private function invoke($params)
  111. {
  112. $url = "http://ilvbt5.fanwe.net/video";
  113. fanwe_require(APP_ROOT_PATH . 'system/saas/SAASAPIClient.php');
  114. $client = new \SAASAPIClient($this->fwyun_access_key, $this->fwyun_secret_key);
  115. return $client->invoke($url, $params);
  116. }
  117. }