PHP蓝奏云直链解析源码

使用说明

支持链接

  • www.lanzous.com
  • www.lanzoui.com
  • 随机二级.lanzous.com
  • 随机二级.lanzoui.com

请求示例

无密码:https://tenapi.cn/lanzou/?url=https://www.lanzous.com/i8fclgh

有密码:https://tenapi.cn/lanzou/?url=https://www.lanzous.com/itahfehy1bc&pwd=d17u

返回数据

{
  "code": 200,
  "data": {
    "name": "智云影音V3.7.3.3清爽特别版.apk ",
    "author": "智云** ",
    "time": "2020-01-03 ",
    "size": " 7.9 M ",
    "url": "https://developer78.baidupan.com/082015bb/2020/01/03/9bb45993f98d785a0775754236a8a451.apk?st=CGGAhiMMwQ2Yqzzww1YO7Q&e=1597909079&b=VOAKkwmzVbRYtwPEVuNT6gPnDLkGmAC1VVBfYVx1VmMEeFppV3kCNAKxB_blQhQfkUYwB4FawUN8C6A3lAo1W_a1ThCoMJgVV_bWGwDJVZt&fi=15880697&pid=13-70-23-99&up="
  }
}

Github:https://github.com/5ime/Lanzou_api

代码

<?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 = array(
    "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 = array(
            "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 domianloads = '(.*?)';/', $lanzouo, $down1);
        preg_match_all('/var urlload = '(.*?)';/', $lanzouo, $down2);
        preg_match_all('/<div class=\"md\">(.*?)<span class=\"mtt\">\((.*?)\)<\/span><\/div>/', $lanzouo, $size);
        $download = getRedirect($down1[1][0] . $down2[1][0]);
        $Json = array(
            "code" => 200, 
            "data" => array(
                "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;
    }
    $b = 'com/';
    $c = '/';
    $id = GetBetween($url, $b, $c);
    $d = 'https://www.lanzous.com/tp/' . $id;
    $lanzouo = curl($d);
    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('/<div class=\"md\">(.*?)<span class=\"mtt\">\((.*?)\)<\/span><\/div>/', $lanzouo, $size);
    preg_match_all('/sign':'(.*?)'/', $lanzouo, $sign);
    $post_data = array('action' => 'downprocess', 'sign' => $sign[1][0], 'p' => $pwd);
    $pwdurl = send_post('https://wwa.lanzous.com/ajaxm.php', $post_data);
    if(strpos($pwdurl,'"zt":0') !== false) {
        $Json = array(
        "code" => 202, 
        "msg" => '密码不正确',
        );
    $Json = json_encode($Json, JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE);
    echo stripslashes($Json);
    return $Json;
    }
    $obj = json_decode($pwdurl, true);
    $download = getRedirect($obj['dom'] . '/file/' . $obj['url']);
    $Json = array(
        "code" => 200, 
        "data" => array(
            "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 '请输入蓝奏云分享的地址,如:https://www.lanzous.com/i8fclgh';
}
function send_post($url, $post_data)
{
    $postdata = http_build_query($post_data);
    $options = array('http' => array(
        '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 = 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',
        );
        $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"];
    }

人已赞赏
各类代码

代码实现微信公众号网页授权登录 获取用户基本信息(头像/昵称/openid)

2020-9-1 20:44:06

谈天说地

www 和 https:// 被Chrome地址栏隐藏了

2019-11-10 11:42:41

0 条回复 A文章作者 M管理员
    暂无讨论,说说你的看法吧
个人中心
购物车
优惠劵
今日签到
有新私信 私信列表
搜索