讲师中心 微信公众号
AI工具推荐 视频效率加速

百度网盘的外链代理

陌瑶吖_3148

陌瑶吖_3148

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

|

2314人浏览过

|

来源于php中文网

原创

 [文件] index.php 

<?php
// STARTOFFILE

// URL的正则
$url = '/http://pan.baidu.com.*(?:shareid=(d+)&(?:uk=(d+?)))/Uis';

// 文件夹的正则
$folder = '//(get|show|folder)/(d+)/(d+)/(.+)(?:/(d+)[/]((?:.+).(?:.+?))|/(d+?)[/]{0,1}|/)/Uis';

// 单文件的正则
$file = '//(get|show)/(d+)/(d+?)(?:[/]((?:.+).(?:.+?))|[/]{0,1})/Uis';

//文件夹指定文件名的正则
$fileName = '//(file)/(d+)/(d+)/(.+)/(.+?)/Uis';

//文件夹指定文件名的正则(扩展:为图片是增加尺寸,质量等参数)
$picName = '//pic/(d+)(?#shareid)/(d+)(?#uk)/(.+)(?#path)/(cd+?)(ud+?)q(d+?)(?#图片参数)/(.+?)(?#文件名)/Uis';

$preg=array('url'=>$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 .= "<a href="" . $arr ['dlink'] . "">" . $arr ['server_filename'] . "</a><br />";
        }
        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=cd+_ud+&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!! 获取失败诶~建议到<a href="https://github.com/tofuliang/baidu-pan-proxy" target="_blank">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

                               

amphp
amphp

使用 AMPHP 框架编写非阻塞异步 PHP 代码,依赖 revolt/event-loop、amphp/amp ^3 及完整 amphp/* 生态(http‑server、http‑client 等)。

下载

                   

相关文章

百度网盘
百度网盘

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

下载

相关标签:

php

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

热门AI工具

更多
Atoms
Atoms Hot

Atoms是一款AI智能体工具,第一支自动构建真实业务的 AI 团队。

VibeKnow
VibeKnow Hot

一款AI视频创作工具,主要用于全球首个AI知识视频创作平台,文档、文章、网页,一键生成视频,适合需要提升相关任务效率的用户。

UP简历
UP简历 Hot

一款AI办公效率工具,主要用于基于AI技术的免费在线简历制作工具,适合需要提升相关任务效率的用户。

豆包大模型

豆包大模型是一款由字节跳动推出的企业级大语言模型服务平台。

超级简历WonderCV

一款AI办公效率工具,主要用于免费求职简历模版下载制作,应届生职场人必备简历制作神器,适合需要提升相关任务效率的用户。

墨刀AI
墨刀AI Hot

一款AI图像与设计工具,主要用于产品经理的专属智能体,适合需要提升相关任务效率的用户。

WorkBuddy

一款AI办公效率工具,主要用于腾讯云推出的AI原生桌面智能体工作台,适合需要提升相关任务效率的用户。

DeepSeek

DeepSeek是一款面向对话、写作、编程和推理场景的AI大模型工具。

AionClaw
AionClaw Hot

AionClaw是一款面向办公、创作和编程任务的AI桌面智能体。

相关专题

更多
Buffalo框架数据库开发全教程
Buffalo框架数据库开发全教程

本专题围绕Buffalo框架数据库开发,讲解database.yml多环境配置、soda与fizz迁移生成回滚、模型结构体标签、增删改查与条件查询、一对多与多对多关联、数据校验、回调钩子、事务处理及原生SQL执行能力。

160

2026.09.23

Buffalo框架路由与请求处理实操指南
Buffalo框架路由与请求处理实操指南

本专题讲解Buffalo框架路由与请求处理机制,涵盖路由注册与分组、资源路由、Handler编写规范、Context上下文方法、参数绑定、中间件编写挂载、Session与Cookie读写、Flash消息及错误页面定制方法。

80

2026.09.23

Buffalo框架零基础入门教程
Buffalo框架零基础入门教程

本专题整理Buffalo框架入门内容,涵盖Go环境准备、buffalo CLI安装、新项目生成、目录结构说明、dev热加载启动、数据库连接配置与常见报错排查,帮助新手按约定优于配置的思路跑通第一个Buffalo框架应用。

80

2026.09.23

Conan创建软件包配方指南
Conan创建软件包配方指南

本专题介绍通过conanfile.py创建软件包的方法,讲解包名、版本、依赖和构建设置等基础信息,以及source、build、package、package_info等常用方法的作用及编写思路。

40

2026.09.22

Conan二进制包配置指南
Conan二进制包配置指南

本专题介绍Conan根据操作系统、编译器、架构和构建类型生成二进制包的方法,讲解Profile、Settings、Options及Package ID的作用,帮助管理不同平台和编译环境下的包版本。

60

2026.09.22

Conan私有仓库搭建教程
Conan私有仓库搭建教程

本专题系统的讲解Conan私有仓库的搭建流程,涵盖仓库服务部署、存储目录配置、用户认证、权限划分和远程地址添加,并介绍内部C++依赖包的上传、下载及版本维护方法。

60

2026.09.22

loomy官网入口地址合集
loomy官网入口地址合集

本专题汇总了 Loomy 桌面 AI 助理的官方入口地址合集及使用指南。提供 macOS 与 Windows 客户端下载 。Loomy 是讯飞推出的桌面级 AI 工作搭子,支持文件整理、数据分析、网页操作及通过飞书/钉钉远程操控电脑,助你高效完成本地办公任务 。

60

2026.09.22

NumPy常见函数使用方法
NumPy常见函数使用方法

本专题整理 NumPy 常见函数使用方法相关教程,覆盖函数大全、参数用法、数组运算、统计聚合、排序处理、where 条件筛选、linspace 创建数列等常用场景,帮助读者快速掌握 NumPy 函数调用思路和实际数据处理技巧。

80

2026.09.22

NumPy性能优化版本更新与常见报错排查
NumPy性能优化版本更新与常见报错排查

本专题整理 NumPy 性能优化、版本更新与常见报错排查相关教程,覆盖向量化计算、广播性能、内存布局、NumPy 2.0 升级、版本兼容冲突、安装导入报错、dtype 溢出、矩阵运算异常和 broadcasting 报错修复,帮助读者系统掌握 NumPy 性能调优与问题定位方法。

80

2026.09.22

热门下载

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

精品课程

更多
相关推荐
/
热门推荐
/
最新课程
墨刀帮助中心
墨刀帮助中心

共0课时 | 0人学习

MyEclipse学习中心
MyEclipse学习中心

共0课时 | 0人学习

Apache Subversion 官方手册
Apache Subversion 官方手册

共0课时 | 0人学习

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

Copyright 2014-2026 https://www.php.cn/ All Rights Reserved | php.cn