php版網易視頻雲api

來源:互聯網
上載者:User

標籤:

最近在做線上教育課程,使用網易雲視頻作為線上ApsaraVideo for Live。

網易官方只有java樣本,我們使用php,就自己寫個api。

當然實現也是很簡單的。

示範:http://www.deitui.com/index.php?m=openclass 

class v163Class{private $AppKey;                //開發人員平台分配的AppKey    private $AppSecret;             //開發人員平台分配的AppSecret,可重新整理    private $Nonce;//隨機數(最大長度128個字元)    private $CurTime;             //當前UTC時間戳記,從1970年1月1日0點0 分0 秒開始到現在的秒數(String)    private $CheckSum;//SHA1(AppSecret + Nonce + CurTime),三個參數拼接的字串,進行SHA1雜湊計算,轉化成16進位字元(String,小寫)    const   HEX_DIGITS = "0123456789abcdef";public function __construct($AppKey,$AppSecret){        $this->AppKey    = $AppKey;        $this->AppSecret = $AppSecret;    }/**產生驗證碼**/ public function checkSumBuilder(){    //此部分產生隨機字串    $hex_digits = self::HEX_DIGITS;    $this->Nonce;    for($i=0;$i<128;$i++){//隨機字串最大128個字元,也可以小於該數    $this->Nonce.= $hex_digits[rand(0,15)];    }    $this->CurTime = (string)(time());//目前時間戳,以秒為單位    $join_string = $this->AppSecret.$this->Nonce.$this->CurTime;    $this->CheckSum = sha1($join_string);     } /*****post請求******/public function postDataCurl($url,$data=array()){    $this->checkSumBuilder();//發送請求前需先產生checkSumif(!empty($data)){$json=json_encode($data);}else{$json="";}$timeout = 5000;          $http_header = array(            ‘AppKey:‘.$this->AppKey,            ‘Nonce:‘.$this->Nonce,            ‘CurTime:‘.$this->CurTime,            ‘CheckSum:‘.$this->CheckSum,            ‘Content-Type: application/json;charset=utf-8;‘,‘Content-Length: ‘ . strlen($json)        );$ch = curl_init(); curl_setopt ($ch, CURLOPT_URL, $url);        curl_setopt ($ch, CURLOPT_POST, 1);        curl_setopt ($ch, CURLOPT_POSTFIELDS, $json);        curl_setopt ($ch, CURLOPT_HEADER, false); curl_setopt ($ch, CURLOPT_HTTPHEADER,$http_header);curl_setopt ($ch, CURLOPT_SSL_VERIFYPEER,false);        curl_setopt ($ch, CURLOPT_CONNECTTIMEOUT, $timeout);         curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1);        $result = curl_exec($ch);          if (false === $result) {            $result =  curl_errno($ch);        }curl_close($ch); return json_decode($result,true) ;    } /***頻道添加***/public function channel_add($name,$type=0){$url="https://vcloud.163.com/app/channel/create";return $data=$this->postDataCurl($url,array("name"=>$name,"type"=>$type));}/****頻道更新*****/public function channel_update($name,$cid,$type=0){$url="https://vcloud.163.com/app/channel/update";return $data=$this->postDataCurl($url,array("name"=>$name,"cid"=>$cid,"type"=>$type));}/****頻道刪除******/public function channel_delete($cid){$url="https://vcloud.163.com/app/channel/delete";return $data=$this->postDataCurl($url,array("cid"=>$cid));}/****擷取頻道資訊******/public function channel_get($cid){$url="https://vcloud.163.com/app/channelstats";return $data=$this->postDataCurl($url,array("cid"=>$cid));}/***擷取頻道列表recordsint單頁記錄數,預設值為10否pnumint要取第幾頁,預設值為1否ofieldString排序的域,支援的排序域為:ctime(預設)否sortint升序還是降序,1升序,0降序,預設為desc否**/public function channel_list($option=array("records"=>10,"pnum"=>1,"ofield"=>"ctime","sort"=>1)){$url="https://vcloud.163.com/app/channellist";return $data=$this->postDataCurl($url,$option);}/**重新擷取推流地址***/public function channel_reset($cid){$url="https://vcloud.163.com/app/address";return $data=$this->postDataCurl($url,array("cid"=>$cid));}/*****設定頻道為錄製狀態cidString頻道ID是needRecordint1-開啟錄製; 0-關閉錄製是formatint1-flv; 0-mp4是durationint錄製切片時間長度(分鐘),預設120分鐘否filenameString錄製後檔案名稱,格式為filename_YYYYMMDD-HHmmssYYYYMMDD-HHmmss, 檔案名稱錄製起始時間(年月日時分秒) -錄製結束時間(年月日時分秒)否****/public function channel_setRecord($cid,$option=array()){$url="https://vcloud.163.com/app/channel/setAlwaysRecord";return $data=$this->postDataCurl($url,$option);}/****暫停頻道*****/public function channel_pause($cid){$url="https://vcloud.163.com/app/channel/pause";return $data=$this->postDataCurl($url,array("cid"=>$cid));}/****大量暫停頻道****/public function channel_pauselist($cidList){$url="https://vcloud.163.com/app/channellist/pause";return $data=$this->postDataCurl($url,array("cidList"=>$cidList));}/****恢複頻道*****/public function channel_resume($cid){$url="https://vcloud.163.com/app/channel/resume";return $data=$this->postDataCurl($url,array("cid"=>$cid));}/****大量復原頻道****/public function channel_resumelist($cidList){$url="https://vcloud.163.com/app/channellist/resume";return $data=$this->postDataCurl($url,array("cidList"=>$cidList));}/****擷取頻道的視頻地址*****/public function channel_videolist($cid){$url="https://vcloud.163.com/app/videolist";return $data=$this->postDataCurl($url,array("cid"=>$cid));}}

  

php版網易視頻雲api

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.