Home  >  Article  >  php教程  >  乐视云直播 点播服务端api

乐视云直播 点播服务端api

PHP中文网
PHP中文网Original
2016-05-23 08:39:112205browse

php代码

<?php


class LeshiController 
{
    public $userid = &#39;&#39;;//用户id
    public $secret = &#39;&#39;;//私钥
    public $user_unique = &#39;&#39;;//用户唯一标识码,由乐视网统一分配并提供 UUID
    public $zhibo_apiurl = &#39;http://api.open.letvcloud.com/live/execute&#39;;//直播接口地址
    public $dianbo_apiurl = &#39;http://api.letvcloud.com/open.php&#39;;//点播接口地址
    public $zhibo_ver = &#39;3.0&#39;;//直播协议版本
    public $dianbo_ver = &#39;2.0&#39;;//点播协议版本
    
    public function __construct()
    {

    }
    /*
     * 直播api
     * $api_name string 直播接口名
     * $param array 直播参数
     */
    public function zhibo($api_name,$param=&#39;&#39;){
        $param[&#39;method&#39;] = $api_name;
        $res = $this->_sendZhiboApi($param);//请求接口
        return $res;
    }
    
    /*
     * 点播api
     * $api_name string 点播接口名
     * $param array 点播参数
     */
    public function dianbo($api_name,$param=&#39;&#39;){
        $param[&#39;api&#39;] = $api_name;
        $res = $this->_sendDianboApi($param);//请求接口
        return $res;
    }
    
    
    /*
     * 发送直播api请求
     */
    protected function _sendZhiboApi($param){
    
        $param[&#39;ver&#39;] = $this->zhibo_ver;//直播版本号
        $param[&#39;userid&#39;] = $this->userid;//用户数字id
        $param[&#39;timestamp&#39;] = time()*1000;//时间戳 毫秒
    
        $sign = $this->_getSign($param);//获取签名
    
        $param[&#39;sign&#39;] = $sign;
    
        $json = $this->_curlPost($this->zhibo_apiurl,$param);
    
        $res = json_decode($json,true);
        
        return $res;
    }
    
    /*
     * 发送点播api请求
     */
    protected function _sendDianboApi($param){
    
        $param[&#39;ver&#39;] = $this->dianbo_ver;//协议版本号,统一取值为2.0
        $param[&#39;user_unique&#39;] = $this->user_unique;//用户唯一标识码,由乐视网统一分配并提供
        $param[&#39;timestamp&#39;] = time()*1000;//当前Unix时间戳
        $param[&#39;format&#39;] = &#39;json&#39;;//返回参数格式:支持json和xml两种方式
    
        $sign = $this->_getSign($param);//获取签名
    
        $param[&#39;sign&#39;] = $sign;
    
        $json = $this->_curlPost($this->dianbo_apiurl,$param);
    
        $res = json_decode($json,true);
        
        if($res[&#39;code&#39;] == 0){
            return isset($res[&#39;data&#39;]) ? $res[&#39;data&#39;] : true;
        }
        
        return false;
    }
    
    
    
    /*
     * 	作用:生成签名
     */
    protected function _getSign($param)
    {
        //签名步骤一:按字典序排序参数
        ksort($param);
        
        $String = $this->_formatBizQueryParaMap($param);//拼接数组

        //签名步骤二:在string后加入KEY
        $String = $String.$this->secret;
 
        //签名步骤三:MD5加密
        $String = md5($String);
    
        return $String;
    }
    
    /*
     * 拼接数组
     */
    protected function _formatBizQueryParaMap($paraMap, $urlencode){
        $buff = "";
        ksort($paraMap);
        foreach ($paraMap as $k => $v){
            if($urlencode){
                $v = urlencode($v);
            }
            $buff .= $k . $v;
        }
        return $buff;
    }
    
    /*
     * 发送curl 请求
     */
    public function _curlPost($url,$data){
        
        $ch = curl_init();
        $header = "Accept-Charset: utf-8";
        curl_setopt($ch, CURLOPT_URL, $url);
        curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
        curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
        curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE);
        curl_setopt($ch, CURLOPT_HTTPHEADER, $header);
        curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
        curl_setopt($ch, CURLOPT_AUTOREFERER, 1);
        curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
        $tmpInfo = curl_exec($ch);
        curl_close($ch);
        
        return $tmpInfo;
    }
    
}
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn