Skip to content
This repository has been archived by the owner on Jun 6, 2024. It is now read-only.

Commit

Permalink
1.4.1更新
Browse files Browse the repository at this point in the history
1.修改POST内容,让调用接口暂时失效
2.增加直链解析,可以不设置UA下载(不过并不稳定,且只支持50MB以下文件)
  • Loading branch information
yuantuo666 authored Aug 27, 2020
1 parent ba2f54d commit e6805e9
Show file tree
Hide file tree
Showing 5 changed files with 74 additions and 22 deletions.
10 changes: 4 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -66,10 +66,8 @@ define('Password', '789');
- [LC优化版](https://github.com/lc6464 "LC")

## New Changes
- 当前版本:`1.4.0`
- 更新日期:2020-8-26
- 当前版本:`1.4.1`
- 更新日期:2020-8-27
- 修改内容
- 增加推送至aria2功能
- 增加面包屑导航,便于寻找指定文件夹
- 完善错误提示,获取列表超时会提示
- 修复特殊路径报错(url传入时未编码)
- 修改POST内容,让调用接口暂时失效
- 增加直链解析,可以不设置UA下载(不过并不稳定,且只支持50MB以下文件)
4 changes: 2 additions & 2 deletions config.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,14 @@
* 请不要使用弱密码!否则后果自负!
* 若只在局域网开放,则可根据个人喜好开启或关闭密码。
*
* @version 1.4.0
* @version 1.4.1
*
* @author Yuan_Tuo <[email protected]>
* @link https://imwcr.cn/
* @link https://space.bilibili.com/88197958
*
*/
define('programVersion', '1.4.0');
define('programVersion', '1.4.1');
if (!defined('init')){ // 直接访问处理程序
http_response_code(403); header('Content-Type: text/plain; charset=utf-8'); header('Refresh: 3;url=./');
die("HTTP 403 禁止访问!\r\n此文件是 PanDownload 网页复刻版 PHP 语言版项目版本 " . programVersion . " 的配置文件!\r\n禁止直接访问!");
Expand Down
15 changes: 11 additions & 4 deletions functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
*
* 请勿随意修改此文件!如需更改相关配置请到 config.php !
*
* @version 1.4.0
* @version 1.4.1
*
* @author Yuan_Tuo <[email protected]>
* @link https://imwcr.cn/
Expand Down Expand Up @@ -183,19 +183,26 @@ function FileInfo(string $filename, float $size, string $md5, int $server_ctime)
return '<p class="card-text">文件名:<b>' . $filename . '</b></p><p class="card-text">文件大小:<b>' . formatSize($size) . '</b></p><p class="card-text">文件MD5:<b>' . $md5
. '</b></p><p class="card-text">上传时间:<b>' . date("Y年m月d日 H:i:s", $server_ctime) . '</b></p>';
}
function getDlink(string $fs_id, string $timestamp, string $sign, string $randsk, string $share_id, string $uk)
function getDlink(string $fs_id, string $timestamp, string $sign, string $randsk, string $share_id, string $uk, string $bdstoken,bool $isnoualink)
{ // 获取下载链接
$app_id = 250528;
//推荐应用ID:498065、309847、778750、250528(官方)、265486、266719;
$url = 'https://pan.baidu.com/api/sharedownload?app_id=' . $app_id . '&channel=chunlei&clienttype=12&sign=' . $sign . '&timestamp=' . $timestamp . '&web=1';

if($isnoualink){
$url = 'https://pan.baidu.com/api/sharedownload?app_id=' . $app_id . '&channel=chunlei&clienttype=0&sign=' . $sign . '&timestamp=' . $timestamp . '&web=1&bdstoken='.$bdstoken;//获取直链 50MB以内
}else{
$url = 'https://pan.baidu.com/api/sharedownload?app_id=' . $app_id . '&channel=chunlei&clienttype=12&sign=' . $sign . '&timestamp=' . $timestamp . '&web=1';//获取下载链接
}

$data = "encrypt=0" . "&extra=" . urlencode('{"sekey":"' . urldecode($randsk) . '"}') . "&fid_list=[$fs_id]" . "&primaryid=$share_id" . "&uk=$uk" . "&product=share&type=nolimit";
$header = array(
"User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/114.514.1919.810 Safari/537.36",
"Cookie: BDUSS=" . BDUSS . ";STOKEN=" . STOKEN . ";BDCLND=" . $randsk . ";",
"Referer: https://pan.baidu.com/disk/home"
);
return json_decode(post($url, $data, $header), true);
//没有 referer 就 112 ,然后没有 sekey 参数就 118 -20???

//没有 referer 就 112 ,然后没有 sekey 参数就 118 -20出现验证码
// 参数 类型 描述
// list json array 文件信息列表
// names json 如果查询共享目录,该字段为共享目录文件上传者的uk和账户名称
Expand Down
63 changes: 55 additions & 8 deletions index.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
*
* 此项目 GitHub 地址:https://github.com/yuantuo666/baiduwp-php
*
* @version 1.4.0
* @version 1.4.1
*
* @author Yuan_Tuo <[email protected]>
* @link https://imwcr.cn/
Expand Down Expand Up @@ -168,6 +168,7 @@
$uk = $_POST["uk"];
$sign = $root["sign"];
$timestamp = $root["timestamp"];
$bdstoken = $root["bdstoken"];
$filejson = GetDir($_POST["dir"], $randsk, $shareid, $uk);
if ($filejson["errno"] != 0) echo '<div class="row justify-content-center"><div class="col-md-7 col-sm-8 col-11"><div class="alert alert-danger" role="alert">
<h5 class="alert-heading">文件夹存在问题</h5><hr /><p class="card-text">此文件夹存在问题,无法访问!</p></div></div></div>'; // 鬼知道发生了啥
Expand All @@ -187,7 +188,7 @@
for ($i = 0; $i < count($filejson["list"]); $i++) { //开始输出文件列表
$file = $filejson["list"][$i];
if ($file["isdir"] === 0) $filecontent .= '<li class="list-group-item border-muted text-muted py-2"><i class="far fa-file mr-2"></i>
<a href="javascript:dl(\'' . number_format($file["fs_id"], 0, '', '') . '\',' . $timestamp . ',\'' . $sign . '\',\'' . urlencode($randsk) . '\',\'' . $shareid . '\',\'' . $uk . '\');">' . $file["server_filename"] . '</a>
<a href="javascript:dl(\'' . number_format($file["fs_id"], 0, '', '') . '\',' . $timestamp . ',\'' . $sign . '\',\'' . urlencode($randsk) . '\',\'' . $shareid . '\',\'' . $uk . '\',\'' . $bdstoken . '\',\'' . $file["size"] . '\');">' . $file["server_filename"] . '</a>
<span class="float-right">' . formatSize($file["size"]) . '</span></li>';
else $filecontent .= '<li class="list-group-item border-muted text-muted py-2"><i class="far fa-folder mr-2"></i>
<a href="javascript:OpenDir(\'' . $file["path"] . '\',\'' . $pwd . '\',\'' . $shareid . '\',\'' . $uk . '\',\'' . $surl . '\');">' . $file["server_filename"] . '</a><span class="float-right"></span></li>';
Expand All @@ -207,6 +208,7 @@
$timestamp = $root["timestamp"];
$shareid = $root["shareid"];
$uk = $root["uk"];
$bdstoken = $root["bdstoken"];
if ($filejson["errno"] != 0) echo '<div class="row justify-content-center"><div class="col-md-7 col-sm-8 col-11"><div class="alert alert-danger" role="alert">
<h5 class="alert-heading">链接存在问题</h5><hr /><p class="card-text">此链接存在问题,无法访问!</p></div></div></div>'; // 鬼知道发生了啥
else { // 终于正常了
Expand All @@ -220,7 +222,7 @@
for ($i = 0; $i < count($filejson["list"]); $i++) {
$file = $filejson["list"][$i];
if ($file["isdir"] === 0) $filecontent .= '<li class="list-group-item border-muted text-muted py-2"><i class="far fa-file mr-2"></i>
<a href="javascript:dl(\'' . number_format($file["fs_id"], 0, '', '') . '\',' . $timestamp . ',\'' . $sign . '\',\'' . urlencode($randsk) . '\',\'' . $shareid . '\',\'' . $uk . '\');">' . $file["server_filename"] . '</a>
<a href="javascript:dl(\'' . number_format($file["fs_id"], 0, '', '') . '\',' . $timestamp . ',\'' . $sign . '\',\'' . urlencode($randsk) . '\',\'' . $shareid . '\',\'' . $uk . '\',\'' . $bdstoken . '\',\'' . $file["size"] . '\');">' . $file["server_filename"] . '</a>
<span class="float-right">' . formatSize($file["size"]) . '</span></li>';
else $filecontent .= '<li class="list-group-item border-muted text-muted py-2"><i class="far fa-folder mr-2"></i>
<a href="javascript:OpenDir(\'' . $file["path"] . '\',\'' . $pwd . '\',\'' . $shareid . '\',\'' . $uk . '\',\'' . $surl_1 . '\');">' . $file["server_filename"] . '</a><span class="float-right"></span></li>';
Expand All @@ -234,14 +236,30 @@
if (IsCheckPassword and (!isset($_SESSION["Password"]) or $_SESSION["Password"] != Password)) {
dl_error("密码错误", "密码错误或超时,请返回首页重新验证密码。"); // 密码错误
} elseif ($_SERVER['REQUEST_METHOD'] == 'POST') {
if (isset($_POST["fs_id"]) && isset($_POST["time"]) && isset($_POST["sign"]) && isset($_POST["randsk"]) && isset($_POST["share_id"]) && isset($_POST["uk"])) {
if (isset($_POST["fs_id"]) && isset($_POST["time"]) && isset($_POST["sign"]) && isset($_POST["randsk"]) && isset($_POST["share_id"]) && isset($_POST["uk"]) && isset($_POST["bdstoken"]) && isset($_POST["filesize"])) {
$fs_id = $_POST["fs_id"];
$timestamp = $_POST["time"];
$sign = $_POST["sign"];
$randsk = $_POST["randsk"];
$share_id = $_POST["share_id"];
$uk = $_POST["uk"];
$json4 = getDlink($fs_id, $timestamp, $sign, $randsk, $share_id, $uk);
$bdstoken=$_POST["bdstoken"];
$filesize=$_POST["filesize"];
$nouarealLink="";//重置
if((int)$filesize<=52428800){
$json5 = getDlink($fs_id, $timestamp, $sign, $randsk, $share_id, $uk ,$bdstoken,true);
if ($json5["errno"] == 0) {
$nouadlink = $json5["list"][0]["dlink"];
//开始获取真实链接
$headerArray = array('User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/114.514.1919.810 Safari/537.36', 'Cookie: BDUSS=' . BDUSS . ';');
$getRealLink = head($nouadlink, $headerArray); // 禁止重定向
$getRealLink = strstr($getRealLink, "Location");
$getRealLink = substr($getRealLink, 10);
$nouarealLink = getSubstr($getRealLink, "http://", "\r\n"); // 删除 http://
}
}
$json4 = getDlink($fs_id, $timestamp, $sign, $randsk, $share_id, $uk ,$bdstoken,false);

if ($json4["errno"] == 0) {
$dlink = $json4["list"][0]["dlink"];
//获取文件相关信息
Expand All @@ -255,6 +273,7 @@
$getRealLink = strstr($getRealLink, "Location");
$getRealLink = substr($getRealLink, 10);
$realLink = getSubstr($getRealLink, "http://", "\r\n"); // 删除 http://

// 1. 使用 dlink 下载文件 2. dlink 有效期为8小时 3. 必需要设置 User-Agent 字段 4. dlink 存在 HTTP 302 跳转
if ($realLink == "") echo '<div class="row justify-content-center"><div class="col-md-7 col-sm-8 col-11"><div class="alert alert-danger" role="alert">
<h5 class="alert-heading">获取下载链接失败</h5><hr /><p class="card-text">已获取到文件,但未能获取到下载链接!</p><p class="card-text">请检查你是否在 <code>config.php</code> 中配置 SVIP 账号的 BDUSS 和 STOKEN!</p>
Expand All @@ -266,9 +285,35 @@
<div class="alert alert-primary" role="alert">
<h5 class="alert-heading">获取下载链接成功</h5>
<hr /><?php echo FileInfo($filename, $size, $md5, $server_ctime); ?>
<?php
if($nouarealLink!=""){
echo '<hr />';
$type=substr($filename,-4);

if ($type==".jpg" || $type==".png" || $type=="jpeg" || $type==".bmp"){
echo '<img src="https://'.$nouarealLink.'" class="img-fluid rounded">';
}elseif($type ==".pdf" || $type =="docx" || $type ==".doc" || $type =="xlsx" || $type ==".xls" || $type =="pptx" || $type ==".ppt" || $type ==".csv" || $type ==".xml" || $type ==".rtf"){
echo '<p class="card-text"><a href="http://view.xdocin.com/xdoc?_xdoc='.urlencode('https://'.$nouarealLink).'" target="_blank">进入在线预览</a></p>';
}elseif($type=".mp4"){
echo '<video src="https://'.$nouarealLink.'" controls="controls"></video>';
}elseif($type=".mp3"){
echo '<audio src="https://'.$nouarealLink.'" controls="controls"></audio>';
}

echo '
<p class="card-text">
<a href="https://'. $nouarealLink.'" target="_blank" rel="nofollow noopener noreferrer">直链(无需设置UA)</a>
</p>';
}

?>


<hr />
<p class="card-text">
<a id="http" href="http://<?php echo $realLink; ?>" target="_blank" rel="nofollow noopener noreferrer">下载链接(不安全)</a>
<a id="https" href="https://<?php echo $realLink; ?>" target="_blank" rel="nofollow noopener noreferrer">下载链接(安全)</a>
<a id="https" href="https://<?php echo $realLink; ?>" target="_blank" rel="nofollow noopener noreferrer">下载链接(需设置UA,8小时有效)</a>
</p>
<p class="card-text">
<a href="javascript:void(0)" data-toggle="modal" data-target="#exampleModal">推送到Aria2</a>
Expand Down Expand Up @@ -317,7 +362,9 @@
<?php }
// 成功!
} elseif ($json4["errno"] == 112) dl_error("链接超时", "获取链接超时,每次解析列表后只有5min有效时间,请返回首页重新解析。"); // 链接超时
else dl_error("获取下载链接失败", "未知错误!"); // 未知错误
else {
dl_error("获取下载链接失败", "未知错误!"); // 未知错误
}
} else dl_error("参数有误", "POST 传参出现问题!请不要自行构建表单提交!"); // 参数不齐
} else dl_error("方法错误", "请不要直接访问此页面或使用 GET 方式访问!"); // 方法错误
} else { // 首页
Expand Down Expand Up @@ -350,4 +397,4 @@
</div>
</body>

</html>
</html>
4 changes: 2 additions & 2 deletions static/functions.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,10 @@ function validateForm() {
document.forms["form1"]["surl"].value = surl;
return true;
}
function dl(fs_id, timestamp, sign, randsk, share_id, uk) {
function dl(fs_id, timestamp, sign, randsk, share_id, uk, bdstoken, filesize) {
var form = $('<form method="post" action="?download" target="_blank"></form>');
form.append(`<input type="hidden" name="fs_id" value="${fs_id}"/><input type="hidden" name="time" value="${timestamp}"/><input type="hidden" name="sign" value="${sign}"/>
<input type="hidden" name="randsk" value="${randsk}"/><input type="hidden" name="share_id" value="${share_id}"/><input type="hidden" name="uk" value="${uk}"/>`);
<input type="hidden" name="randsk" value="${randsk}"/><input type="hidden" name="share_id" value="${share_id}"/><input type="hidden" name="uk" value="${uk}"/><input type="hidden" name="bdstoken" value="${bdstoken}"/><input type="hidden" name="filesize" value="${filesize}"/>`);
$(document.body).append(form); form.submit();
}
function OpenDir(path, pwd, share_id, uk, surl) {
Expand Down

0 comments on commit e6805e9

Please sign in to comment.