├── D123pan.clsss.php
├── README.md
├── cache
└── index.html
└── index.php
/D123pan.clsss.php:
--------------------------------------------------------------------------------
1 | 0,'info'=>'');
8 | if(empty($url)){$return['info']= '请输入URL';return $return;}
9 | if($this->str_exists($url,'http')){
10 | $urlarr = explode('/',str_replace('.html','',$url));
11 | $shareKey = $urlarr[count($urlarr)-1];
12 | }else{
13 | $shareKey=$url;
14 | }
15 | if($this->cache_time>0){
16 | $cachekey = $shareKey.$pwd;
17 | $cacheresult = $this->cache($cachekey);
18 | if($cacheresult && $cacheresult['expires_time']>time())return $cacheresult['data'];
19 | }
20 | if(empty($pwd)){
21 | $url = 'https://www.123pan.com/s/'.$shareKey.'.html';
22 | $softInfo = $this->curlget($url);
23 | preg_match("~window.g_initialProps(.*?)};~", $softInfo, $segment);
24 | $jsonstr = trim(trim($segment[1]),'=')."}";
25 | $jsonarr = json_decode($jsonstr,1);
26 | if(empty($jsonarr)){$return['info']= '解析错误';return $return;}
27 | if($jsonarr['res']['data']['HasPwd']=='false'){$return['info']= '请输入提取码';return $return;}
28 | $softInfo = $jsonarr['reslist'];
29 | }else{
30 | $url = 'https://www.123pan.com/b/api/share/get?limit=100&next=1&orderBy=share_id&orderDirection=desc&shareKey='.$shareKey.'&SharePwd='.$pwd.'&ParentFileId=0&Page=1';
31 | $softInfo = json_decode($this->curlget($url),true);
32 | if($softInfo['code']>0){
33 | $return['info']= $softInfo['message'];return $return;
34 | }
35 | }
36 | $url = 'https://www.123pan.com/b/api/share/download/info';
37 | $info = $softInfo['data']['InfoList'][0];
38 | $param=array(
39 | 'Etag'=> $info['Etag'],
40 | 'FileID'=> $info['FileId'],
41 | 'S3keyFlag'=> $info['S3KeyFlag'],
42 | 'ShareKey'=> $shareKey,
43 | 'Size'=> $info['Size'],
44 | );
45 | $softInfo = json_decode($this->curlget($url,$param,'POST'),true);
46 | if($softInfo['code']>0){
47 | $return['info']= $softInfo['message'];return $return;
48 | }
49 | $downUrl = $softInfo['data']['DownloadURL'];
50 | if(empty($downUrl)){$return['info']= '获取下载地址失败';return $return;}
51 | $return['status']=1;
52 | $return['info']=$downUrl;
53 | if($this->cache_time>0){
54 | $cacheresult=array();
55 | $cacheresult['data']=$return;
56 | $cacheresult['expires_time']=time()+$this->cache_time;
57 | $this->cache($cachekey,$cacheresult);
58 | }
59 | return $return;
60 | }
61 | public function cache($key,$value='',$time=''){
62 | if(is_array($key))$key=md5(implode('',$key));
63 | $filename=$this->cachepath.$key.'.cache';
64 | if(empty($value)){
65 | $data= @file_get_contents($filename);$this->clearcache();
66 | return json_decode($data,1);
67 | }else{
68 | if(!is_array($value))$value=array($value);
69 | file_put_contents($filename,json_encode($value));
70 | }
71 | }
72 | //清空所有缓存
73 | public function clearcache(){
74 | $cachepath=$this->cachepath;
75 | $date=date('Y-m-d');$cachename='cachetime'.$date.'.c';
76 | if(file_exists($cachepath.$cachename))return false;
77 | foreach(scandir($cachepath) as $fn) {
78 | if(strpos($cachename,'.c')>0)unlink($cachepath.$fn);
79 | }file_put_contents($cachepath.$cachename,'1');
80 | return true;
81 | }
82 | /**
83 | * CURL发送HTTP请求
84 | * @param string $url 请求URL
85 | * @param array $params 请求参数
86 | * @param string $method 请求方法GET/POST
87 | * @param $header 头信息
88 | * @param $multi 是否支付附件
89 | * @param $debug 是否输出错误
90 | * @param $optsother 附件项
91 | * @return array $data 响应数据
92 | */
93 | private function curlget($url, $params='', $method = 'GET', $header = array(), $UserAgent = false,$debug=false,$optsother='') {
94 | if(empty($UserAgent))$UserAgent=$this->UserAgent;
95 | $opts = array(CURLOPT_TIMEOUT => 10,CURLOPT_RETURNTRANSFER=> 1,CURLOPT_SSL_VERIFYPEER=> false,CURLOPT_SSL_VERIFYHOST=> false,CURLOPT_HTTPHEADER => $header,CURLOPT_USERAGENT=>$UserAgent);
96 | switch (strtoupper($method)) {/* 根据请求类型设置特定参数 */
97 | case 'GET':$opts[CURLOPT_URL] = $params?$url.'?'.http_build_query($params):$url;break;
98 | case 'POST':$params = http_build_query($params);//判断是否传输文件
99 | $opts[CURLOPT_URL] = $url;$opts[CURLOPT_POST] = 1;$opts[CURLOPT_POSTFIELDS] = $params;break;
100 | default:if($debug)echo ('不支持的请求方式!');break;
101 | }$ch = curl_init();if($optsother && is_array($optsother))$opts=$opts+$optsother;curl_setopt_array($ch, $opts);$data = curl_exec($ch);$error = curl_error($ch);curl_close($ch);/* 初始化并执行curl请求 */
102 | if($error && $debug){echo ('请求发生错误:'.$error);}
103 | return $data;
104 | }//检测字符串中是否存在
105 | private function str_exists($haystack, $needle){
106 | return !(strpos(''.$haystack, ''.$needle) === FALSE);
107 | }
108 | }
109 | ?>
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # 123云盘直链解析API
2 |
3 | #### 介绍
4 | > 123网盘直链带密码解析 下载地址解析API
5 |
6 | #### 支持的功能
7 | - 123盘直链带密码
8 | - 带密码的文件分享链接但不支持分享的文件夹
9 | - 生成直链或直接下载
10 | - 缓存解析结果(一分钟) 提高解析速度,降低解析频率
11 | - 自定义UserAgent
12 |
13 |
14 | #### 说明
15 |
16 | url:123盘外链链接
17 |
18 | type:是否直接下载 值:down
19 |
20 | pwd:外链密码
21 |
22 | 内部调用方法
23 | ```php
24 | include('D123pan.clsss.php');
25 | $dp = new d123pan;
26 | //$dp->cache_time=60;//设置缓存时间
27 | $res=$dp->getUrl($url,$pwd);
28 | ```
29 | > 注意:`cache`必须给777权限(可写)
30 |
31 | # 使用示例
32 |
33 | > 直接下载
34 |
35 | #### 完整链接
36 |
37 | - 不带提取码:
38 |
39 | http://tool.bitefu.net/123pan/?url=https://www.123pan.com/s/poqA-CFWG3.html&type=down
40 |
41 | http://tool.bitefu.net/123pan/?url=poqA-CFWG3&type=down
42 | - 带提取码:
43 |
44 | http://tool.bitefu.net/123pan/?url=https://www.123pan.com/s/poqA-WFWG3.html&type=down&pwd=6cUF
45 |
46 | http://tool.bitefu.net/123pan/?url=poqA-WFWG3&type=down&pwd=6cUF
47 |
48 | #### 短链接
49 |
50 | - 不带提取码:http://tool.bitefu.net/123pan/?d=poqA-CFWG3
51 |
52 | - 带提取码:http://tool.bitefu.net/123pan/?d=poqA-WFWG3_6cUF
53 |
54 | > 输出直链
55 |
56 | - 不带提取码:
57 |
58 | http://tool.bitefu.net/123pan/?url=https://www.123pan.com/s/poqA-WFWG3.html
59 |
60 | http://tool.bitefu.net/123pan/?url=poqA-WFWG3
61 |
62 | - 带提取码:
63 |
64 | http://tool.bitefu.net/123pan/?url=https://www.123pan.com/s/poqA-WFWG3.html&pwd=6cUF
65 |
66 | http://tool.bitefu.net/123pan/?url=poqA-WFWG3&pwd=6cUF
67 |
68 |
69 | #### 捐助我
70 |
71 | 捐助列表:http://tool.bitefu.net/pay/
72 |
73 |
74 |
--------------------------------------------------------------------------------
/cache/index.html:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Y-ASLant/123pan/044b9e6ea3fd913a9ed19d86bcb4ad74c408fc30/cache/index.html
--------------------------------------------------------------------------------
/index.php:
--------------------------------------------------------------------------------
1 | getUrl($url,$pwd);
12 | if($res['status']==0)ajaxReturn($res);
13 | switch($type){
14 | case "down":
15 | $urlarr = explode('?',$res['info']);parse_str($urlarr[1],$param_arr);
16 | $url = base64_decode($param_arr['params']);
17 | header("Location:".$url);die;
18 | break;
19 | default:
20 | header('Content-Type:application/json; charset=utf-8');
21 | ajaxReturn($res);
22 | break;
23 | }
24 |
25 | function ajaxReturn($array){
26 | $content=json_encode($array,JSON_UNESCAPED_UNICODE);
27 | if(empty($_GET['callback'])){
28 | echo $content;exit;
29 | }else{
30 | echo $_GET['callback']."(".$content.")";exit;
31 | }
32 | }
33 | ?>
--------------------------------------------------------------------------------