<?php
$databases = include_once("./Application/Common/Conf/config.php");
$link = mysqli_connect(
    $databases['DB_HOST'], 
    $databases['DB_USER'],   
   $databases['DB_PWD'],
   $databases['DB_NAME']);   
   $sql="select * from bc_config where id =1 ";
   $result=mysqli_query($link,$sql);
 while ($row = mysqli_fetch_assoc($result))
  { 
	$shanghu = $row; 
  }
	 $jiekou1 = $shanghu['jiekou1'];
	 $jiekou2 = $shanghu['jiekou2'];
	 $jiekou3 = $shanghu['jiekou3'];
	 $jiekou4 = $shanghu['jiekou4'];
switch($_GET['lx']){
	
	case 'hqpt':
	$handle = fopen("{$jiekou1}","rb");
	$content = "";
	while (!feof($handle)) {
		$content .= fread($handle, 10000);
	};
	//$content = json_decode($content);
	echo $content;
	
	break;
	case 'hqzb':
	
		$url2 = isset($_GET["id"]) ? $_GET["id"] : "jsonxingguang.txt";
		$url= $jiekou2.$url2;
		$handle = fopen($url,"rb");
		$content = "";
		while (!feof($handle)) {
			$content .= fread($handle, 10000);
		};
		//$content = json_decode($content);

		$info=json_decode($content,true);
		
		 $videoarray = array();
		 for($i = 0;$i < count($info['zhubo']);$i++){
				$title=$info['zhubo'][$i]['title'];
				$title1= str_replace(array("%3F","%20","%28","%29","%5E","%7E"),"",$title);
			array_push($videoarray,array('address'=>$info['zhubo'][$i]['address'],'img'=>$info['zhubo'][$i]['img'],'title'=>$title1));
		 }
		 echo json_encode($videoarray, JSON_UNESCAPED_UNICODE);
		
	break;
	case'bofang':
		
		
		function getrealurl($url){
		$header = get_headers($url,1);
		if (strpos($header[0],'301') || strpos($header[0],'302')) {
			if(is_array($header['Location'])) {
				return $header['Location'][count($header['Location'])-1];
			}else{
				return $header['Location'];
			}
		}else {
			return $url;
			}
		}
		$url= $_GET['url'];
		if(strpos($url,'rtmp') !== false){ 
		 $url2 = $url; 
		}else{
		 $url2 = getrealurl($url); 
		}
		
		echo  json_encode(['code'=>1,'msg'=>$url2], JSON_UNESCAPED_UNICODE);
	break;
	
	case 'hqzb1':
	
		$handle = fopen("{$jiekou3}","rb");
	$content = "";
	while (!feof($handle)) {
		$content .= fread($handle, 10000);
	};
	//$content = json_decode($content);
	echo $content;
		
	break;
	case 'hqzb2':
	
		$url2 = isset($_GET["id"]) ? $_GET["id"] : "jsonxingguang.txt";
		$url= $jiekou4.$url2;
		$handle = fopen($url,"rb");
		$content = "";
		while (!feof($handle)) {
			$content .= fread($handle, 10000);
		};
		//$content = json_decode($content);

		$info=json_decode($content,true);
		
		 $videoarray = array();
		 for($i = 0;$i < count($info['zhubo']);$i++){
				$title=$info['zhubo'][$i]['title'];
				$title1= str_replace(array("%3F","%20","%28","%29","%5E","%7E"),"",$title);
			array_push($videoarray,array('address'=>$info['zhubo'][$i]['address'],'img'=>$info['zhubo'][$i]['img'],'title'=>$title1));
		 }
		 echo json_encode($videoarray, JSON_UNESCAPED_UNICODE);
		
	break;
}