美文网首页
php生成阿里云直播和推播地址

php生成阿里云直播和推播地址

作者: 耍帅oldboy | 来源:发表于2022-12-12 21:19 被阅读0次
public function zhibo(){
        //推流域名
        $push_domain = '';
        //推流域名配置的鉴权Key
        $push_key = '';
        //生成随机的AppName
        $appName = "12342456";
        //生成随机的StreamNmae
        $streamName = "6544321";
        //配置过期时间为1小时
        $expireTime = 3600;
        //播放域名
        $play_domain = '';
        //播放域名配置的鉴权Key
        $play_key = '';
        $push_url = $this->push_url($push_domain,$push_key,$expireTime,$appName,$streamName);
        $data['tui'] = $push_url;
        $play_url = $this->play_url($play_domain,$play_key,$expireTime,$appName,$streamName);
        $data['bo']=$play_url;
        dd($data);
 
    }
 
    function push_url($push_domain,$push_key,$expireTime,$appName,$streamName){
        //未开启鉴权Key的情况下
        if($push_key==''){
            $push_url = 'rtmp://'.$push_domain.'/'.$appName.'/'.$streamName;
            echo $push_url;
            return;
        }
        $timeStamp = time() + $expireTime;
        $sstring = '/'.$appName.'/'.$streamName.'-'.$timeStamp.'-0-0-'.$push_key;
        $md5hash = md5($sstring);
        $push_url = 'rtmp://'.$push_domain.'/'.$appName.'/'.$streamName.'?auth_key='.$timeStamp.'-0-0-'.$md5hash;
        return $push_url;
    }
 
 
    function play_url($play_domain,$play_key,$expireTime,$appName,$streamName){
        //未开启鉴权Key的情况下
        if($play_key==''){
            $rtmp_play_url = 'rtmp://'.$play_domain.'/'.$appName.'/'.$streamName;
            $flv_play_url = 'http://'.$play_domain.'/'.$appName.'/'.$streamName.'.flv';
            $hls_play_url = 'http://'.$play_domain.'/'.$appName.'/'.$streamName.'.m3u8';
        }else{
            $timeStamp = time() + $expireTime;
 
            $rtmp_sstring = '/'.$appName.'/'.$streamName.'-'.$timeStamp.'-0-0-'.$play_key;
            $rtmp_md5hash = md5($rtmp_sstring);
            $rtmp_play_url = 'rtmp://'.$play_domain.'/'.$appName.'/'.$streamName.'?auth_key='.$timeStamp.'-0-0-'.$rtmp_md5hash;
 
            $flv_sstring = '/'.$appName.'/'.$streamName.'.flv-'.$timeStamp.'-0-0-'.$play_key;
            $flv_md5hash = md5($flv_sstring);
            $flv_play_url = 'http://'.$play_domain.'/'.$appName.'/'.$streamName.'.flv?auth_key='.$timeStamp.'-0-0-'.$flv_md5hash;
 
            $hls_sstring = '/'.$appName.'/'.$streamName.'.m3u8-'.$timeStamp.'-0-0-'.$play_key;
            $hls_md5hash = md5($hls_sstring);
            $hls_play_url = 'http://'.$play_domain.'/'.$appName.'/'.$streamName.'.m3u8?auth_key='.$timeStamp.'-0-0-'.$hls_md5hash;
        }
        $data = [
            'rtmp'=>$rtmp_play_url,
            'flv'=>$flv_play_url,
            'hls'=>$hls_play_url,
        ];
        return $data;
    }

相关文章

网友评论

      本文标题:php生成阿里云直播和推播地址

      本文链接:https://www.haomeiwen.com/subject/ofmcqdtx.html