[PHP] 纯文本查看 复制代码
<?php
$t='{"photoId":"3xf4nkgxnznyyqg","page":"selected"}';
$name='visionVideoDetail';
$data=ks_dan($t,$name);
echo '<pre>';
print_r(json_decode($data,true));
function ks_dan($t,$name){
$url = 'https://video.kuaishou.com/graphql';
$header = array (
0 => 'Connection: keep-alive',
1 => 'accept: */*',
2 => 'User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/86.0.4240.198 Safari/537.36',
3 => 'content-type: application/json',
4 => 'Origin: https://video.kuaishou.com',
5 => 'Sec-Fetch-Site: same-origin',
6 => 'Sec-Fetch-Mode: cors',
7 => 'Sec-Fetch-Dest: empty',
8 => 'Referer: https://video.kuaishou.com/featured/3xr97vqpypqjvzw',
9 => 'Accept-Language: zh-CN,zh;q=0.9',
);
$postData = '{"operationName":"'.$name.'","variables":'.$t.',"query":"query '.$name.'($photoId: String, $type: String, $page: String) {\n '.$name.'(photoId: $photoId, type: $type, page: $page) {\n status\n type\n author {\n id\n name\n following\n headerUrl\n __typename\n }\n photo {\n id\n duration\n caption\n likeCount\n realLikeCount\n coverUrl\n photoUrl\n liked\n timestamp\n expTag\n llsid\n __typename\n }\n tags {\n type\n name\n __typename\n }\n commentLimit {\n canAddComment\n __typename\n }\n llsid\n __typename\n }\n}\n"}';
$cookie = '这里填写COOKIE'; //需要cookie的话去掉这行的注释
$timeout = 10;
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); //返回数据不直接输出
curl_setopt($ch, CURLOPT_ENCODING, "gzip"); //指定gzip压缩
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true); //302/301
//SSL
if(substr($url, 0, 8) === 'https://') {
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
//error:14077458:SSL routines:SSL23_GET_SERVER_HELLO:reason(1112)解决
//值有0-6,请参考手册,值1不行试试其他值
//curl_setopt($ch, CURLOPT_SSLVERSION, 1);
}
//post数据
if(!empty($postData)) {
curl_setopt($ch, CURLOPT_POST, 1); //发送POST类型数据
curl_setopt($ch, CURLOPT_POSTFIELDS, $postData); //POST数据,$post可以是数组(multipart/form-data),也可以是拼接参数串(application/x-www-form-urlencoded)
}
if(!empty($cookie)) {
$header[] = $cookie;
}
if(!empty($header)) {
curl_setopt($ch, CURLOPT_HTTPHEADER, $header); //使用header头信息
}
//超时时间
curl_setopt($ch, CURLOPT_TIMEOUT, (int)$timeout);
//执行
$content = curl_exec($ch);
if($error = curl_error($ch)) {
//log error
error_log($error);
}
curl_close($ch);
// $content 是请求结果
return $content;
}