<?php
function baiduPan($url) {
if (strpos($url, 'pan.baidu.com') === false) return false;
$ch = curl_init();
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_HEADER, false);
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_VERBOSE, true);
/*
$cookiefile = "cookie.txt";
curl_setopt($ch, CURLOPT_COOKIEJAR, $cookiefile);
curl_setopt($ch, CURLOPT_COOKIEFILE, $cookiefile);
curl_close($ch);
$ch = curl_init();
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_HEADER, false);
curl_setopt($ch, CURLOPT_VERBOSE, true);
curl_setopt($ch, CURLOPT_COOKIEJAR, $cookiefile);
curl_setopt($ch, CURLOPT_COOKIEFILE, $cookiefile);
*/
$html = curl_exec($ch);
file_put_contents("out3.txt", $html);
if (preg_match('/fs_id\\\\":\\\\"(.*?)\\\\"/i', $html, $m)) {
$fsid = $m[1];
preg_match('/shareid="(.*?)"/i', $html, $m);
$shareid = $m[1];
preg_match('/.uk="(.*?)"/i', $html, $m);
$uk = $m[1];
preg_match('/timestamp="(.*?)"/i', $html, $m);
$timestamp = $m[1];
curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla/5.0 (Windows NT 6.1; WOW64; rv:19.0) Gecko/20100101 Firefox/19.0");
curl_setopt($ch, CURLOPT_HTTPHEADER, array("X-Requested-With: XMLHttpRequest", "Accept: application/json"));
$referer = $url;
curl_setopt($ch, CURLOPT_REFERER, $referer);
preg_match('/sign="(.*?)"/i', $html, $m);
$share_sign = $m[1];
$proxyUrl = sprintf('http://pan.baidu.com/share/download?uk=%s&shareid=%s&fid_list=%s&sign=%s',
$uk, $shareid, urlencode("[") . $fsid . urlencode("]"), $share_sign);
$proxyUrl .= sprintf("×tamp=%s", $timestamp);
var_dump($fsid);
$proxyUrl .= sprintf("&r=%s", rand(0, 1000000000) / 1000000000);
curl_setopt($ch, CURLOPT_URL, $proxyUrl);
$proxyHtml = curl_exec($ch);
$jsonObj = json_decode($proxyHtml, true);
var_dump($proxyHtml);exit();
$downloadButtonUrl = $jsonObj['dlink'];
$downloadButtonUrl = str_replace("\\\\/", "/", $downloadButtonUrl);
curl_setopt($ch, CURLOPT_URL, $downloadButtonUrl);
curl_setopt($ch, CURLOPT_VERBOSE, 1);
curl_setopt($ch, CURLOPT_HEADER, 1);
$result = curl_exec($ch);
list($header, $body) = explode("\r\n\r\n", $result, 2);
if (preg_match('/Location: (.*?)(\r?\n)/is', $header, $matches)) {
return $matches[1];
}
}
return false;
}
//$testurl = 'http://pan.baidu.com/wap/link?shareid=3142223074&uk=1864945200';
$testurl = 'http://pan.baidu.com/wap/link?shareid=2532037509&uk=1177880683';
$downurl = baiduPan($testurl);
echo $downurl;
baidu 云盘 php下载代码,还需要测试
最新推荐文章于 2024-08-14 16:41:24 发布