搜狐视频真实地址接口实例

调用方式"https://域名/XX.php?url=视频地址 "

<?php
//搜狐视频真实地址
header("Access-Control-Allow-Origin:*");
header('Content-type: application/json');
!empty($_GET['url']) ? $geturl = $_GET['url'] : exit(json_encode([
    'code'=>202,
    "msg"=>"请输入网址"
],JSON_UNESCAPED_UNICODE));

$view = myCurl($geturl);
$b = 'vid="';
$c = '"';
$id = GetBetween($view,$b,$c); //类型1
$b = "vid:";
$c = ",";
$mid = GetBetween($view,$b,$c); //类型2
if ($id){
	$vids = $id;
}else{
	$vids = $mid;
}
$api = myCurl('https://m.tv.sohu.com/phone_playinfo?vid='.$vids.'&partner=1&uid=200303033657WXZ8');
$json = mb_convert_encoding($api,'utf-8', 'gbk');
$data = json_decode($json,true);
$video = $data['data']['urls']['downloadUrl'][0][0];

if ($video){
	$value = array('code'=>200,'title'=>$data['data']['video_name'],'url'=>$video);
}else{
	$value = array('code'=>202,'msg'=>'接口失效');
}

echo json_encode($value,JSON_PRETTY_PRINT|JSON_UNESCAPED_UNICODE);


function myCurl($url){ //Curl GET
    $ch = curl_init();     // Curl 初始化  
    $timeout = 30;     // 超时时间:30s  
    $ua='Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/50.0.2661.102 Safari/537.36';    // 伪造抓取 UA  
    $ip = mt_rand(11, 191) . "." . mt_rand(0, 240) . "." . mt_rand(1, 240) . "." . mt_rand(1, 240);
    curl_setopt($ch, CURLOPT_URL, $url);              // 设置 Curl 目标  
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);      // Curl 请求有返回的值  
    curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, $timeout);     // 设置抓取超时时间  
    curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);        // 跟踪重定向  
    curl_setopt($ch, CURLOPT_REFERER, $url);   // 伪造来源网址  
    curl_setopt($ch, CURLOPT_HTTPHEADER, array('X-FORWARDED-FOR:'.$ip, 'CLIENT-IP:'.$ip));  //伪造IP  
    curl_setopt($ch, CURLOPT_USERAGENT, $ua);   // 伪造ua   
    curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE); // https请求 不验证证书和hosts  
    curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE);  //不检查 证书中 SSL 加密算法是否存在
    curl_setopt($ch, CURLOPT_AUTOREFERER, true); ////当Location:重定向时,自动设置header中的Referer:信息
    curl_setopt($ch, CURLOPT_ENCODING, '');//解决网页乱码问题
    curl_setopt($ch, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_0); //强制协议为1.0
    curl_setopt($ch, CURLOPT_IPRESOLVE, CURL_IPRESOLVE_V4 ); //强制使用IPV4协议解析域名
    $content = curl_exec($ch);   
    curl_close($ch);    // 结束 Curl  
    return $content;    // 函数返回内容  
}

// 截取ID
function GetBetween($content,$start,$end) {
	$r = explode($start, $content);
	if (isset($r[1])) {
		$r = explode($end, $r[1]);
		return $r[0];
	}
	return '';
}