|
代码示例:
直播:kmgd.php?id=060(&type=live)
(注:“&type=live”可有可无)
节目单:kmgd.php?id=060&type=epg
回看(不支持定时回看):kmgd.php?type=back&start=20220414190009&end=20220414193010&event_id=209737646(此为节目单中某链接里获取到的链接)
ID文件:
代码回复可见:
- <?php
- $head_httpdvb = 'http://httpdvb.slave.96599.cn:14311';
- $head_httpstream = 'http://stream.slave.96599.cn:14311';
- function getcurl($url){
- $user_agent = "Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.1; Trident/4.0)";
- $ch = curl_init();
- //curl_setopt ($ch, CURLOPT_PROXY, $proxy);
- curl_setopt ($ch, CURLOPT_URL, $url);//设置要访问的IP
- curl_setopt ($ch, CURLOPT_USERAGENT, $user_agent);//模拟用户使用的浏览器
- curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1 ); // 使用自动跳转
- curl_setopt ($ch, CURLOPT_TIMEOUT, 60); //设置超时时间
- curl_setopt ($ch, CURLOPT_AUTOREFERER, 1 ); // 自动设置Referer
- curl_setopt ($ch, CURLOPT_HEADER,0); //显示返回的HEAD区域的内容
- curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1);
- curl_setopt ($ch, CURLOPT_FOLLOWLOCATION, 1);
- curl_setopt ($ch, CURLOPT_TIMEOUT, 30);
- $result = curl_exec($ch);
- curl_close($ch);
- return $result;
- }
- function getinfo_json($chnlid,$token){
- $i_url = 'http://slave.96599.cn:13160/media/channel/get_info?chnlid=4200000'.$chnlid.'&accesstoken='.$token;
- $i_result = file_get_contents($i_url);
- return json_decode($i_result);
- }
- $accesstoken='R5EEFBFB6U309400ECK7735953DI9FB1EF78PBM300C495V0Z816B5W161AA85172C19FEB';
- $id=isset($_GET['id'])?$_GET['id']:'060';
- $type=isset($_GET['type'])?$_GET['type']:'live';
- if($type=='live'){
- //直播
- header("ACCESS-CONTROL-ALLOW-ORIGIN:*");
- header("Content-type: application/x-mpegURL");
- $json = getinfo_json($id,$accesstoken);
- $playtoken = isset($json->play_token)?$json->play_token:'ABCDEFGHI';
- $playurl=$head_httpdvb.'/playurl?playtype=live&protocol=hls&accesstoken='.$accesstoken.'&programid=4200000'.$id.'&playtoken='.$playtoken;
- $m3u8 =getcurl($playurl);
- echo preg_replace('/(http):\/\/([^\/]+)/i',$head_httpdvb,$m3u8);
- }else if($type=='epg'){
- //节目单
- $date=isset($_GET['date'])?$_GET['date']:date('Y-m-d');
- $time = time();
- $json = getinfo_json($id,$accesstoken);
- echo $json->chnl_name." ".$date." 节目单<br/>";
- $list_url='http://slave.96599.cn:13160/media/event/get_list?chnlid=4200000'.$id.'&pageidx=1&vcontrol=0&attachdesc=1&repeat=1&accesstoken='.$accesstoken.'&starttime='.strtotime($date).'&endtime='.strtotime('+1 day',strtotime($date)).'&pagenum=100&flagposter=0';
- $list_result = file_get_contents($list_url);
- $list_json = json_decode($list_result);
- $event_list=$list_json->event_list;
- $php_Self = substr($_SERVER['PHP_SELF'],strripos($_SERVER['PHP_SELF'],"/")+1);
- for ($x=0; $x<count($event_list); $x++) {
- $url=$php_Self.'?type=back&start='.date('YmdHis',$event_list[$x]->start_time).'&end='.date('YmdHis',$event_list[$x]->end_time).'&event_id='.$event_list[$x]->event_id;
- $n=date('H:i',$event_list[$x]->start_time).' '.$event_list[$x]->event_name;
- if(number_format($time)>number_format($event_list[$x]->end_time)){
- echo "<a href='{$url}' title=''>$n</a><br/>";
- }else{
- echo $n."<br/>";
- }
- }
- }else if($type=='back'){
- //回看
- header("ACCESS-CONTROL-ALLOW-ORIGIN:*");
- header("Content-type: application/x-mpegURL");
- $start=$_GET['start'];
- $end=$_GET['end'];
- $eventid=$_GET['event_id'];
- $url='http://slave.96599.cn:13160/media/event/get_info?accesstoken='.$accesstoken.'&eventid='.$eventid;
- $result = file_get_contents($url);
- $json = json_decode($result);
- $_playtoken = $json->play_token;
- $playurl=$head_httpstream.'/playurl?playtype=lookback&protocol=hls&starttime='.$start.'&endtime='.$end.'&accesstoken='.$accesstoken.'&programid='.$eventid.'&playtoken='.$_playtoken;
- $m3u8 =getcurl($playurl);
- echo preg_replace('/(http):\/\/([^\/]+)/i',$head_httpstream,$m3u8);
- }
- ?>
复制代码
|
本帖子中包含更多资源
您需要 登录 才可以下载或查看,没有账号?立即注册
×
|