原源码来自 https://github.com/xhgzs/LanzouApi
本站提供的解析地址为:https://www.xiaole88.com/lz.php?url=
如果链接有密码则需要附加pwd=xxx
本源码最后修改日为 2020年9月16日
源码奉上
<?php
/**
* @package Lanzou
* @author iami233
* @version 1.0.0
* @link http://github.com/5ime/Lanzou_api
*/
header ('Access-Control-Allow-Origin:*');
header ('Content-type: application/json');
error_reporting (0);
$url = $_GET['url'];
$pwd = $_GET['pwd'];
$error = curl ($url);
if (strpos ($error, '文件取消分享了') !== false) {
$Json = [
"code" => 201,
"msg" => '文件取消分享了',
];
$Json = json_encode ($Json, JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE);
echo stripslashes ($Json);
return $Json;
} elseif ($url != null) {
if ($pwd == null) {
$b = 'com/';
$c = '/';
$id = GetBetween ($url, $b, $c);
$d = 'https://www.lanzous.com/tp/' . $id;
$lanzouo = curl ($d);
if (strpos ($lanzouo, '输入密码') !== false) {
$Json = [
"code" => 202,
"msg" => '请输入密码',
];
$Json = json_encode ($Json, JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE);
echo stripslashes ($Json);
return $Json;
}
preg_match_all ("/<div class=\"md\">(.*?)<span class=\"mtt\">/", $lanzouo, $name);
preg_match_all ('/时间:<\\/span>(.*?)<span class=\\"mt2\\">/', $lanzouo, $time);
preg_match_all ('/发布者:<\\/span>(.*?)<span class=\\"mt2\\">/', $lanzouo, $author);
preg_match_all ('/var domianload = \'(.*?)\';/', $lanzouo, $down1);
preg_match_all ('/submit\.href = domianload \+ \'(.*?)\'/', $lanzouo, $down2);
preg_match_all ('/var downloads = \'(.*?)\';/', $lanzouo, $down3);
preg_match_all ('/<div class=\\"md\\">(.*?)<span class=\\"mtt\\">\\((.*?)\\)<\\/span><\\/div>/', $lanzouo, $size);
$download = getRedirect ($down1[1][0] . $down2[1][0] . $down3[1][0]);
$Json = [
"code" => 200,
"data" => [
"name" => $name[1][0],
"author" => $author[1][0],
"time" => $time[1][0],
"size" => $size[2][0],
"url" => $download
]
];
$Json = json_encode ($Json, JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE);
echo stripslashes ($Json);
return $Json;
}
} else {
echo '请输入蓝奏云分享的地址,如:';
}
function send_post ($url, $post_data) {
$postdata = http_build_query ($post_data);
$options = [
'http' => [
'method' => 'POST',
'header' => 'Referer: https://www.lanzous.com/\\r\\n' . 'Accept-Language:zh-CN,zh;q=0.9\\r\\n',
'content' => $postdata,
'timeout' => 15 * 60,
]
];
$context = stream_context_create ($options);
$result = file_get_contents ($url, false, $context);
return $result;
}
function curl ($url) {
$header[] = "Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8";
$header[] = "Accept-Encoding: gzip, deflate, sdch, br";
$header[] = "Accept-Language: zh-CN,zh;q=0.8";
$ch = curl_init ();
curl_setopt ($ch, CURLOPT_URL, $url); //设置传输的 url
curl_setopt ($ch, CURLOPT_HTTPHEADER, $header); //发送 http 报头
curl_setopt ($ch, CURLOPT_USERAGENT, "Mozilla/5.0 (iPhone; CPU iPhone OS 6_0 like Mac OS X) AppleWebKit/536.26 (KHTML, like Gecko) Version/6.0 Mobile/10A5376e Safari/8536.25"); //设置UA
curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt ($ch, CURLOPT_ENCODING, 'gzip,deflate'); // 解码压缩文件
curl_setopt ($ch, CURLOPT_SSL_VERIFYPEER, false); // 对认证证书来源的检查
curl_setopt ($ch, CURLOPT_SSL_VERIFYHOST, false); // 从证书中检查SSL加密算法是否存在
curl_setopt ($ch, CURLOPT_TIMEOUT, 5); // 设置超时限制防止死循环
$output = curl_exec ($ch);
curl_close ($ch);
return $output;
}
function GetBetween ($content, $start, $end) {
$r = explode ($start, $content);
if (isset($r[1])) {
$r = explode ($end, $r[1]);
return $r[0];
}
return '';
}
function getRedirect ($url, $ref = '') {
$headers = [
'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',
];
$curl = curl_init ();
curl_setopt ($curl, CURLOPT_URL, $url);
curl_setopt ($curl, CURLOPT_HTTPHEADER, $headers);
if ($ref) {
curl_setopt ($curl, CURLOPT_REFERER, $ref);
}
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"];
}
共 0 条评论