<?php
function SignIn4Bilibili($url, $header, $referer="", $cookie="") {
$ch = curl_init();
$options = array(
// 常量作为数组的索引
CURLOPT_URL => $url,
CURLOPT_USERAGENT => 'Mozilla/5.0 (Windows NT 10.0; WOW64; Trident/7.0; rv:11.0) like Gecko',
//CURLOPT_POST => true,
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "gzip",
CURLOPT_HEADER => 0,
CURLOPT_HTTPHEADER => $header,
CURLOPT_REFERER => $referer,
CURLOPT_COOKIE => $cookie,
// 规避SSL验证
CURLOPT_SSL_VERIFYPEER => false,
// 跳过HOST验证
CURLOPT_SSL_VERIFYHOST => false,
// 超时时间
CURLOPT_TIMEOUT => 100,
);
curl_setopt_array($ch, $options);
$result = curl_exec($ch);
curl_close($ch);
return $result;
}
?>
<?php
// 不能使用关联数组
$header = array();
$header[] = "authority: api.bilibili.com";
$header[] = "Accept: application/json, text/plain, */*";
$header[] = "origin: https://www.bilibili.com";
$header[] = "referer: https://www.bilibili.com";
$header[] = "cookie: your cookie";
$url = "https://api.bilibili.com/x/web-interface/nav/stat";
echo SignIn4Bilibili($url, $header);
/*
// 常量作为数组的索引
$api = 'fucku';
$options = array(
0 => "index 0",
CURLOPT_URL => $api,
CURLOPT_POST => true,
CURLOPT_RETURNTRANSFER => true,
CURLOPT_HTTPHEADER => array('Content-Type: text/plain'),
);
echo "</br>";
//var_dump ($options);
echo "</br>";
echo $options[10002];
echo "</br>";
echo $options[10023][0];
echo "</br>";
echo $options[0];
*/
?>
|