项目简介
蓝奏云是国内常用的免费网盘,但分享链接需要跳转多次才能下载。本项目通过 PHP 接口自动解析蓝奏云分享链接,提取文件直链地址,实现一步到位的下载体验。
主要功能:
- 解析蓝奏云分享链接,返回文件直链
- 支持带密码的分享链接
- 支持直接跳转下载(
type=down) - QQ / 微信 / 支付宝内置浏览器自动引导外部打开
- 随机 IP 伪装,降低被限频风险
接口参数
| 参数 | 必填 | 说明 |
|---|---|---|
url | 是 | 蓝奏云分享链接 |
pwd | 否 | 分享密码(加密文件必填) |
type | 否 | 填 down 则直接 302 跳转下载 |
n | 否 | 自定义下载文件名后缀 |
调用示例
获取直链信息(JSON):
GET https://your-domain.com/?url=https://wwbvd.lanzn.com/ig1uE3lma4zg&pwd=fstj
返回格式:
{
"code": 200,
"msg": "解析成功",
"name": "文件名.apk",
"filesize": "15.6 M",
"downUrl": "https://xxx.com/file/xxx"
}
直接下载(302 跳转):
GET https://your-domain.com/?url=https://wwbvd.lanzn.com/ig1uE3lma4zg&type=down&pwd=fstj
完整源码
<?php
/**
* @package Lanzou
* @author Filmy,hanximeng
* @version 1.3.103
* @Date 2025-09-28
* @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';
//防红:检测QQ、微信、支付宝内置浏览器,引导用户使用外部浏览器打开
$ua = $_SERVER['HTTP_USER_AGENT'] ?? '';
if (preg_match('/MicroMessenger|QQ\/|MQQBrowser|AlipayClient/i', $ua)) {
header('Content-Type:text/html; charset=utf-8');
die('<!DOCTYPE html><html><head><meta charset="utf-8"><meta name="viewport" content="width=device-width,initial-scale=1"><title>请在浏览器中打开</title></head><body><p>请在浏览器中打开此链接</p></body></html>');
}
$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.lanzouf.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);
}
if(!isset($softName[1])) {
preg_match('~div class="b"><span>(.*?)</span></div>~', $softInfo, $softName);
}
//带密码的链接的处理
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_all("~'sign':'(.*?)',~", $softInfo, $segment);
preg_match_all("~ajaxdata = '(.*?)'~", $softInfo, $signs);
preg_match_all("/ajaxm\.php\?file=(\d+)/", $softInfo, $ajaxm);
$post_data = array(
"action" => "downprocess",
"sign" => $segment[1][1],
"p" => $pwd,
"kd" => 1
);
$softInfo = MloocCurlPost($post_data, "https://www.lanzouf.com/".$ajaxm[0][0], $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.lanzouf.com/" . $link[1];
$softInfo = MloocCurlGet($ifurl);
preg_match_all("~wp_sign = '(.*?)'~", $softInfo, $segment);
preg_match_all("~ajaxdata = '(.*?)'~", $softInfo, $signs);
preg_match_all("/ajaxm\.php\?file=(\d+)/", $softInfo, $ajaxm);
$post_data = array(
"action" => "downprocess",
"websignkey" => $signs[1][0],
"signs" => $signs[1][0],
"sign" => $segment[1][0],
"websign" => '',
"kd" => 1,
"ves" => 1
);
$softInfo = MloocCurlPost($post_data, "https://www.lanzouf.com/".$ajaxm[0][1], $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'];
//cookie生成
$softInfo=MloocCurlGet($downUrl1);
preg_match_all("~arg1='(.*?)'~", $softInfo, $arg);
$decrypted = acw_sc_v2_simple($arg["1"]["0"]);
//解析最终直链地址
$downUrl2 = MloocCurlHead($downUrl1,"https://developer.lanzoug.com",$UserAgent,"down_ip=1; expires=Sat, 16-Nov-2019 11:42:54 GMT; path=/; domain=.baidupan.com;acw_sc__v2=".$decrypted);
//判断最终链接是否获取成功,如未成功则使用原链接
if(strpos($downUrl2,"http") === false) {
$downUrl = $downUrl1;
} else {
//后缀自定义功能
if(!empty($_GET['n'])){
preg_match_all("~(.*?)\?fn=(.*?)\\.~", $downUrl2, $rename);
$downUrl = $rename['0']['0'].$_GET['n'];
}else{
$downUrl = $downUrl2;
}
}
//修复pid参数可能导致的服务器ip地址泄露
$downUrl=preg_replace('/pid=(.*?.)&/', '', $downUrl);
//判断是否是直接下载
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;
}
//CURL GET函数
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()));
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($curl, CURLOPT_ENCODING, 'gzip');
curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, false);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
$response = curl_exec($curl);
curl_close($curl);
return $response;
}
//CURL 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()));
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);
curl_setopt($curl, CURLOPT_TIMEOUT, 10);
$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;
}
//cookie生成函数
function acw_sc_v2_simple($arg1) {
$posList = [15,35,29,24,33,16,1,38,10,9,19,31,40,27,22,23,25,13,6,11,39,18,20,8,14,21,32,26,2,30,7,4,17,5,3,28,34,37,12,36];
$mask = '3000176000856006061501533003690027800375';
$outPutList = array_fill(0, 40, '');
for ($i = 0; $i < strlen($arg1); $i++) {
$char = $arg1[$i];
foreach ($posList as $j => $pos) {
if ($pos == $i + 1) {
$outPutList[$j] = $char;
}
}
}
$arg2 = implode('', $outPutList);
$result = '';
$length = min(strlen($arg2), strlen($mask));
for ($i = 0; $i < $length; $i += 2) {
$strHex = substr($arg2, $i, 2);
$maskHex = substr($mask, $i, 2);
$xorResult = dechex(hexdec($strHex) ^ hexdec($maskHex));
$result .= str_pad($xorResult, 2, '0', STR_PAD_LEFT);
}
return $result;
}
?>
部署方式
- 将
index.php上传到支持 PHP 的服务器(需开启curl扩展) - 确保服务器能访问外网(需请求蓝奏云域名)
- 访问
https://your-domain.com/?url=蓝奏云链接即可使用
Nginx 伪静态:打造干净的下载直链
实际使用中,把一长串 API 链接发给用户体验很差。通过 Nginx 伪静态,可以把下载地址伪装成一个简洁的文件链接:
location = /113.apk {
return 301 /lanzou/?url=https://wwbvd.lanzn.com/ig1uE3lma4zg&type=down&pwd=fstj;
}
这样用户访问 https://your-domain.com/113.apk 就会自动解析并跳转下载,看起来就像在直接下载一个文件。
你可以为每个文件配置一条规则,管理多个下载链接:
# 应用下载
location = /app.apk {
return 301 /lanzou/?url=https://xxxx.lanzn.com/xxxxx&type=down&pwd=xxxx;
}
# 工具下载
location = /tool.exe {
return 301 /lanzou/?url=https://xxxx.lanzn.com/xxxxx&type=down;
}
适合用来做软件分发、资源下载页等场景。
注意事项
- 蓝奏云页面结构可能更新,正则规则需要跟着调整
- 接口仅供个人学习使用,请勿用于商业用途
- 建议部署在国内服务器,访问蓝奏云速度更快