吾爱破解 - 52pojie.cn

 找回密码
 注册[Register]

QQ登录

只需一步,快速开始

查看: 4891|回复: 79
收起左侧

[其他原创] 123网盘解析PHP版本

  [复制链接]
sxlixiaoyang 发表于 2023-5-27 19:50
本帖最后由 sxlixiaoyang 于 2023-5-27 20:37 编辑

看到有大佬在论坛上发布了123网盘的解析原理及代码 ,飞机直达: https://www.52pojie.cn/thread-1790395-1-1.html
本人在大佬的基础上,用PHP+html重构了代码(PS:其实是gpt的功劳,自己只是稍加修改了部分代码,话说GPT还是有一点点智障…………)
运行效果请访问URL:点击这里
废话不多说,下面是代码:
[PHP] 纯文本查看 复制代码
<!DOCTYPE html>
<html>
<head>
    <title>123解析</title>
    <style>
        body {
            font-family: "Helvetica Neue", Arial, sans-serif;
            background-color: #f5f5f7;
            margin: 0;
            padding: 0;
            display: flex;
            align-items: center;
            justify-content: center;
            min-height: 100vh;
        }

        .container {
            max-width: 600px;
            padding: 20px;
            box-sizing: border-box;
            text-align: center;
        }

        h1 {
            font-size: 32px;
            font-weight: bold;
            color: #333333;
            margin-bottom: 40px;
            margin-top: 40px;
        }

        form {
            margin-bottom: 40px;
        }

        label {
            display: block;
            font-size: 20px;
            font-weight: bold;
            color: #333333;
            margin-bottom: 10px;
        }

        input[type="text"] {
            width: 100%;
            padding: 12px;
            font-size: 16px;
            border: 1px solid #cccccc;
            box-sizing: border-box;
            margin-bottom: 20px;
        }

        input[type="submit"] {
            padding: 12px 24px;
            font-size: 18px;
            font-weight: bold;
            color: #ffffff;
            background-color: #0070c9;
            border: none;
            cursor: pointer;
        }

        .download-link {
            margin-top: 20px;
            display: flex;
            align-items: center;
            justify-content: center;
        }
      

        .error-icon {
            margin-right: 10px;
            color: #ff0000;
            font-size: 24px;
        }

        .success-icon {
            margin-right: 10px;
            color: #009900;
            font-size: 24px;
        }

        a {
            display: inline-block;
            padding: 12px 24px;
            font-size: 18px;
            font-weight: bold;
            color: #ffffff;
            background-color: #0070c9;
            text-decoration: none;
        }

        a:hover {
            background-color: #0057a0;
        }
    </style>
</head>
<body>
    <div class="container">
        <h1>123解析</h1>
        <form method="post" action="">
            <label for="shareUrl">分享链接:</label>
            <input type="text" id="shareUrl" name="shareUrl" required>
            <input type="submit" name="submit" value="解析">
        </form>

        <?php if(isset($_POST['submit']) && isset($redirectUrl)): ?>
           
        <?php endif; ?>






<?php
if(isset($_POST['submit'])) {
    $shareUrl = $_POST['shareUrl'];
    $shareCode = "";
    $pattern = "/(?<=\/s\/)[^\/.]+/";
    preg_match($pattern, $shareUrl, $match);

    if ($match) {
        $shareId = $match[0];
        $extractCodePattern = "/提取码:(\w+)/";
        preg_match($extractCodePattern, $shareUrl, $extractCodeMatch);

        if ($extractCodeMatch) {
            $shareCode = $extractCodeMatch[1];
        }

        // Get user information
        getInfo($shareId, $shareCode);
    } else {
        echo'<span class="error-icon">&#10007;</span>'. "错误: 123pan URL 未找到!";
    }
}

function getInfo($shareId, $shareCode) {
    $requestUrl = "https://www.123pan.com/b/api/share/get?limit=100&next=1&orderBy=share_id&orderDirection=desc&shareKey=" . $shareId . "&SharePwd=" . $shareCode . "&ParentFileId=0&Page=1";
    $opts = array(
        'http' => array(
            'header' => "User-Agent: Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/109.0.0.0 Safari/537.36 Edg/109.0.1518.100\r\n"
        )
    );
    $context = stream_context_create($opts);
    $responseText = file_get_contents($requestUrl, false, $context);

    parseInfo($responseText, $shareId);
}

function parseInfo($str, $shareId) {
    $data = json_decode($str, true);

    if ($data['code'] == 0) {
        $type = $data['data']['InfoList'][0]['Type'];

        if ($type == 0) {
            $fileId = $data['data']['InfoList'][0]['FileId'];
            $size = $data['data']['InfoList'][0]['Size'];
            $s3KeyFlag = $data['data']['InfoList'][0]['S3KeyFlag'];
            $etag = $data['data']['InfoList'][0]['Etag'];

            // Perform second step
            combinedData($shareId, $fileId, $size, $s3KeyFlag, $etag);
        } else {
            echo "错误: Folder parsing is currently not supported.";
        }
    } else {
        $code = $data['code'];
        $message = $data['message'];
        echo '<span class="error-icon">&#10007;</span>'."错误: 错误码" . $code . "//" . $message;
    }
}

