Baidu Internet Disk external chain proxy
[File] index. php
$ Url, 'Folder' => $ folder, 'file' => $ file, 'picname' => $ picName, 'filename' => $ fileName ); class BaiduPanProxy {private $ uk; private $ Upload ID; private $ path; // folder path private $ file; // specify the file name private $ size when the output is an image; // specify the size of the output image as private $ method; // output method private $ folderIndex; // the folder's file index number private $ folder; // The json content of the folder is private $ url = ''; private $ preg = array (); // public $ trueLinkPreg = '| (http: [\\\/] {2, 6} www \. baidupcs \. co M [\\\/] {1, 3} file [\\\/] {1, 3 }. *) \\\ "| U'; // public $ trueLinkPreg = 'expired | (http: [\\\/] {} d \. pcs \. baidu \. com [\\\/] {1, 3} file [\\\/] {1, 3 }. *) \\\ "| U'; public function _ construct ($ url, $ preg) {$ this-> url = $ url; $ this-> preg = $ preg;} private function parseUrl () {foreach ($ this-> preg as $ k => $ value) {if (0! = Preg_match ($ value, $ this-> url, $ match) {switch ($ k) {case 'URL': list (, $ this-> Upload ID, $ this-> uk) = $ match; $ this-> method = 'get'; // in this case, the default value is get, you cannot customize $ this-> matchBy = 'URL'; break; case 'Folder': if (8 = count ($ match) // folder, without the name list (, $ this-> method, $ this-> Upload ID, $ this-> uk, $ this-> path, $ this-> folderIndex) = $ match; if (5 = count ($ match) // folder, traverse list (, $ this-> method, $ this-> Upload ID, $ this-> uk, $ this-> path) = $ match; if (7 = count ($ match) // folder, with a file name list (, $ this-> method, $ this-> consumer ID, $ this-> uk, $ this-> path, $ this-> folderIndex) = $ match; $ this-> folderIndex = $ this-> folderIndex-1; $ this-> matchBy = 'Folder'; // var_dump ($ match); exit (); break; case 'file': list (, $ this-> method, $ this-> Upload ID, $ this-> uk) = $ match; $ this-> matchBy = 'file '; break; case 'picname': list (, $ This-> Upload ID, $ this-> uk, $ this-> path, $ c, $ u, $ q, $ this-> file) = $ match; $ this-> size = 'size = '. $ c. '_'. $ u. '& quality = '. $ q; $ this-> file = urldecode ($ this-> file); $ this-> matchBy = 'picname'; break; case 'filename': list (,, $ this-> Upload ID, $ this-> uk, $ this-> path, $ this-> file) = $ match; $ this-> file = urldecode ($ this-> file); $ this-> matchBy = 'filename'; break;} return $ this ;}} if (! $ Match) $ this-> error (); // exit if no correct parameter is found} private function parseFolder ($ url) {$ html = file_get_contents ($ url ); return json_decode ($ html, true);} private function searchFolder () {$ url =" http://pan.baidu.com/share/list?dir= ". $ This-> path. "& consumer id = ". $ this-> consumer ID. "& uk = ". $ this-> uk. "&"; $ this-> json = $ this-> parseFolder ($ url); if (! Is_array ($ this-> json) $ this-> error ();} private function getFolderIndex ($ list) {foreach ($ list as $ k => $ v) {if (strtolower ($ v ['server _ filename']) = strtolower ($ this-> file) return $ k ;}} private function digFolder ($ path = '', $ region id ='', $ uk = '') {$ url =" http://pan.baidu.com/share/list?dir= ". $ Path. "& consumer id = ". $ region ID. "& uk = ". $ uk. "&"; $ this-> json = $ this-> parseFolder ($ url); if (! Is_array ($ this-> json) $ this-> error (); foreach ($ this-> json ['list'] as $ arr) {if (1 = $ arr ['isdir']) $ this-> digFolder (urlencode ($ arr ['path']), $ region ID, $ uk ); else $ this-> str. = "". $ arr ['server _ filename']."
";}Return $ this-> str;} private function getRealLink () {if (! $ This-> method) {// if there is no method, only two methods are available: enter the actual file name or output the tunable Image. $ this-> searchFolder (); $ this-> folderIndex = $ this-> getFolderIndex ($ this-> json ['list']); if ($ this-> size) {// adjust the image output quality $ this-> realLink = preg_replace ("/size = c \ d + _ u \ d + & quality = \ d + /", $ this-> size, $ this-> json ['list'] [$ this-> folderIndex] ['thumbs '] ['url3']);} else {$ this-> realLink = $ this-> json ['list'] [$ this-> folderIndex] ['dlink'];} elseif ('Folder' ==$ this-> met Hod) {$ this-> realLink = $ this-> digFolder ($ this-> path, $ this-> consumer ID, $ this-> uk);} else {if (! $ This-> path) {$ url =" http://pan.baidu.com/share/link?shareid= ". $ This-> consumer ID. "& uk = ". $ this-> uk; $ html = file_get_contents ($ url); if (0 = preg_match ($ this-> trueLinkPreg, $ html, $ url )) $ this-> error (); $ _ string = array ("replace" => Array ("&",'\\'), "string" => Array ("&", ""); // replace the escape character $ this-> realLink = str_ireplace ($ _ string ["replace"], $ _ string ["string"], $ url [1]);} elseif ($ this-> path) {$ this-> searchFolder (); $ this-> realLink = $ this-> Json ['list'] [$ this-> folderIndex] ['dlink'] ;}} public function haveFun () {if ($ this-> checkNew ($ this-> localVersion, $ this-> checkFrequency) $ this-> updateFile ($ this-> localVersion ); $ this-> parseUrl ()-> getRealLink (); if ('show' = $ this-> method | 'Folder' = $ this-> method) echo $ this-> realLink; else header ("Location :". $ this-> realLink);} private function error () {die ('oops !! Failed to retrieve ~ Recommended https://www.php1.cn/;/a > Learn More ~ ');} Private function checkNew ($ localVersion, $ checkFrequency) {$ lastCheck = (int) @ file_get_contents (_ DIR __. "/. lastcheck "); if (time ()-$ lastCheck> $ checkFrequency) {@ file_put_contents (_ DIR __. "/. lastcheck ", time (); $ serverVersion = (double) @ file_get_contents (" https://raw.github.com/tofuliang/baidu-pan-proxy/master/version "); If ($ serverVersion-(double) $ localVersion> 0) return true; return false;} public function updateFile ($ localVersion) {$ new = (string) @ file_get_contents (" https://raw.github.com/tofuliang/baidu-pan-proxy/master/index.php "); If (strpos ($ new, 'startoffile ') & strpos ($ new, 'endoffile') {copy (_ FILE __, _ FILE __. $ localVersion) & @ file_put_contents (_ FILE __, $ new) & exit ("the agent has been updated to the new version ");}}} $ link = new BaiduPanProxy ($ _ SERVER ["QUERY_STRING"], $ preg); $ link-> localVersion = '0. 6'; $ link-> checkFrequency = 86400; // The number of seconds at which the server detects updates. the default value is $ link-> haveFun (); // ENDOFFILE