├── .gitattributes
├── LICENSE
├── README.md
└── index.php
/.gitattributes:
--------------------------------------------------------------------------------
1 | # Auto detect text files and perform LF normalization
2 | * text=auto
3 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | MIT License
2 |
3 | Copyright (c) 2018 MHanL
4 |
5 | Permission is hereby granted, free of charge, to any person obtaining a copy
6 | of this software and associated documentation files (the "Software"), to deal
7 | in the Software without restriction, including without limitation the rights
8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 | copies of the Software, and to permit persons to whom the Software is
10 | furnished to do so, subject to the following conditions:
11 |
12 | The above copyright notice and this permission notice shall be included in all
13 | copies or substantial portions of the Software.
14 |
15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21 | SOFTWARE.
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | ## 因调用量过大导致服务器IP被屏蔽,今后不再提供示例站点,请自行搭建相关服务
2 | # LanzouAPI
3 | 下载源码
4 | ## 说明
5 | 1. 支持检测文件是否被取消
6 |
7 | 2. 支持带密码的文件分享链接但不支持分享的文件夹
8 |
9 | 3. 支持生成直链或直接下载
10 |
11 | 4. 增加ios应用在线安装
12 |
13 | 5. 解析最终直链
14 |
15 | 6. 自动识别旧版链接替换为新版并解析
16 |
17 | ## 使用方法
18 |
19 | url:蓝奏云外链链接
20 |
21 | type:是否直接下载 值:down
22 |
23 | pwd:外链密码
24 |
25 | ### 直接下载:
26 |
27 | 无密码:?url=https://www.lanzouq.com/iGNHA6th9cd&type=down
28 |
29 | 有密码:?url=https://www.lanzous.com/i42Xxebssfg&type=down&pwd=1234
30 |
31 |
32 | ### 输出直链:
33 |
34 | 无密码:?url=https://www.lanzouq.com/iGNHA6th9cd
35 |
36 | 有密码:?url=https://www.lanzous.com/i42Xxebssfg&pwd=1234
37 |
38 | ## 反馈
39 | Github或许无法及时回复处理,以下为其余联系方式。
40 |
41 | ### Gmail
42 | hanximeng.com@gmail.com
43 |
44 | ## 本项目仅供学习交流,项目作者不保证其稳定性,如因站点变动导致无法使用继而对作者进行人身攻击,作者可选择随时停更或删除项目。
45 |
--------------------------------------------------------------------------------
/index.php:
--------------------------------------------------------------------------------
1 | 400,
22 | 'msg' => '请输入URL'
23 | )
24 | , JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES)
25 | );
26 | }
27 | //一个简单的链接处理
28 | $url='https://www.lanzoup.com/'.explode('.com/',$url)['1'];
29 | $softInfo = MloocCurlGet($url);
30 | //判断文件链接是否失效
31 | if (strstr($softInfo, "文件取消分享了") != false) {
32 | die(
33 | json_encode(
34 | array(
35 | 'code' => 400,
36 | 'msg' => '文件取消分享了'
37 | )
38 | , JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES)
39 | );
40 | }
41 | //取文件名称、大小
42 | preg_match('~style="font-size: 30px;text-align: center;padding: 56px 0px 20px 0px;">(.*?)~', $softInfo, $softName);
43 | if(!isset($softName[1])) {
44 | preg_match('~
(.*?)
~', $softInfo, $softName);
45 | }
46 | preg_match('~大小:(.*?)
~', $softInfo, $softFilesize);
47 | if(!isset($softFilesize[1])) {
48 | preg_match('~文件大小:(.*?)
~', $softInfo, $softFilesize);
49 | }
50 | if(!isset($softName[1])) {
51 | preg_match('~var filename = \'(.*?)\';~', $softInfo, $softName);
52 | }
53 | if(!isset($softName[1])) {
54 | preg_match('~div class="b">(.*?)~', $softInfo, $softName);
55 | }
56 | //带密码的链接的处理
57 | if(strstr($softInfo, "function down_p(){") != false) {
58 | if(empty($pwd)) {
59 | die(
60 | json_encode(
61 | array(
62 | 'code' => 400,
63 | 'msg' => '请输入分享密码'
64 | )
65 | , JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES)
66 | );
67 | }
68 | preg_match_all("~'sign':'(.*?)',~", $softInfo, $segment);
69 | preg_match_all("~ajaxdata = '(.*?)'~", $softInfo, $signs);
70 | preg_match_all("/ajaxm\.php\?file=(\d+)/", $softInfo, $ajaxm);
71 | $post_data = array(
72 | "action" => "downprocess",
73 | "sign" => $segment[1][1],
74 | "p" => $pwd,
75 | "kd" => 1
76 | );
77 | $softInfo = MloocCurlPost($post_data, "https://www.lanzoup.com/".$ajaxm[0][0], $url);
78 | $softName[1] = json_decode($softInfo,JSON_UNESCAPED_UNICODE)['inf'];
79 | } else {
80 | //不带密码的链接处理
81 | preg_match("~\n "downprocess",
93 | "websignkey" => $signs[1][0],
94 | "signs" => $signs[1][0],
95 | "sign" => $segment[1][0],
96 | "websign" => '',
97 | "kd" => 1,
98 | "ves" => 1
99 | );
100 | $softInfo = MloocCurlPost($post_data, "https://www.lanzoup.com/".$ajaxm[0][1], $ifurl);
101 | }
102 | //其他情况下的信息输出
103 | $softInfo = json_decode($softInfo, true);
104 | if ($softInfo['zt'] != 1) {
105 | die(
106 | json_encode(
107 | array(
108 | 'code' => 400,
109 | 'msg' => $softInfo['inf']
110 | )
111 | , JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES)
112 | );
113 | }
114 | //拼接链接
115 | $downUrl1 = $softInfo['dom'] . '/file/' . $softInfo['url'];
116 | //解析最终直链地址
117 | $downUrl2 = MloocCurlHead($downUrl1,"https://developer.lanzoug.com",$UserAgent,"down_ip=1; expires=Sat, 16-Nov-2019 11:42:54 GMT; path=/; domain=.baidupan.com");
118 | //判断最终链接是否获取成功,如未成功则使用原链接
119 | if(strpos($downUrl2,"http") === false) {
120 | $downUrl = $downUrl1;
121 | } else {
122 | //2025-03-17 新增后缀自定义功能 https://github.com/hanximeng/LanzouAPI/issues/26
123 | if(!empty($_GET['n'])){
124 | preg_match_all("~(.*?)\?fn=(.*?)\\.~", $downUrl2, $rename);
125 | $downUrl = $rename['0']['0'].$_GET['n'];
126 | }else{
127 | $downUrl = $downUrl2;
128 | }
129 | }
130 | //2024-12-03 修复pid参数可能导致的服务器ip地址泄露
131 | $downUrl=preg_replace('/pid=(.*?.)&/', '', $downUrl);
132 | //判断是否是直接下载
133 | if ($type != "down") {
134 | die(
135 | json_encode(
136 | array(
137 | 'code' => 200,
138 | 'msg' => '解析成功',
139 | 'name' => isset($softName[1]) ? $softName[1] : "",
140 | 'filesize' => isset($softFilesize[1]) ? $softFilesize[1] : "",
141 | 'downUrl' => $downUrl
142 | )
143 | , JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES)
144 | );
145 | } else {
146 | header("Location:$downUrl");
147 | die;
148 | }
149 | //获取下载链接函数
150 | function MloocCurlGetDownUrl($url) {
151 | $header = get_headers($url,1);
152 | if(isset($header['Location'])) {
153 | return $header['Location'];
154 | }
155 | return "";
156 | }
157 | //CURL函数
158 | function MloocCurlGet($url = '', $UserAgent = '') {
159 | $curl = curl_init();
160 | curl_setopt($curl, CURLOPT_URL, $url);
161 | curl_setopt($curl, CURLOPT_FOLLOWLOCATION, 1);
162 | if ($UserAgent != "") {
163 | curl_setopt($curl, CURLOPT_USERAGENT, $UserAgent);
164 | }
165 | curl_setopt($curl, CURLOPT_HTTPHEADER, array('X-FORWARDED-FOR:'.Rand_IP(), 'CLIENT-IP:'.Rand_IP()));
166 | #关闭SSL
167 | curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
168 | curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, false);
169 | #返回数据不直接显示
170 | curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
171 | $response = curl_exec($curl);
172 | curl_close($curl);
173 | return $response;
174 | }
175 | //POST函数
176 | function MloocCurlPost($post_data = '', $url = '', $ifurl = '', $UserAgent = '') {
177 | $curl = curl_init();
178 | curl_setopt($curl, CURLOPT_URL, $url);
179 | curl_setopt($curl, CURLOPT_USERAGENT, $UserAgent);
180 | if ($ifurl != '') {
181 | curl_setopt($curl, CURLOPT_REFERER, $ifurl);
182 | }
183 | curl_setopt($curl, CURLOPT_HTTPHEADER, array('X-FORWARDED-FOR:'.Rand_IP(), 'CLIENT-IP:'.Rand_IP()));
184 | #关闭SSL
185 | curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
186 | curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, false);
187 | #返回数据不直接显示
188 | curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
189 | curl_setopt($curl, CURLOPT_POST, 1);
190 | curl_setopt($curl, CURLOPT_POSTFIELDS, $post_data);
191 | $response = curl_exec($curl);
192 | curl_close($curl);
193 | return $response;
194 | }
195 | //直链解析函数
196 | function MloocCurlHead($url,$guise,$UserAgent,$cookie) {
197 | $headers = array(
198 | 'Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8',
199 | 'Accept-Encoding: gzip, deflate',
200 | 'Accept-Language: zh-CN,zh;q=0.9',
201 | 'Cache-Control: no-cache',
202 | 'Connection: keep-alive',
203 | 'Pragma: no-cache',
204 | 'Upgrade-Insecure-Requests: 1',
205 | 'User-Agent: '.$UserAgent
206 | );
207 | $curl = curl_init();
208 | curl_setopt($curl, CURLOPT_URL, $url);
209 | curl_setopt($curl, CURLOPT_HTTPHEADER,$headers);
210 | curl_setopt($curl, CURLOPT_REFERER, $guise);
211 | curl_setopt($curl, CURLOPT_COOKIE , $cookie);
212 | curl_setopt($curl, CURLOPT_USERAGENT, $UserAgent);
213 | curl_setopt($curl, CURLOPT_NOBODY, 0);
214 | curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
215 | curl_setopt($curl, CURLINFO_HEADER_OUT, TRUE);
216 | curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
217 | //超时设置,默认为10秒
218 | curl_setopt($curl, CURLOPT_TIMEOUT, 10);
219 | $data = curl_exec($curl);
220 | $url=curl_getinfo($curl);
221 | curl_close($curl);
222 | return $url["redirect_url"];
223 | }
224 | //随机IP函数
225 | function Rand_IP() {
226 | $ip2id = round(rand(600000, 2550000) / 10000);
227 | $ip3id = round(rand(600000, 2550000) / 10000);
228 | $ip4id = round(rand(600000, 2550000) / 10000);
229 | $arr_1 = array("218","218","66","66","218","218","60","60","202","204","66","66","66","59","61","60","222","221","66","59","60","60","66","218","218","62","63","64","66","66","122","211");
230 | $randarr= mt_rand(0,count($arr_1)-1);
231 | $ip1id = $arr_1[$randarr];
232 | return $ip1id.".".$ip2id.".".$ip3id.".".$ip4id;
233 | }
234 | ?>
235 |
--------------------------------------------------------------------------------