|
最近找了下快手解析发现以前网上的大部分失效了所以分享一个出来
官方接口 非调用第三方
代码有点乱
各位将就一下
<?php
echo getData('63lUSa');
function getData($link = '')
{
$headers = get_headers('https://v.kuaishou.com/'.$link);
foreach($headers as $k => $v){
if(strpos($v, 'Location') === 0){
$url = substr($v, strlen('Location: '));
$photoId = sj($url, 'photo/', '?');
$principalId = sj($url, 'userId=', '&');
$apiUrl = 'https://live.kuaishou.com:443/m_graphql';
$opreationName = 'FeedQuery';
$variables = ['principalId'=>$principalId, 'photoId'=>$photoId];
$query = "query FeedQuery(\$principalId: String, \$photoId: String) {\n feedById(principalId: \$principalId, photoId: \$photoId) {\n currentWork {\n id\n thumbnailUrl\n poster\n workType\n type\n useVideoPlayer\n imgUrls\n imgSizes\n magicFace\n musicName\n caption\n location\n liked\n onlyFollowerCanComment\n relativeHeight\n timestamp\n width\n height\n counts {\n displayView\n displayLike\n displayComment\n __typename\n }\n user {\n id\n eid\n name\n avatar\n __typename\n }\n expTag\n playUrl\n __typename\n }\n status\n errMsg\n __typename\n }\n}\n";
$postData = ['operationName'=>$opreationName, 'variables'=>$variables, 'query'=>$query];
$postData = json_encode($postData);
// echo $postData.'<hr>';
$data = hs($apiUrl, $postData, 'utf-8', '', [
"User-Agent: PostmanRuntime/7.25.0",
"Content-Length: ".strlen($postData),
"Content-type: application/json",
"Host: live.kuaishou.com"
]);
$data = json_decode($data, true);
$videoData = $data['data']['feedById']['currentWork'];
$playUrl = $videoData['playUrl'];
$poster = $videoData['poster'];
$caption = $videoData['caption'];
$view = w2n($data['data']['feedById']['currentWork']['counts']['displayView']);
return json_encode(['title'=>$caption, 'cover'=>$poster, 'link'=>$playUrl, 'view'=>$view], 256);
break;
}
}
}
function sj($str, $front, $back)
{
if ($front == null) {
return ($ret = substr($str, 0, 0 - (strlen($str) - strpos($str, $back)))) === "" ? 0 : $ret;
} elseif ($back == null) {
if (strpos($str, $front) === false) return 0;
return substr($str, strlen($front) + strpos($str, $front));
} else {
return sj(sj($str, $front, null), null, $back);
}
}
function w2n($w = 0){
return strstr($w, 'w') ? substr($w, 0, -1)*10000 : $w*1;
}
function hs($url, $data = '', $charset = 'utf-8', $cookie = '', $header = [])
{
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_HTTPHEADER, $header);
if ($data) curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt ($ch, CURLOPT_REFERER, "http://www.baidu.cn/");
if ($data) curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
curl_setopt($ch, CURLOPT_COOKIE, $cookie);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 15);
curl_setopt($ch, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_0);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
$output = curl_exec($ch);
curl_close($ch);
return $output;
}
复制代码
|
|