function combinedData($shareId, $fileId, $size, $s3KeyFlag, $etag) {
    $requestUrl = "https://www.123pan.com/b/api/share/download/info";
    $postData = json_encode(array(
        "ShareKey" => $shareId,
        "FileID" => $fileId,
        "S3keyFlag" => $s3KeyFlag,
        "Size" => $size,
        "Etag" => $etag
    ));

    $opts = array(
        'http' => array(
            'header' => "User-Agent: Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/109.0.0.0 Safari/537.36 Edg/109.0.1518.100\r\n" .
                        "Content-Type: application/json;charset=UTF-8\r\n",
            'method' => 'POST',
            'content' => $postData
        )
    );
    $context = stream_context_create($opts);
    $response = file_get_contents($requestUrl, false, $context);

    parseDownloadURL($response);
}

function parseDownloadURL($str) {
    $data = json_decode($str, true);

    if ($data['code'] == 0) {
        $downloadURL = $data['data']['DownloadURL'];
        $downloadURL = extractDownloadLink($downloadURL);
        getDirectLink($downloadURL);
    } else {
        $code = $data['code'];
        $message = $data['message'];
        echo '<span class="error-icon">&#10007;</span>'."错误: 错误码" . $code . "//" . $message;
    }
}

function extractDownloadLink($str) {
    $pattern = "/params=([^&]+)/";
    preg_match($pattern, $str, $match);

    if ($match) {
        $paramsValue = $match[1];
        $decodedString = base64_decode($paramsValue);

        // Check if auto_redirect parameter exists
        if (strpos($decodedString, 'auto_redirect') === false) {
            if (strpos($decodedString, '?') !== false) {
                $decodedString .= "&auto_redirect=0";
            } else {
                $decodedString .= "?auto_redirect=0";
            }
        }

        return $decodedString;
    } else {
        echo "Failed to extract Download URL";
    }
}

function getDirectLink($requestUrl) {
    $opts = array(
        'http' => array(
            'header' => "User-Agent: Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/109.0.0.0 Safari/537.36 Edg/109.0.1518.100\r\n"
        )
    );
    $context = stream_context_create($opts);
    $responseText = file_get_contents($requestUrl, false, $context);

    parseDirectLink($responseText);
}

function parseDirectLink($str) {
    $data = json_decode($str, true);

    if ($data['code'] == 0) {
        $redirectUrl = $data['data']['redirect_url'];
         echo '<span class="success-icon">&#10003;</span><a href="' . $redirectUrl . '">点击下载</a>';
    } else {
        $code = $data['code'];
        $message = $data['message'];
        echo '<span class="error-icon">&#10007;</span>'."错误: 错误码" . $code . "//" . $message;
    }
}
?>
    </div>
</body>
</html>


免费评分

参与人数 4吾爱币 +4 热心值 +3 收起 理由
cntjgaowei + 1 + 1 谢谢@Thanks!
oneai + 1 用心讨论,共获提升!
ardahfy + 1 + 1 我很赞同!
blindcat + 1 + 1 欢迎分析讨论交流,吾爱破解论坛有你更精彩!

查看全部评分

发帖前要善用论坛搜索功能,那里可能会有你要找的答案或者已经有人发布过相同内容了,请勿重复发帖。

midisky 发表于 2023-11-2 18:23
最近123不能idm下载了,想试试你这个会不会有什么新思路,
结果各种错误。

错误: 错误码1//签名错误,请检查您的本地时间是否为东八区时间-platform forbidden
zgjoget 发表于 2023-5-27 20:23
本帖最后由 zgjoget 于 2023-5-27 20:25 编辑
urdarling 发表于 2023-5-27 20:06
他不是可以直接下载码
前几天我下载文件提示要下载客户端才能下载那个文件,但是刚刚又随便点开个下载又能直接下载。
urdarling 发表于 2023-5-27 20:06
blindcat 发表于 2023-5-27 20:20
看看,学习下
 楼主| sxlixiaoyang 发表于 2023-5-27 20:33
本帖最后由 sxlixiaoyang 于 2023-5-27 20:36 编辑
laodan 发表于 2023-5-27 20:30
一样的,现在我写代码喜欢和GPT配合着写,能有不掉头发的方法为啥还要掉头发。

Heroes think a like
fangxiaolong 发表于 2023-5-27 20:36
学习下。。。
abmabmabm 发表于 2023-5-27 20:40
123就经常要别人下载网盘才可以下载,但有时候又不用
mb888 发表于 2023-5-27 20:43
123网盘解析,这个网盘使用的不多,还是支持一下
苏音 发表于 2023-5-27 20:45
谢谢分享,学习了
wsck63304521 发表于 2023-5-27 20:46
123网盘解析PHP版本
您需要登录后才可以回帖 登录 | 注册[Register]

本版积分规则

返回列表

RSS订阅|小黑屋|处罚记录|联系我们|吾爱破解 - LCG - LSG ( 京ICP备16042023号 | 京公网安备 11010502030087号 )

GMT+8, 2024-11-24 12:46

Powered by Discuz!

Copyright © 2001-2020, Tencent Cloud.

快速回复 返回顶部 返回列表