0

0

百度网盘的外链代理

PHP中文网

PHP中文网

发布时间:2016-05-25 17:04:52

|

2234人浏览过

|

来源于php中文网

原创

 [文件] index.php 

$url,'folder'=>$folder,'file'=>$file,'picName'=>$picName,'fileName'=>$fileName);

class BaiduPanProxy{
    private $uk;
    private $shareid;
    private $path; //文件夹路径
    private $file; //指定输出为图片时的文件名
    private $size; //指定输出为图片时的尺寸
    private $method; //输出方法
    private $folderIndex; //文件夹的文件索引号
    private $folder;//文件夹的json内容
    private $url='';
    private $preg=array();
    // public $trueLinkPreg='|(http:[\\\/]{2,6}www\.baidupcs\.com[\\\/]{1,3}file[\\\/]{1,3}.*)\\\"|U'; //已失效
    public $trueLinkPreg='|(http:[\\\/]{2,6}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->shareid, $this->uk) = $match;
                        $this->method='get';//此情况下默认是get,不能自定义
                        $this->matchBy='url';
                        break;

                    case 'folder':
                        if(8 == count ( $match )) // 文件夹,不带文件名
                            list ( , $this->method, $this->shareid, $this->uk, $this->path,,,$this->folderIndex) = $match;
                        if(5 == count ( $match )) // 文件夹,遍历
                            list ( , $this->method, $this->shareid, $this->uk, $this->path) = $match;
                        if(7 == count ( $match )) // 文件夹,带文件名
                            list ( , $this->method, $this->shareid, $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->shareid, $this->uk) = $match;
                        $this->matchBy='file';
                        break;

                    case 'picName':
                        list ( , $this->shareid, $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->shareid, $this->uk, $this->path,$this->file) = $match;
                        $this->file=urldecode($this->file);
                        $this->matchBy='fileName';
                        break;
                }
                return $this;
            }
        }
        if(!$match) $this->error();//匹配不到任何正确的参数则退出
    }
    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 . "&shareid=" . $this->shareid . "&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 = '', $shareid = '', $uk = ''){
        $url = "http://pan.baidu.com/share/list?dir=" . $path . "&shareid=" . $shareid . "&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'] ), $shareid, $uk );
            else
                $this->str .= "" . $arr ['server_filename'] . "
"; } return $this->str; } private function getRealLink(){ if(!$this->method){//如果没有方法,只有输入真实文件名或输出可调质量图片两种方法 $this->searchFolder(); $this->folderIndex=$this->getFolderIndex($this->json['list']); if($this->size){ //调节图片输出质量 $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->method) { $this->realLink = $this->digFolder($this->path,$this->shareid ,$this->uk); }else{ if(!$this->path){ $url = "http://pan.baidu.com/share/link?shareid=" . $this->shareid . "&uk=" . $this->uk; $html = file_get_contents ( $url ); if (0 == preg_match ( $this->trueLinkPreg, $html, $url )) $this->error(); $_string = array ("replace" => Array ("&", '\\' ), "string" => Array ("&", "" ) ); // 替换转义字符 $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!! 获取失败诶~建议到http://www.php.cn/;/a>了解了解吧~'); } 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; } 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 ( "代理程序已更新到新版" ); } } } $link = new BaiduPanProxy($_SERVER ["QUERY_STRING"],$preg); $link->localVersion = '0.6'; $link->checkFrequency = 86400; // 每隔多少秒到服务器检测更新,默认是一天 $link->haveFun(); //ENDOFFILE

                               

MVM mall 网上购物系统
MVM mall 网上购物系统

采用 php+mysql 数据库方式运行的强大网上商店系统,执行效率高速度快,支持多语言,模板和代码分离,轻松创建属于自己的个性化用户界面 v3.5更新: 1).进一步静态化了活动商品. 2).提供了一些重要UFT-8转换文件 3).修复了除了网银在线支付其它支付显示错误的问题. 4).修改了LOGO广告管理,增加LOGO链接后主页LOGO路径错误的问题 5).修改了公告无法发布的问题,可能是打压

下载

                   

百度网盘
百度网盘

百度网盘是一款省心、好用的超级云存储产品,已为超过7亿用户提供云服务,空间超大,支持多类型文件的备份、分享、查看和处理,自建多个数据存储中心。有需要的小伙伴快来保存下载体验吧!

下载

相关标签:

php

本站声明:本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn

相关专题

更多
php源码安装教程大全
php源码安装教程大全

本专题整合了php源码安装教程,阅读专题下面的文章了解更多详细内容。

7

2025.12.31

php网站源码教程大全
php网站源码教程大全

本专题整合了php网站源码相关教程,阅读专题下面的文章了解更多详细内容。

4

2025.12.31

视频文件格式
视频文件格式

本专题整合了视频文件格式相关内容,阅读专题下面的文章了解更多详细内容。

7

2025.12.31

不受国内限制的浏览器大全
不受国内限制的浏览器大全

想找真正自由、无限制的上网体验?本合集精选2025年最开放、隐私强、访问无阻的浏览器App,涵盖Tor、Brave、Via、X浏览器、Mullvad等高自由度工具。支持自定义搜索引擎、广告拦截、隐身模式及全球网站无障碍访问,部分更具备防追踪、去谷歌化、双内核切换等高级功能。无论日常浏览、隐私保护还是突破地域限制,总有一款适合你!

7

2025.12.31

出现404解决方法大全
出现404解决方法大全

本专题整合了404错误解决方法大全,阅读专题下面的文章了解更多详细内容。

42

2025.12.31

html5怎么播放视频
html5怎么播放视频

想让网页流畅播放视频?本合集详解HTML5视频播放核心方法!涵盖<video>标签基础用法、多格式兼容(MP4/WebM/OGV)、自定义播放控件、响应式适配及常见浏览器兼容问题解决方案。无需插件,纯前端实现高清视频嵌入,助你快速打造现代化网页视频体验。

4

2025.12.31

关闭win10系统自动更新教程大全
关闭win10系统自动更新教程大全

本专题整合了关闭win10系统自动更新教程大全,阅读专题下面的文章了解更多详细内容。

3

2025.12.31

阻止电脑自动安装软件教程
阻止电脑自动安装软件教程

本专题整合了阻止电脑自动安装软件教程,阅读专题下面的文章了解更多详细教程。

3

2025.12.31

html5怎么使用
html5怎么使用

想快速上手HTML5开发?本合集为你整理最实用的HTML5使用指南!涵盖HTML5基础语法、主流框架(如Bootstrap、Vue、React)集成方法,以及无需安装、直接在线编辑运行的平台推荐(如CodePen、JSFiddle)。无论你是新手还是进阶开发者,都能轻松掌握HTML5网页制作、响应式布局与交互功能开发,零配置开启高效前端编程之旅!

2

2025.12.31

热门下载

更多
网站特效
/
网站源码
/
网站素材
/
前端模板

精品课程

更多
相关推荐
/
热门推荐
/
最新课程
PHP课程
PHP课程

共137课时 | 8.1万人学习

JavaScript ES5基础线上课程教学
JavaScript ES5基础线上课程教学

共6课时 | 6.9万人学习

PHP新手语法线上课程教学
PHP新手语法线上课程教学

共13课时 | 0.8万人学习

关于我们 免责申明 举报中心 意见反馈 讲师合作 广告合作 最新更新
php中文网:公益在线php培训,帮助PHP学习者快速成长!
关注服务号 技术交流群
PHP中文网订阅号
每天精选资源文章推送

Copyright 2014-2026 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号