【更新】php获取蓝奏真实直链
LanzouAPI
说明
1.支持检测文件是否被取消
2.支持带密码的文件分享链接但不支持分享的文件夹
3.支持生成直链或直接下载
4.转载或使用请保留版权!!
今日看lz分享链接的时候,页面源码内发布了这个文章,今日起,就不再更新了,知悉!https://www.toutiao.com/a6750138907435745803/
食用方法
url:蓝奏云外链链接
type:是否直接下载 -> 值:down
pwd:外链密码 -> 链接结尾加 &pwd=密码
演示
看这里!看这里!看这里!!!
不知道该说什么,转自上一篇
[post cid="336" /]
更新内容
不晓得。。。
多了真实链接地址???
一脸懵bb。2019.6.13:修复一处bug
2019.6.13.2:修复带密码分享获取直链失败
2019.7.18:获取返回null的可以注释掉代理ip或者更换即可
2019.10.8:修复返回400错误,国外服务器请自行解除代理封印。偶尔遇到400抽风请多刷新两次,如果还是凉凉,欢迎留言。
2019.12.3:修复自定义链接无法获取地址,其他问题欢迎留言
2019.12.17:修复无法获取地址,其他问题欢迎留言
2019.12.24:最后一波,以后自己动手抓吧
注意事项
由于蓝奏云限制国外服务器无法获取
所以只能使用curl进行代理访问,但是因为代理的ip不是经常有效,所以这里提供一个获取免费代理的地址
怎么修改的话你就看代码那个ip和端口就行了~~
~~如果你是国内用户,可以免代理访问,但需要手动在$ip和$ip_port前面注释掉
免费代理地址
源代码
<?php
/**
* @package Lanzou
* @author Filmy & andy & 不知名的玩家
* @version 1.3.2
* @link https://mlooc.cn & http://lsland.cn
*/
header('Access-Control-Allow-Origin:*');
header('Content-Type:application/json; charset=utf-8');
$header = [
'X-FORWARDED-FOR:182.140.245.39:443',
'CLIENT-IP:182.140.245.39:443',
'Cookie: sec_tc=AQAAAHZM7QcZrQoAi82Dx4i2cPi2O5MD; pc_ad1=1; UM_distinctid=16f11aaa8ac3b3-04b9ec524cd244-43450521-1aeaa0-16f11aaa8ae7b8; CNZZDATA5288474=cnzz_eid%3D141190898-1576548831-%26ntime%3D1576548831; CNZZDATA1253610888=372794536-1576548556-%7C1576548556'
];
function CurlGet($url, $UserAgent = 'Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/69.0.3497.100 Safari/537.36')
{
global $header;
$curl = curl_init();
curl_setopt($curl, CURLOPT_URL, $url);
curl_setopt($curl, CURLOPT_HTTPHEADER, $header); //伪造IP
curl_setopt($curl, CURLOPT_REFERER, 'https://www.lanzous.com');
curl_setopt($curl, CURLOPT_COOKIE, $cookie);
curl_setopt($curl, CURLOPT_FOLLOWLOCATION, 1);
if ($UserAgent != "") {
curl_setopt($curl, CURLOPT_USERAGENT, $UserAgent);
}
#关闭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;
}
function CurlPost($post_data, $url, $ifurl, $UserAgent = 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/71.0.3578.10 Safari/537.36')
{
global $header;
$curl = curl_init();
curl_setopt($curl, CURLOPT_URL, $url);
curl_setopt($curl, CURLOPT_HTTPHEADER, $header); //伪造IP
curl_setopt($curl, CURLOPT_USERAGENT, $UserAgent);
if ($ifurl != '') {
curl_setopt($curl, CURLOPT_REFERER, $ifurl);
}
#关闭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 CurlGetRealUrl($url)
{
$curl = curl_init();
$header = array(
'Host:vip.d0.baidupan.com',
'Connection:keep-alive',
'Upgrade-Insecure-Requests:1',
'User-Agent:Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/71.0.3578.10 Safari/537.36',
'Accept:text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8',
'Accept-Encoding:gzip, deflate, br',
'Accept-Language:zh-CN,zh;q=0.9'
);
curl_setopt($curl, CURLOPT_URL, $url);
curl_setopt($curl, CURLOPT_REFERER, 'https://www.lanzous.com');
//设置头文件的信息作为数据流输出
curl_setopt($curl, CURLOPT_HEADER, true);
//设置获取的信息以文件流的形式返回,而不是直接输出。
curl_setopt($curl,CURLOPT_HTTPHEADER,$header);
curl_setopt($curl, CURLOPT_FOLLOWLOCATION, 0);
#关闭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."end";
}
$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)
);
}
$softInfo = CurlGet($url);
if (strstr($softInfo, "文件取消分享了") != false) {
die(
json_encode(
array(
'code' => 400,
'msg' => '文件取消分享了'
)
, JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES)
);
}
preg_match('~class="b">(.*?)<\/div>~', $softInfo, $softName);
if (strstr($softInfo, "手机Safari可在线安装") != false) {
if(strstr($softInfo, "n_file_infos") != false){
$ipaInfo = CurlGet($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 = CurlGet("https://www.lanzous.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('~href="(.*?)" id="plist"~', $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($pwd){
$ifurl = "https://www.lanzous.com/";
}else{
preg_match_all('~<iframe.*?name="(.*?)" src="(.*?)" frameborder="[\s\S]*?" scrolling="~', $softInfo, $link);
$nameId = $link[1][0];
if($nameId == 1){
$link = $link[2][1];
}else{
$link = $link[2][0];
}
$ifurl = "https://www.lanzous.com/" . $link;
$softInfo = CurlGet($ifurl);
}
if (empty($pwd) && strstr($softInfo, "输入密码") != false) {
die(
json_encode(
array(
'code' => 400,
'msg' => '请输入分享密码'
)
, JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES)
);
}
if($pwd){
preg_match("~'action=(.*?)&sign=(.*?)&p=~", $softInfo, $segment);
$post_data = array(
"action" => $segment[1],
"sign" => $segment[2],
"p" => $pwd,
);
}else{
preg_match_all("~[\s\S]*?:'(.*?)',[\s\S]*?:'(.*?)'~", $softInfo, $segment);
$post_data = array(
"action" => $segment[1][1],
"sign" => $segment[2][2],
);
}
$softInfo = CurlPost($post_data, "https://www.lanzous.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)
);
}
$downUrl = $softInfo['dom'] . '/file/' . str_replace('\/','/',$softInfo['url']);
preg_match('~Location: (.*?)[\s\S]*?end~',CurlGetRealUrl($downUrl),$real_url);
$real_url = trim(str_replace(array('Location:','/r/n','/r','/n','end'),'',$real_url[0]));
if ($type != "down") {
die(
json_encode(
array(
'code' => 200,
'msg' => '此api仅供于学习!',
'name' => isset($softName[1]) ? str_replace(array("<span>","</span>"),'',$softName[1]) : $softInfo['inf'],
'downUrl' => $real_url
)
, JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES)
);
} else {
header("Location:$real_url");
die;
}
?>