forked from hanximeng/LanzouAPI
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.php
250 lines (250 loc) · 8.61 KB
/
index.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
<?php
/**
* @package Lanzou
* @author Filmy,hanximeng
* @version 1.2.91
* @Date 2022-08-24
* @link https://hanximeng.com
*/
header('Access-Control-Allow-Origin:*');
header('Content-Type:application/json; charset=utf-8');
//默认UA
$UserAgent = 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/72.0.3626.121 Safari/537.36';
$url = isset($_GET['url']) ? $_GET['url'] : "";
$pwd = isset($_GET['pwd']) ? $_GET['pwd'] : "";
$type = isset($_GET['type']) ? $_GET['type'] : "";
//判断传入链接参数是否为空
if (empty($url)) {
die(
json_encode(
array(
'code' => 400,
'msg' => '请输入URL'
)
, JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES)
);
}
//一个简单的链接处理
$url='https://www.lanzouy.com/'.explode('.com/',$url)['1'];
$softInfo = MloocCurlGet($url);
//判断文件链接是否失效
if (strstr($softInfo, "文件取消分享了") != false) {
die(
json_encode(
array(
'code' => 400,
'msg' => '文件取消分享了'
)
, JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES)
);
}
//取文件名称、大小
preg_match('~style="font-size: 30px;text-align: center;padding: 56px 0px 20px 0px;">(.*?)</div>~', $softInfo, $softName);
if(!isset($softName[1])) {
preg_match('~<div class="n_box_3fn".*?>(.*?)</div>~', $softInfo, $softName);
}
preg_match('~<div class="n_filesize".*?>大小:(.*?)</div>~', $softInfo, $softFilesize);
if(!isset($softFilesize[1])) {
preg_match('~<span class="p7">文件大小:</span>(.*?)<br>~', $softInfo, $softFilesize);
}
if(!isset($softName[1])) {
preg_match('~var filename = \'(.*?)\';~', $softInfo, $softName);
}
//判断文件是否是IOS的安装包
if (strstr($softInfo, "手机Safari可在线安装") != false) {
if(strstr($softInfo, "n_file_infos") != false) {
$ipaInfo = MloocCurlGet($url, 'Mozilla/5.0 (iPhone; CPU iPhone OS 10_3_1 like Mac OS X) AppleWebKit/603.1.30 (KHTML, like Gecko) Version/10.0 Mobile/14E304 Safari/602.1');
preg_match('~href="(.*?)" target="_blank" class="appa"~', $ipaInfo, $ipaDownUrl);
} else {
preg_match('~com/(\w+)~', $url, $lanzouId);
if (!isset($lanzouId[1])) {
die(
json_encode(
array(
'code' => 400,
'msg' => '解析失败,获取不到文件ID'
)
, JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES)
);
}
$lanzouId = $lanzouId[1];
$ipaInfo = MloocCurlGet("https://www.lanzouy.com/tp/" . $lanzouId, 'Mozilla/5.0 (iPhone; CPU iPhone OS 10_3_1 like Mac OS X) AppleWebKit/603.1.30 (KHTML, like Gecko) Version/10.0 Mobile/14E304 Safari/602.1');
preg_match("~nmousedows = '(.*?)'~", $ipaInfo, $ipaDownUrl);
}
$ipaDownUrl = isset($ipaDownUrl[1]) ? $ipaDownUrl[1] : "";
if ($type != "down") {
die(
json_encode(
array(
'code' => 200,
'msg' => '解析成功',
'name' => isset($softName[1]) ? $softName[1] : "",
'downUrl' => $ipaDownUrl
)
, JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES)
);
} else {
header("Location:$ipaDownUrl");
die;
}
}
//带密码的链接的处理
if(strstr($softInfo, "function down_p(){") != false) {
if(empty($pwd)) {
die(
json_encode(
array(
'code' => 400,
'msg' => '请输入分享密码'
)
, JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES)
);
}
preg_match("~action=(.*?)&sign=(.*?)&p='\+(.*?),~", $softInfo, $segment);
$post_data = array(
"action" => $segment[1],
"sign" => $segment[2],
"p" => $pwd
);
$softInfo = MloocCurlPost($post_data, "https://www.lanzouy.com/ajaxm.php", $url);
$softName[1] = json_decode($softInfo,JSON_UNESCAPED_UNICODE)['inf'];
} else {
//不带密码的链接处理
preg_match("~\n<iframe.*?name=\"[\s\S]*?\"\ssrc=\"\/(.*?)\"~", $softInfo, $link);
//蓝奏云新版页面正则规则
if(empty($link[1])) {
preg_match("~<iframe.*?name=\"[\s\S]*?\"\ssrc=\"\/(.*?)\"~", $softInfo, $link);
}
$ifurl = "https://www.lanzouy.com/" . $link[1];
$softInfo = MloocCurlGet($ifurl);
preg_match_all("~sign = '(.*?)'~", $softInfo, $segment);
$post_data = array(
"action" => 'downprocess',
"signs"=>"?ctdf",
"sign" => $segment[1][0],
);
$softInfo = MloocCurlPost($post_data, "https://www.lanzouy.com/ajaxm.php", $ifurl);
}
//其他情况下的信息输出
$softInfo = json_decode($softInfo, true);
if ($softInfo['zt'] != 1) {
die(
json_encode(
array(
'code' => 400,
'msg' => $softInfo['inf']
)
, JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES)
);
}
//拼接链接
$downUrl1 = $softInfo['dom'] . '/file/' . $softInfo['url'];
//解析最终直链地址
$downUrl2 = MloocCurlHead($downUrl1,"http://developer.store.pujirc.com",$UserAgent,"down_ip=1; expires=Sat, 16-Nov-2019 11:42:54 GMT; path=/; domain=.baidupan.com");
//判断最终链接是否获取成功,如未成功则使用原链接
if($downUrl2 == "") {
$downUrl = $downUrl1;
} else {
$downUrl = $downUrl2;
}
//判断是否是直接下载
if ($type != "down") {
die(
json_encode(
array(
'code' => 200,
'msg' => '解析成功',
'name' => isset($softName[1]) ? $softName[1] : "",
'filesize' => isset($softFilesize[1]) ? $softFilesize[1] : "",
'downUrl' => $downUrl
)
, JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES)
);
} else {
header("Location:$downUrl");
die;
}
//获取下载链接函数
function MloocCurlGetDownUrl($url) {
$header = get_headers($url,1);
if(isset($header['Location'])) {
return $header['Location'];
}
return "";
}
//CURL函数
function MloocCurlGet($url = '', $UserAgent = '') {
$curl = curl_init();
curl_setopt($curl, CURLOPT_URL, $url);
curl_setopt($curl, CURLOPT_FOLLOWLOCATION, 1);
if ($UserAgent != "") {
curl_setopt($curl, CURLOPT_USERAGENT, $UserAgent);
}
curl_setopt($curl, CURLOPT_HTTPHEADER, array('X-FORWARDED-FOR:'.Rand_IP(), 'CLIENT-IP:'.Rand_IP()));
#关闭SSL
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, false);
#返回数据不直接显示
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
$response = curl_exec($curl);
curl_close($curl);
return $response;
}
//POST函数
function MloocCurlPost($post_data = '', $url = '', $ifurl = '', $UserAgent = '') {
$curl = curl_init();
curl_setopt($curl, CURLOPT_URL, $url);
curl_setopt($curl, CURLOPT_USERAGENT, $UserAgent);
if ($ifurl != '') {
curl_setopt($curl, CURLOPT_REFERER, $ifurl);
}
curl_setopt($curl, CURLOPT_HTTPHEADER, array('X-FORWARDED-FOR:'.Rand_IP(), 'CLIENT-IP:'.Rand_IP()));
#关闭SSL
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, false);
#返回数据不直接显示
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($curl, CURLOPT_POST, 1);
curl_setopt($curl, CURLOPT_POSTFIELDS, $post_data);
$response = curl_exec($curl);
curl_close($curl);
return $response;
}
//直链解析函数
function MloocCurlHead($url,$guise,$UserAgent,$cookie) {
$headers = array(
'Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8',
'Accept-Encoding: gzip, deflate',
'Accept-Language: zh-CN,zh;q=0.9',
'Cache-Control: no-cache',
'Connection: keep-alive',
'Pragma: no-cache',
'Upgrade-Insecure-Requests: 1',
'User-Agent: '.$UserAgent
);
$curl = curl_init();
curl_setopt($curl, CURLOPT_URL, $url);
curl_setopt($curl, CURLOPT_HTTPHEADER,$headers);
curl_setopt($curl, CURLOPT_REFERER, $guise);
curl_setopt($curl, CURLOPT_COOKIE , $cookie);
curl_setopt($curl, CURLOPT_USERAGENT, $UserAgent);
curl_setopt($curl, CURLOPT_NOBODY, 0);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($curl, CURLINFO_HEADER_OUT, TRUE);
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
$data = curl_exec($curl);
$url=curl_getinfo($curl);
curl_close($curl);
return $url["redirect_url"];
}
//随机IP函数
function Rand_IP() {
$ip2id = round(rand(600000, 2550000) / 10000);
$ip3id = round(rand(600000, 2550000) / 10000);
$ip4id = round(rand(600000, 2550000) / 10000);
$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");
$randarr= mt_rand(0,count($arr_1)-1);
$ip1id = $arr_1[$randarr];
return $ip1id.".".$ip2id.".".$ip3id.".".$ip4id;
}
?>