echo kuaishouzhibo ("https://live.kuaishou.com/u/KPL704668133");
//快手直播
function kuaishouzhibo ($url){
$xiey = array ("Accept-Language: zh-CN,zh;q=0.9","Cookie: clientid=3; did=web_effdb9007cadcab20942c0d2fbc996a5; client_key=65890b29; kpn=GAME_ZONE; didv=1649844274382; ksliveShowClipTip=true; needLoginToWatchHD=1; kuaishou.live.bfb1s=3e261140b0cf7444a0ba411c6f227d88");
$yuan = getwangye ($url,"电脑",$xiey);
$yuan = quzhongjian ($yuan, // 0 蓝光8M 1 蓝光4M 2 超清 3 高清
$pzhi = "2";
$zhi1 = jsonjiexi ($yuan,"json","playUrls",$pzhi,"url");
return $zhi1;
}
function jsonjiexi ($yuanma,$can1,$can2 = $jsondata = json_decode ($yuanma, true);
$linshi = $jsondata[$can1];
if ($can2 <> ""){
$linshi = $linshi[$can2];
}
if ($can3 <> ""){
$linshi = $linshi[$can3];
}
if ($can4 <> ""){
$linshi = $linshi[$can4];
}
if ($can5 <> ""){
$linshi = $linshi[$can5];
}
if ($can6 <> ""){
$linshi = $linshi[$can6];
}
if ($can7 <> ""){
$linshi = $linshi[$can7];
}
if (is_array ($linshi)){
return json_encode ($linshi,JSON_UNESCAPED_UNICODE);
}else{
return $linshi;
}
}
function quzhongjian ($str, $leftStr, $rightStr){
$left = strpos ($str, $leftStr);
$www = $left + strlen ($leftStr);
$right = strpos ($str, $rightStr,$www);
if ($left == false or $right == false){
return false;
}else{
return substr ($str,$www, $right-$www);
}
}
function getwangye ($url,$ua = $header = array ();
$header = array_merge ($xieyi,$header);
$ch = curl_init ();
curl_setopt ($ch, CURLOPT_URL, $url);
curl_setopt ($ch, CURLOPT_HTTPHEADER, $header);
curl_setopt ($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt ($ch, CURLOPT_SSL_VERIFYHOST, false);
curl_setopt ($ch, CURLOPT_HEADER, 0);
curl_setopt ($ch, CURLOPT_TIMEOUT, 30);
curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1); //禁止调用时就输出获取到的数据
curl_setopt ($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt ($ch, CURLOPT_AUTOREFERER, true);
curl_setopt ($ch, CURLOPT_REFERER, $url);
if ($ua == "手机"){
curl_setopt ($ch, CURLOPT_USERAGENT, "User-Agent: Mozilla/5.0 (Linux; Android 11; M2103K19C Build/RP1A.200720.011; wv) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/81.0.4044.145 Mobile Safari/537.36");
}elseif ($ua == "电脑"){
curl_setopt ($ch, CURLOPT_USERAGENT, "User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/86.0.4240.198 Safari/537.36");
}elseif ($ua == "随机"){
curl_setopt ($ch, CURLOPT_USERAGENT, rand_ua ());
}else{
curl_setopt ($ch, CURLOPT_USERAGENT, $ua);
}
$result = curl_exec ($ch);
curl_close ($ch);
return $result;
}
?>