网盛资源- 最新刷机包,救砖解锁,刷机工具教程,免费下载,安卓免费APP下载,源码资源,破解软件资源,辅助游戏工具

 找回密码
 立即注册
搜索
热搜: 活动 交友 discuz
查看: 10889|回复: 1

解析123网盘链接 – PHP代码分享

[复制链接]

1万

主题

6395

帖子

4万

积分

管理员

Rank: 9Rank: 9Rank: 9

积分
49067
发表于 2023-6-29 20:03:05 | 显示全部楼层 |阅读模式
d2b5ca33bd094117.png

将下面代码新建成index.php保存即可。
  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4.     <title>123解析</title>
  5.     <style>
  6.         body {
  7.             font-family: "Helvetica Neue", Arial, sans-serif;
  8.             background-color: #f5f5f7;
  9.             margin: 0;
  10.             padding: 0;
  11.             display: flex;
  12.             align-items: center;
  13.             justify-content: center;
  14.             min-height: 100vh;
  15.         }

  16.         .container {
  17.             max-width: 600px;
  18.             padding: 20px;
  19.             box-sizing: border-box;
  20.             text-align: center;
  21.         }

  22.         h1 {
  23.             font-size: 32px;
  24.             font-weight: bold;
  25.             color: #333333;
  26.             margin-bottom: 40px;
  27.             margin-top: 40px;
  28.         }

  29.         form {
  30.             margin-bottom: 40px;
  31.         }

  32.         label {
  33.             display: block;
  34.             font-size: 20px;
  35.             font-weight: bold;
  36.             color: #333333;
  37.             margin-bottom: 10px;
  38.         }

  39.         input[type="text"] {
  40.             width: 100%;
  41.             padding: 12px;
  42.             font-size: 16px;
  43.             border: 1px solid #cccccc;
  44.             box-sizing: border-box;
  45.             margin-bottom: 20px;
  46.         }

  47.         input[type="submit"] {
  48.             padding: 12px 24px;
  49.             font-size: 18px;
  50.             font-weight: bold;
  51.             color: #ffffff;
  52.             background-color: #0070c9;
  53.             border: none;
  54.             cursor: pointer;
  55.         }

  56.         .download-link {
  57.             margin-top: 20px;
  58.             display: flex;
  59.             align-items: center;
  60.             justify-content: center;
  61.         }
  62.       

  63.         .error-icon {
  64.             margin-right: 10px;
  65.             color: #ff0000;
  66.             font-size: 24px;
  67.         }

  68.         .success-icon {
  69.             margin-right: 10px;
  70.             color: #009900;
  71.             font-size: 24px;
  72.         }

  73.         a {
  74.             display: inline-block;
  75.             padding: 12px 24px;
  76.             font-size: 18px;
  77.             font-weight: bold;
  78.             color: #ffffff;
  79.             background-color: #0070c9;
  80.             text-decoration: none;
  81.         }

  82.         a:hover {
  83.             background-color: #0057a0;
  84.         }
  85.     </style>
  86. </head>
  87. <body>
  88.     <div class="container">
  89.         <h1>123解析</h1>
  90.         <form method="post" action="">
  91.             <label for="shareUrl">分享链接:</label>
  92.             <input type="text" id="shareUrl" name="shareUrl" required>
  93.             <input type="submit" name="submit" value="解析">
  94.         </form>

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






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

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

  108.         if ($extractCodeMatch) {
  109.             $shareCode = $extractCodeMatch[1];
  110.         }

  111.         // Get user information
  112.         getInfo($shareId, $shareCode);
  113.     } else {
  114.         echo'<span class="error-icon">✗</span>'. "错误: 123pan URL 未找到!";
  115.     }
  116. }

  117. function getInfo($shareId, $shareCode) {
  118.     $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";
  119.     $opts = array(
  120.         'http' => array(
  121.             '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"
  122.         )
  123.     );
  124.     $context = stream_context_create($opts);
  125.     $responseText = file_get_contents($requestUrl, false, $context);

  126.     parseInfo($responseText, $shareId);
  127. }

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

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

  132.         if ($type == 0) {
  133.             $fileId = $data['data']['InfoList'][0]['FileId'];
  134.             $size = $data['data']['InfoList'][0]['Size'];
  135.             $s3KeyFlag = $data['data']['InfoList'][0]['S3KeyFlag'];
  136.             $etag = $data['data']['InfoList'][0]['Etag'];

  137.             // Perform second step
  138.             combinedData($shareId, $fileId, $size, $s3KeyFlag, $etag);
  139.         } else {
  140.             echo "错误: Folder parsing is currently not supported.";
  141.         }
  142.     } else {
  143.         $code = $data['code'];
  144.         $message = $data['message'];
  145.         echo '<span class="error-icon">✗</span>'."错误: 错误码" . $code . "//" . $message;
  146.     }
  147. }

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

  157.     $opts = array(
  158.         'http' => array(
  159.             '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" .
  160.                         "Content-Type: application/json;charset=UTF-8\r\n",
  161.             'method' => 'POST',
  162.             'content' => $postData
  163.         )
  164.     );
  165.     $context = stream_context_create($opts);
  166.     $response = file_get_contents($requestUrl, false, $context);

  167.     parseDownloadURL($response);
  168. }

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

  171.     if ($data['code'] == 0) {
  172.         $downloadURL = $data['data']['DownloadURL'];
  173.         $downloadURL = extractDownloadLink($downloadURL);
  174.         getDirectLink($downloadURL);
  175.     } else {
  176.         $code = $data['code'];
  177.         $message = $data['message'];
  178.         echo '<span class="error-icon">✗</span>'."错误: 错误码" . $code . "//" . $message;
  179.     }
  180. }

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

  184.     if ($match) {
  185.         $paramsValue = $match[1];
  186.         $decodedString = base64_decode($paramsValue);

  187.         // Check if auto_redirect parameter exists
  188.         if (strpos($decodedString, 'auto_redirect') === false) {
  189.             if (strpos($decodedString, '?') !== false) {
  190.                 $decodedString .= "&auto_redirect=0";
  191.             } else {
  192.                 $decodedString .= "?auto_redirect=0";
  193.             }
  194.         }

  195.         return $decodedString;
  196.     } else {
  197.         echo "Failed to extract Download URL";
  198.     }
  199. }

  200. function getDirectLink($requestUrl) {
  201.     $opts = array(
  202.         'http' => array(
  203.             '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"
  204.         )
  205.     );
  206.     $context = stream_context_create($opts);
  207.     $responseText = file_get_contents($requestUrl, false, $context);

  208.     parseDirectLink($responseText);
  209. }

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

  212.     if ($data['code'] == 0) {
  213.         $redirectUrl = $data['data']['redirect_url'];
  214.          echo '<span class="success-icon">✓</span><a href="' . $redirectUrl . '">点击下载</a>';
  215.     } else {
  216.         $code = $data['code'];
  217.         $message = $data['message'];
  218.         echo '<span class="error-icon">✗</span>'."错误: 错误码" . $code . "//" . $message;
  219.     }
  220. }
  221. ?>
  222.     </div>
  223. </body>
  224. </html>
复制代码


回复

使用道具 举报

0

主题

38

帖子

838

积分

高级会员

Rank: 4

积分
838
发表于 2025-11-20 03:25:16 | 显示全部楼层
111111111111
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

QQ|Archiver|小黑屋|网盛资源论坛 ( 粤ICP备2022085098号 )|网站地图

GMT+8, 2026-11-13 03:53 , Processed in 0.260850 second(s), 29 queries .

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

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