mirror of
https://github.com/qaiu/netdisk-fast-download.git
synced 2026-11-27 15:47:00 +00:00
Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
11f156605a | ||
|
|
1eae4698d6 | ||
|
|
4361d96c52 | ||
|
|
971cdcd067 | ||
|
|
4b9339072a |
No files matched your search
@@ -25,8 +25,8 @@ body:
|
||||
id: version
|
||||
attributes:
|
||||
label: 版本号
|
||||
description: 页面上的版本,或发布包名里的版本,例如 0.4.12。
|
||||
placeholder: "0.4.12"
|
||||
description: 页面上的版本,或发布包名里的版本,例如 0.4.13。
|
||||
placeholder: "0.4.13"
|
||||
validations:
|
||||
required: true
|
||||
- type: dropdown
|
||||
|
||||
@@ -25,8 +25,8 @@ body:
|
||||
id: version
|
||||
attributes:
|
||||
label: 版本号
|
||||
description: 例如 0.4.12。不确定就写获取方式。
|
||||
placeholder: "0.4.12"
|
||||
description: 例如 0.4.13。不确定就写获取方式。
|
||||
placeholder: "0.4.13"
|
||||
validations:
|
||||
required: true
|
||||
- type: dropdown
|
||||
|
||||
+17
-20
@@ -1,25 +1,22 @@
|
||||
## 更新内容
|
||||
|
||||
目录列表支持分页了。之前蓝奏云目录只返回前 50 个文件,小飞机盘和蓝奏云优享只返回前 60 个。早先的分页需求见 https://github.com/qaiu/netdisk-fast-download/issues/112 。
|
||||
|
||||
- 目录分页(#308):
|
||||
- 蓝奏云:按页读取 `filemoreajax`,每页 50 个。只有 `zt=2`(翻过最后一页)或不足 50 个的页才算结束。`zt=4`「请刷新,重试0」视为限流,同一页等 2 秒、再等 5 秒重试;仍失败就返回可重试的错误,不当作最后一页。每页返回 `nextCursor`,下一页沿用同一组翻页参数。不带游标时最多直接请求到第 6 页。
|
||||
- 小飞机盘、蓝奏云优享:`offset` 作为页码,每页 60 个,由 `totalPage` / `total` 判断是否还有下一页。
|
||||
- 新接口 `/v2/getFileListPage` 返回 `list`、`hasMore`、`nextPage`、`nextCursor`、`total`、`totalPage`。`/v2/getFileList` 也接受 `page`(或 `pg`)和 `pageCursor`。不带页码时返回结构和以前一样。不支持分页的网盘请求第 2 页及以后时返回空页。
|
||||
- 前端:目录面板和树形视图有「加载更多」,滚动到底也会自动加载下一页。已加载的文件会保留,加载失败时显示错误并停止自动加载,点击可重试。`list.html` 同样支持。
|
||||
- 蓝奏云目录风控页(#307):目录分享页改用移动端 UA 请求,文件页仍用桌面 UA。如果仍返回空白风控页,提示「访问风控,不能据此判断分享已失效」,不再报成分享已失效。
|
||||
- 新增 Issue 表单:解析失败、运行问题、功能建议(#305)。
|
||||
|
||||
## 实测范围
|
||||
|
||||
- 蓝奏云 `pan.lanzoui.com/b66477`:连续翻完 93 页,共 4598 个文件,没有重复,最后一页 9 个且 `hasMore=false`。实测遇到 `zt=4` 时,2 秒后重试成功。第 2 页的文件可以下载。
|
||||
- 蓝奏云带密码目录 `moteam.lanzoum.com/b00yaejvte`(密码 `1234`):第 1 页 7 个且没有下一页,第 2 页为空。不带页码的旧接口仍返回 7 个。
|
||||
- 蓝奏云优享:用真实小目录、把每页条数临时设为 1 来验证。`offset` 是从 1 开始的页码,`total` / `totalPage` 正确,翻过最后一页为空。
|
||||
- 夸克、城通:目录列表和以前一样,请求第 2 页返回空页。
|
||||
- 蓝奏文件页识别 `ajaxfiles.php`(#310):
|
||||
- 单文件页 iframe 里的下载 ajax 写成了 `/ajaxfiles.php`。解析器原来只认 `ajaxm.php` 和 `ajaxfile.php`,匹配不上就报「获取失败0, 可能分享已失效」。表单字段没有改。
|
||||
- `https://njkn.lanzouw.com/winx123`(无密码)没有失效。修复后本机完整下载 1,197,569 字节,`unzip -t` 无错误。
|
||||
- 另外三个同样改成 `ajaxfiles.php` 的对照只各下载了 1 MiB Range,返回 206,文件头分别是 7z、zip、zip,没有做完整下载:
|
||||
- `wwn.lanzouy.com/ihLkw1gezutg`
|
||||
- b66477 目录下的 `pan.lanzoui.com/io4y41i3zq5e`
|
||||
- 密码目录 `b00yaejvte` 里的子文件 `w1.lanzn.com/i4VjZ332qzwh`
|
||||
- 带密码的单文件分享没有找到公开样例,没有实测。
|
||||
- 目录按已加载文件名筛选(#311):
|
||||
- 分享目录浏览器和首页解析后的目录共用目录树。两套视图以及独立的 `list.html` 按文件名做大小写不敏感的子串匹配,只筛已经加载的行,不把后续页自动拉完。
|
||||
- 目录树底部「全选 / 取消全选」只作用于当前关键字命中的、已经加载的可选文件。不勾选被筛掉的项,不拉取未加载分页,也不清掉范围外原来的选择。
|
||||
- 分页仍走现有的 `nextCursor` / `pageCursor`。
|
||||
- 界面验收跑在本机开发服务和本机夹具,不是线上分享页。
|
||||
|
||||
## 限制
|
||||
|
||||
- 小飞机盘没有可用的真实目录样本,只做了本地模拟测试(与蓝奏云优享是同一套接口)。
|
||||
- 蓝奏云优享没有实测超过 60 个文件的大目录。
|
||||
- 蓝奏云不带游标直接请求第 7 页及以后会提示需要游标,请按 `nextCursor` 顺序翻页。
|
||||
- 风控页提示只能说明这次请求被拦截,不代表分享一定有效。
|
||||
- 没有把这次界面验收当成线上分享页或全站界面已验。
|
||||
- 三个对照链接只验证了 1 MiB Range,不能据此说这些文件已经完整下载并核对。
|
||||
- 带密码的单文件分享未测。
|
||||
- 本机访问部分蓝奏下载域时连接时好时坏。winx123 曾连续超时,重试后完整下载成功。
|
||||
@@ -470,7 +470,7 @@ docker run --rm -v /var/run/docker.sock:/var/run/docker.sock containrrr/watchtow
|
||||
> 注意: netdisk-fast-download.service中的ExecStart的路径改为实际路径
|
||||
```shell
|
||||
cd ~
|
||||
wget -O netdisk-fast-download.zip https://github.com/qaiu/netdisk-fast-download/releases/download/v0.4.12/netdisk-fast-download-linux-amd64.zip
|
||||
wget -O netdisk-fast-download.zip https://github.com/qaiu/netdisk-fast-download/releases/download/v0.4.13/netdisk-fast-download-linux-amd64.zip
|
||||
unzip netdisk-fast-download.zip
|
||||
cd netdisk-fast-download
|
||||
bash service-install.sh
|
||||
|
||||
@@ -32,8 +32,12 @@ import java.util.zip.CRC32;
|
||||
import static cn.qaiu.util.RandomStringGenerator.gen36String;
|
||||
|
||||
/**
|
||||
* 123盘解析器 v2 - 使用Android平台API
|
||||
* 支持账号密码或token配置
|
||||
* 123盘解析器。
|
||||
* 分享单文件走分享域名:先 POST /api/share/download/traffic/check,
|
||||
* 再 POST /api/v2/share/download/info。platform web,App-Version 149。
|
||||
* 域名只由 shareKey 解码出的数字 uid 组成,不使用调用方提供的任意 host。
|
||||
* 文件夹打包下载仍走 App-Version 55 的 batch_download_share_info。
|
||||
* 支持账号密码或 token 配置。
|
||||
*
|
||||
* @author <a href="https://qaiu.top">QAIU</a>
|
||||
*/
|
||||
@@ -41,9 +45,13 @@ public class Ye2Tool extends PanBase {
|
||||
|
||||
private static final String API_BASE = "https://api.123278.com";
|
||||
private static final String GET_SHARE_INFO_URL = API_BASE + "/b/api/share/get?limit=100&next=1&orderBy=share_id&orderDirection=desc&shareKey={shareKey}&SharePwd={pwd}&ParentFileId={ParentFileId}&Page=1";
|
||||
private static final String DOWNLOAD_API_URL = API_BASE + "/b/api/file/download_info";
|
||||
private static final String DOWNLOAD_API_V2_BASE = "https://api.123278.com";
|
||||
private static final String DOWNLOAD_API_V2_PATH = "/b/api/v2/share/download/info";
|
||||
/** 分享页脚本把 /share/download/traffic/check 加上 /api 前缀,发到当前分享域名。 */
|
||||
static final String SHARE_TRAFFIC_CHECK_PATH = "/api/share/download/traffic/check";
|
||||
/** 分享页脚本把 /v2/share/download/info 加上 /api 前缀,不是 api.123278.com/b/api。 */
|
||||
static final String SHARE_DOWNLOAD_INFO_PATH = "/api/v2/share/download/info";
|
||||
static final String SHARE_PLATFORM = "web";
|
||||
/** 当前分享页静态资源里的 App-Version。个人文件接口 App-Version 55 会返回 5066。 */
|
||||
static final String SHARE_WEB_APP_VERSION = "149";
|
||||
private static final String BATCH_DOWNLOAD_API_URL = API_BASE + "/b/api/file/batch_download_share_info";
|
||||
private static final String LOGIN_URL = "https://login.123pan.com/api/user/sign_in";
|
||||
|
||||
@@ -126,28 +134,25 @@ public class Ye2Tool extends PanBase {
|
||||
return TokenCache.isExpired(cacheKey);
|
||||
}
|
||||
|
||||
private String crc32(String data) {
|
||||
CRC32 crc32 = new CRC32();
|
||||
crc32.update(data.getBytes());
|
||||
long value = crc32.getValue();
|
||||
return String.format("%08x", value);
|
||||
}
|
||||
|
||||
private long hexToInt(String hexStr) {
|
||||
return Long.parseLong(hexStr, 16);
|
||||
}
|
||||
|
||||
private String encode123(String url, String way, String version, String timestamp) {
|
||||
Random random = new Random();
|
||||
int randomInt = random.nextInt(10000000) + 1;
|
||||
long a = (10000000L * randomInt) / 10000;
|
||||
return signQuery(url, way, version, Long.parseLong(timestamp), nextSignRandom());
|
||||
}
|
||||
|
||||
long timeLong = Long.parseLong(timestamp) / 1000;
|
||||
private static long nextSignRandom() {
|
||||
int randomInt = new Random().nextInt(10000000) + 1;
|
||||
return (10000000L * randomInt) / 10000;
|
||||
}
|
||||
|
||||
/**
|
||||
* 签名原文:unix秒|随机数|实际路径|platform|App-Version|时间混淆值。
|
||||
* 分享下载的路径是 /api/...,platform 是 web,版本是 149。
|
||||
*/
|
||||
static String signMaterial(String url, String way, String version, long timeMillis, long randomA) {
|
||||
long timeLong = timeMillis / 1000;
|
||||
java.time.LocalDateTime dateTime = java.time.Instant.ofEpochSecond(timeLong)
|
||||
.atZone(java.time.ZoneId.systemDefault())
|
||||
.toLocalDateTime();
|
||||
String timeStr = dateTime.format(DateTimeFormatter.ofPattern("yyyyMMddHHmm"));
|
||||
|
||||
StringBuilder g = new StringBuilder();
|
||||
for (char c : timeStr.toCharArray()) {
|
||||
int digit = Character.getNumericValue(c);
|
||||
@@ -157,11 +162,22 @@ public class Ye2Tool extends PanBase {
|
||||
g.append(CHAR_MAP.charAt(digit - 1));
|
||||
}
|
||||
}
|
||||
String y = String.valueOf(crc32Decimal(g.toString()));
|
||||
return timeLong + "|" + randomA + "|" + url + "|" + way + "|" + version + "|" + y;
|
||||
}
|
||||
|
||||
String y = String.valueOf(hexToInt(crc32(g.toString())));
|
||||
String finalCrcInput = String.format("%d|%d|%s|%s|%s|%s", timeLong, a, url, way, version, y);
|
||||
String finalCrc = String.valueOf(hexToInt(crc32(finalCrcInput)));
|
||||
return String.format("?%s=%d-%d-%s", y, timeLong, a, finalCrc);
|
||||
static String signQuery(String url, String way, String version, long timeMillis, long randomA) {
|
||||
String material = signMaterial(url, way, version, timeMillis, randomA);
|
||||
String y = material.substring(material.lastIndexOf('|') + 1);
|
||||
long timeLong = timeMillis / 1000;
|
||||
String finalCrc = String.valueOf(crc32Decimal(material));
|
||||
return "?" + y + "=" + timeLong + "-" + randomA + "-" + finalCrc;
|
||||
}
|
||||
|
||||
private static long crc32Decimal(String data) {
|
||||
CRC32 crc32 = new CRC32();
|
||||
crc32.update(data.getBytes(java.nio.charset.StandardCharsets.UTF_8));
|
||||
return crc32.getValue();
|
||||
}
|
||||
|
||||
public Future<String> parse() {
|
||||
@@ -210,15 +226,14 @@ public class Ye2Tool extends PanBase {
|
||||
}
|
||||
|
||||
JsonObject fileInfo = data.getJsonArray("InfoList").getJsonObject(0);
|
||||
if (token.equals("nologin")) {
|
||||
fail(loginRequiredDownloadMessage(false, null));
|
||||
return;
|
||||
}
|
||||
|
||||
if (fileInfo.getInteger("Type", 0) == 1) {
|
||||
if (!hasUsableToken(token)) {
|
||||
fail(loginRequiredDownloadMessage(false, null));
|
||||
return;
|
||||
}
|
||||
getZipDownUrl(client, fileInfo);
|
||||
} else {
|
||||
getDownUrl(client, fileInfo);
|
||||
getDownUrl(fileInfo, token);
|
||||
}
|
||||
})
|
||||
.onFailure(this.handleFail(GET_SHARE_INFO_URL));
|
||||
@@ -317,112 +332,55 @@ public class Ye2Tool extends PanBase {
|
||||
return promise.future();
|
||||
}
|
||||
|
||||
private void getDownUrl(WebClient client, JsonObject fileInfo) {
|
||||
/**
|
||||
* 分享单文件:流量预检通过后走分享域名 v2。不回退个人文件接口,也不创建订单。
|
||||
*/
|
||||
private void getDownUrl(JsonObject fileInfo, String token) {
|
||||
setFileInfo(fileInfo);
|
||||
|
||||
String normalizedShareKey = YeShareHostUtil.normalizeShareKey(shareLinkInfo.getShareKey());
|
||||
if (StringUtils.isNotEmpty(normalizedShareKey)) {
|
||||
JsonObject v2Body = new JsonObject()
|
||||
.put("ShareKey", normalizedShareKey)
|
||||
.put("FileID", fileInfo.getInteger("FileId"))
|
||||
.put("S3keyFlag", fileInfo.getString("S3KeyFlag"))
|
||||
.put("Size", fileInfo.getLong("Size"))
|
||||
.put("Etag", fileInfo.getString("Etag"));
|
||||
requestShareV2Download(normalizedShareKey, v2Body).onSuccess(v2Url -> {
|
||||
if (StringUtils.isNotEmpty(v2Url)) {
|
||||
complete(v2Url);
|
||||
return;
|
||||
}
|
||||
requestLegacyDownUrl(client, fileInfo);
|
||||
}).onFailure(err -> {
|
||||
log.warn("Ye2 v2分享下载接口失败,回退旧接口: {}", err.getMessage());
|
||||
requestLegacyDownUrl(client, fileInfo);
|
||||
});
|
||||
applyResolvedShareKey(shareLinkInfo, normalizedShareKey);
|
||||
Integer fileId = fileInfo.getInteger("FileId");
|
||||
if (!usableShareKey(normalizedShareKey) || fileId == null) {
|
||||
fail("123网盘公开下载参数缺少分享标识");
|
||||
return;
|
||||
}
|
||||
|
||||
requestLegacyDownUrl(client, fileInfo);
|
||||
long size = fileInfo.getLong("Size") == null ? 0L : fileInfo.getLong("Size");
|
||||
requestShareDownload(normalizedShareKey, fileId, fileInfo.getString("S3KeyFlag"), size,
|
||||
fileInfo.getString("Etag"), token).onSuccess(this::complete)
|
||||
.onFailure(err -> fail(err.getMessage()));
|
||||
}
|
||||
|
||||
private void requestLegacyDownUrl(WebClient client, JsonObject fileInfo) {
|
||||
JsonObject jsonObject = new JsonObject();
|
||||
jsonObject.put("driveId", 0);
|
||||
jsonObject.put("etag", fileInfo.getString("Etag"));
|
||||
jsonObject.put("fileId", fileInfo.getInteger("FileId"));
|
||||
jsonObject.put("fileName", fileInfo.getString("FileName"));
|
||||
jsonObject.put("s3keyFlag", fileInfo.getString("S3KeyFlag"));
|
||||
jsonObject.put("size", fileInfo.getLong("Size"));
|
||||
jsonObject.put("type", 0);
|
||||
|
||||
String timestamp = String.valueOf(System.currentTimeMillis());
|
||||
String encryptedParams = encode123("/b/api/file/download_info", "android", "55", timestamp);
|
||||
String apiUrl = DOWNLOAD_API_URL + encryptedParams;
|
||||
|
||||
log.info("Ye2 API URL: {}", apiUrl);
|
||||
|
||||
HttpRequest<Buffer> bufferHttpRequest = client.postAbs(apiUrl);
|
||||
bufferHttpRequest.putHeader("platform", "android");
|
||||
bufferHttpRequest.putHeader("App-Version", "55");
|
||||
bufferHttpRequest.putHeader("Authorization", "Bearer " + TokenCache.getToken(cacheKey));
|
||||
bufferHttpRequest.putHeader("User-Agent", "Mozilla/5.0 (Linux; Android 13) AppleWebKit/537.36");
|
||||
bufferHttpRequest.putHeader("Content-Type", "application/json");
|
||||
|
||||
bufferHttpRequest
|
||||
.sendJsonObject(jsonObject)
|
||||
.onSuccess(res2 -> handleDownloadUrlResponse(client, asJson(res2), "Ye2"))
|
||||
.onFailure(err -> fail("下载接口失败: " + err.getMessage()));
|
||||
private Future<String> requestShareDownload(String shareKey, long fileId, String s3keyFlag, long size,
|
||||
String etag, String token) {
|
||||
return executeShareFileDownload(this::postShareJson, new ShareFileRequest(
|
||||
shareLinkInfo.getShareUrl(),
|
||||
shareLinkInfo.getStandardUrl(),
|
||||
shareKey,
|
||||
shareLinkInfo.getSharePassword(),
|
||||
fileId,
|
||||
s3keyFlag,
|
||||
size,
|
||||
etag,
|
||||
token,
|
||||
System.currentTimeMillis(),
|
||||
nextSignRandom()));
|
||||
}
|
||||
|
||||
private Future<String> requestShareV2Download(String shareKey, JsonObject body) {
|
||||
Promise<String> promise = Promise.promise();
|
||||
String timestamp = String.valueOf(System.currentTimeMillis());
|
||||
String encryptedParams = encode123(DOWNLOAD_API_V2_PATH, "web", "3", timestamp);
|
||||
String apiUrl = DOWNLOAD_API_V2_BASE + DOWNLOAD_API_V2_PATH + encryptedParams;
|
||||
String shareOrigin = resolveYeShareOrigin(shareKey);
|
||||
String shareReferer = buildShareReferer(shareOrigin, shareKey, shareLinkInfo.getSharePassword());
|
||||
|
||||
HttpRequest<Buffer> request = client.postAbs(apiUrl);
|
||||
request.putHeader("Accept", "*/*");
|
||||
request.putHeader("Authorization", "Bearer " + TokenCache.getToken(cacheKey));
|
||||
request.putHeader("App-Version", "3");
|
||||
request.putHeader("platform", "web");
|
||||
request.putHeader("Origin", shareOrigin);
|
||||
request.putHeader("Referer", shareReferer);
|
||||
request.putHeader("User-Agent", "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/149.0.0.0 Safari/537.36");
|
||||
request.putHeader("Content-Type", "application/json;charset=UTF-8");
|
||||
|
||||
request.sendJsonObject(body).onSuccess(resp -> {
|
||||
JsonObject json = asJson(resp);
|
||||
if (json == null || json.getInteger("code", -1) != 0) {
|
||||
promise.fail("v2接口返回异常: " + (json == null ? "null" : json.encode()));
|
||||
return;
|
||||
}
|
||||
JsonObject data = json.getJsonObject("data", new JsonObject());
|
||||
JsonArray dispatchList = data.getJsonArray("dispatchList", new JsonArray());
|
||||
String downloadPath = data.getString("downloadPath");
|
||||
if (StringUtils.isBlank(downloadPath)) {
|
||||
promise.complete("");
|
||||
return;
|
||||
}
|
||||
String prefix = "";
|
||||
if (dispatchList.size() > 0) {
|
||||
JsonObject firstDispatch = dispatchList.getJsonObject(0);
|
||||
if (firstDispatch != null) {
|
||||
prefix = firstDispatch.getString("prefix", "");
|
||||
}
|
||||
}
|
||||
if (StringUtils.isBlank(prefix)) {
|
||||
promise.complete(downloadPath);
|
||||
return;
|
||||
}
|
||||
String finalUrl = prefix.endsWith("/") ? prefix.substring(0, prefix.length() - 1) : prefix;
|
||||
finalUrl += downloadPath.startsWith("/") ? downloadPath : "/" + downloadPath;
|
||||
promise.complete(finalUrl);
|
||||
}).onFailure(promise::fail);
|
||||
|
||||
private Future<JsonObject> postShareJson(ShareHttpCall call) {
|
||||
Promise<JsonObject> promise = Promise.promise();
|
||||
HttpRequest<Buffer> request = client.postAbs(call.url());
|
||||
call.headers.forEach(entry -> request.putHeader(entry.getKey(), entry.getValue()));
|
||||
request.sendJsonObject(call.body)
|
||||
.onSuccess(resp -> promise.complete(asJson(resp)))
|
||||
.onFailure(promise::fail);
|
||||
return promise.future();
|
||||
}
|
||||
|
||||
/**
|
||||
* 文件夹打包下载仍使用 App-Version 55 的 /b/api/file/batch_download_share_info。
|
||||
* 分享页脚本已改走 /v2/file/batch_download_share_info,这次不改这条路径。
|
||||
*/
|
||||
private void getZipDownUrl(WebClient client, JsonObject fileInfo) {
|
||||
JsonObject jsonObject = new JsonObject();
|
||||
jsonObject.put("shareKey", YeShareHostUtil.normalizeShareKey(shareLinkInfo.getShareKey()));
|
||||
@@ -691,76 +649,322 @@ public class Ye2Tool extends PanBase {
|
||||
Future<String> tokenFuture = resolveTokenFuture();
|
||||
|
||||
tokenFuture.onSuccess(token -> {
|
||||
if (token.equals("nologin")) {
|
||||
fail(loginRequiredDownloadMessage(false, null));
|
||||
if (hasUsableToken(token)) {
|
||||
TokenCache.putToken(cacheKey, token);
|
||||
}
|
||||
String normalizedShareKey = resolveDownloadShareKey(paramJson, shareLinkInfo.getShareKey());
|
||||
applyResolvedShareKey(shareLinkInfo, normalizedShareKey);
|
||||
if (!usableShareKey(normalizedShareKey)) {
|
||||
fail("123网盘公开下载参数缺少分享标识");
|
||||
return;
|
||||
}
|
||||
|
||||
String rawShareKey = paramJson.getString("shareKey");
|
||||
if (StringUtils.isBlank(rawShareKey)) {
|
||||
rawShareKey = paramJson.getString("ShareKey");
|
||||
}
|
||||
if (StringUtils.isBlank(rawShareKey)) {
|
||||
rawShareKey = shareLinkInfo.getShareKey();
|
||||
}
|
||||
String normalizedShareKey = YeShareHostUtil.normalizeShareKey(rawShareKey);
|
||||
if (StringUtils.isNotEmpty(normalizedShareKey)) {
|
||||
JsonObject v2Body = new JsonObject()
|
||||
.put("ShareKey", normalizedShareKey)
|
||||
.put("FileID", paramJson.getInteger("fileId", paramJson.getInteger("FileID", 0)))
|
||||
.put("S3keyFlag", paramJson.getString("s3keyFlag", paramJson.getString("S3keyFlag", "")))
|
||||
.put("Size", paramJson.getLong("size", paramJson.getLong("Size", 0L)))
|
||||
.put("Etag", paramJson.getString("etag", paramJson.getString("Etag", "")));
|
||||
requestShareV2Download(normalizedShareKey, v2Body).onSuccess(v2Url -> {
|
||||
if (StringUtils.isNotEmpty(v2Url)) {
|
||||
complete(v2Url);
|
||||
return;
|
||||
}
|
||||
parseByIdLegacy(token, paramJson);
|
||||
}).onFailure(err -> {
|
||||
log.warn("Ye2 parseById v2接口失败,回退旧接口: {}", err.getMessage());
|
||||
parseByIdLegacy(token, paramJson);
|
||||
});
|
||||
return;
|
||||
}
|
||||
|
||||
parseByIdLegacy(token, paramJson);
|
||||
long fileId = paramJson.getLong("fileId", paramJson.getLong("FileID", 0L));
|
||||
String s3keyFlag = firstNonBlank(paramJson, "s3keyFlag", "S3keyFlag", "S3KeyFlag");
|
||||
long size = paramJson.getLong("size", paramJson.getLong("Size", 0L));
|
||||
String etag = firstNonBlank(paramJson, "etag", "Etag");
|
||||
requestShareDownload(normalizedShareKey, fileId, s3keyFlag, size, etag, token)
|
||||
.onSuccess(this::complete)
|
||||
.onFailure(err -> fail(err.getMessage()));
|
||||
}).onFailure(err -> fail("123盘解析异常: " + err.getMessage()));
|
||||
|
||||
return promise.future();
|
||||
}
|
||||
|
||||
private void parseByIdLegacy(String token, JsonObject paramJson) {
|
||||
if (paramJson.containsKey("FileID") && !paramJson.containsKey("fileId")) {
|
||||
paramJson.put("fileId", paramJson.getValue("FileID"));
|
||||
static final class ShareFileRequest {
|
||||
final String shareUrl;
|
||||
final String standardUrl;
|
||||
final String shareKey;
|
||||
final String password;
|
||||
final long fileId;
|
||||
final String s3keyFlag;
|
||||
final long size;
|
||||
final String etag;
|
||||
final String token;
|
||||
final long timeMillis;
|
||||
final long randomA;
|
||||
|
||||
ShareFileRequest(String shareUrl, String standardUrl, String shareKey, String password, long fileId,
|
||||
String s3keyFlag, long size, String etag, String token, long timeMillis, long randomA) {
|
||||
this.shareUrl = shareUrl;
|
||||
this.standardUrl = standardUrl;
|
||||
this.shareKey = shareKey;
|
||||
this.password = password;
|
||||
this.fileId = fileId;
|
||||
this.s3keyFlag = s3keyFlag;
|
||||
this.size = size;
|
||||
this.etag = etag;
|
||||
this.token = token;
|
||||
this.timeMillis = timeMillis;
|
||||
this.randomA = randomA;
|
||||
}
|
||||
if (paramJson.containsKey("S3keyFlag") && !paramJson.containsKey("s3keyFlag")) {
|
||||
paramJson.put("s3keyFlag", paramJson.getValue("S3keyFlag"));
|
||||
}
|
||||
if (paramJson.containsKey("Size") && !paramJson.containsKey("size")) {
|
||||
paramJson.put("size", paramJson.getValue("Size"));
|
||||
}
|
||||
if (paramJson.containsKey("Etag") && !paramJson.containsKey("etag")) {
|
||||
paramJson.put("etag", paramJson.getValue("Etag"));
|
||||
}
|
||||
|
||||
static final class ShareHttpCall {
|
||||
final String origin;
|
||||
final String path;
|
||||
final String query;
|
||||
final JsonObject body;
|
||||
final MultiMap headers;
|
||||
|
||||
ShareHttpCall(String origin, String path, String query, JsonObject body, MultiMap headers) {
|
||||
this.origin = origin;
|
||||
this.path = path;
|
||||
this.query = query;
|
||||
this.body = body;
|
||||
this.headers = headers;
|
||||
}
|
||||
|
||||
String timestamp = String.valueOf(System.currentTimeMillis());
|
||||
String encryptedParams = encode123("/b/api/file/download_info", "android", "55", timestamp);
|
||||
String apiUrl = DOWNLOAD_API_URL + encryptedParams;
|
||||
String url() {
|
||||
return origin + path + query;
|
||||
}
|
||||
}
|
||||
|
||||
log.info("Ye2 parseById API URL: {}", apiUrl);
|
||||
@FunctionalInterface
|
||||
interface ShareJsonPost {
|
||||
Future<JsonObject> post(ShareHttpCall call);
|
||||
}
|
||||
|
||||
HttpRequest<Buffer> bufferHttpRequest = client.postAbs(apiUrl);
|
||||
bufferHttpRequest.putHeader("platform", "android");
|
||||
bufferHttpRequest.putHeader("App-Version", "55");
|
||||
bufferHttpRequest.putHeader("Authorization", "Bearer " + token);
|
||||
bufferHttpRequest.putHeader("User-Agent", "Mozilla/5.0 (Linux; Android 13) AppleWebKit/537.36");
|
||||
bufferHttpRequest.putHeader("Content-Type", "application/json");
|
||||
/**
|
||||
* 分享接口只发到 key 解码出的 https://{uid}.share.123pan.cn。
|
||||
* mshare、/s/ 和调用方写入的其它 host 都不能改变这个目标。
|
||||
*/
|
||||
static String shareApiOrigin(String shareUrl, String standardUrl, String shareKey) {
|
||||
String uid = YeShareHostUtil.getNumericSubdomainIdByShareKey(shareKey);
|
||||
if (!uid.matches("\\d+")) {
|
||||
return null;
|
||||
}
|
||||
if (hostileShareHost(shareUrl) || hostileShareHost(standardUrl)) {
|
||||
return null;
|
||||
}
|
||||
return "https://" + uid + ".share.123pan.cn";
|
||||
}
|
||||
|
||||
bufferHttpRequest
|
||||
.sendJsonObject(paramJson)
|
||||
.onSuccess(res2 -> handleDownloadUrlResponse(client, asJson(res2), "Ye2"))
|
||||
.onFailure(err -> fail("下载接口失败: " + err.getMessage()));
|
||||
/**
|
||||
* 调用方给出的地址如果带了 host,只允许空、普通网页,或与 shareKey 一致的数字分享域名。
|
||||
* 127.0.0.1、云元数据、以及伪装成 123 域名的其它 host 直接拒绝。
|
||||
*/
|
||||
static boolean hostileShareHost(String url) {
|
||||
if (StringUtils.isBlank(url)) {
|
||||
return false;
|
||||
}
|
||||
java.net.URI uri;
|
||||
try {
|
||||
uri = java.net.URI.create(url.trim());
|
||||
} catch (IllegalArgumentException e) {
|
||||
return true;
|
||||
}
|
||||
String host = uri.getHost();
|
||||
if (host == null) {
|
||||
return true;
|
||||
}
|
||||
String scheme = uri.getScheme();
|
||||
if (!"https".equalsIgnoreCase(scheme) && !"http".equalsIgnoreCase(scheme)) {
|
||||
return true;
|
||||
}
|
||||
if (uri.getUserInfo() != null || uri.getPort() > 0) {
|
||||
return true;
|
||||
}
|
||||
if (host.equalsIgnoreCase("www.123pan.com") || host.equalsIgnoreCase("yun.123pan.com")
|
||||
|| host.equalsIgnoreCase("123pan.com")) {
|
||||
return false;
|
||||
}
|
||||
return !host.matches("(?i)\\d+\\.(?:mshare|share)\\.123pan\\.cn");
|
||||
}
|
||||
|
||||
static JsonObject trafficCheckBody(String shareKey, long fileId) {
|
||||
return new JsonObject()
|
||||
.put("shareKey", shareKey)
|
||||
.put("fileIds", new JsonArray().add(fileId));
|
||||
}
|
||||
|
||||
static JsonObject downloadInfoBody(String shareKey, long fileId, String s3keyFlag, long size, String etag) {
|
||||
return new JsonObject()
|
||||
.put("ShareKey", shareKey)
|
||||
.put("FileID", fileId)
|
||||
.put("S3keyFlag", s3keyFlag == null ? "" : s3keyFlag)
|
||||
.put("Size", size)
|
||||
.put("Etag", etag == null ? "" : etag);
|
||||
}
|
||||
|
||||
static String trafficStopMessage(JsonObject data) {
|
||||
if (data == null) {
|
||||
return null;
|
||||
}
|
||||
if (Boolean.TRUE.equals(data.getBoolean("isBlocked"))) {
|
||||
return "123网盘限制了这个分享的下载。解析器不会自动下单或选择付费流量。";
|
||||
}
|
||||
if (Boolean.TRUE.equals(data.getBoolean("isPay"))) {
|
||||
return "123网盘这个文件需要付费后下载。解析器不会自动下单或选择付费流量。";
|
||||
}
|
||||
if (Boolean.TRUE.equals(data.getBoolean("isTrafficExceeded"))) {
|
||||
return "123网盘分享提取流量不足。解析器不会自动购买或选择付费流量。";
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
static String joinDownloadUrl(String downloadPath, String prefix) {
|
||||
if (StringUtils.isBlank(downloadPath)) {
|
||||
return "";
|
||||
}
|
||||
String path = downloadPath.trim();
|
||||
if (path.startsWith("//")) {
|
||||
return "";
|
||||
}
|
||||
if (isAbsoluteHttp(path)) {
|
||||
return path;
|
||||
}
|
||||
if (StringUtils.isBlank(prefix) || !isAbsoluteHttp(prefix.trim())) {
|
||||
return "";
|
||||
}
|
||||
String normalizedPrefix = prefix.trim();
|
||||
if (normalizedPrefix.endsWith("/") && path.startsWith("/")) {
|
||||
return normalizedPrefix.substring(0, normalizedPrefix.length() - 1) + path;
|
||||
}
|
||||
if (!normalizedPrefix.endsWith("/") && !path.startsWith("/")) {
|
||||
return normalizedPrefix + "/" + path;
|
||||
}
|
||||
return normalizedPrefix + path;
|
||||
}
|
||||
|
||||
private static boolean isAbsoluteHttp(String value) {
|
||||
return value.startsWith("https://") || value.startsWith("http://");
|
||||
}
|
||||
|
||||
static Future<String> executeShareFileDownload(ShareJsonPost post, ShareFileRequest request) {
|
||||
String origin = shareApiOrigin(request.shareUrl, request.standardUrl, request.shareKey);
|
||||
if (origin == null || !usableShareKey(request.shareKey)) {
|
||||
return Future.failedFuture("123网盘公开下载参数缺少可识别的分享域名");
|
||||
}
|
||||
String referer = origin + "/123pan/" + YeShareHostUtil.normalizeShareKey(request.shareKey);
|
||||
if (StringUtils.isNotBlank(request.password)) {
|
||||
referer = referer + "?pwd=" + request.password;
|
||||
}
|
||||
MultiMap headers = shareHeaders(origin, referer, request.token);
|
||||
ShareHttpCall traffic = new ShareHttpCall(
|
||||
origin,
|
||||
SHARE_TRAFFIC_CHECK_PATH,
|
||||
signQuery(SHARE_TRAFFIC_CHECK_PATH, SHARE_PLATFORM, SHARE_WEB_APP_VERSION,
|
||||
request.timeMillis, request.randomA),
|
||||
trafficCheckBody(request.shareKey, request.fileId),
|
||||
headers);
|
||||
ShareHttpCall download = new ShareHttpCall(
|
||||
origin,
|
||||
SHARE_DOWNLOAD_INFO_PATH,
|
||||
signQuery(SHARE_DOWNLOAD_INFO_PATH, SHARE_PLATFORM, SHARE_WEB_APP_VERSION,
|
||||
request.timeMillis, request.randomA),
|
||||
downloadInfoBody(request.shareKey, request.fileId, request.s3keyFlag, request.size, request.etag),
|
||||
headers);
|
||||
return post.post(traffic).compose(json -> {
|
||||
if (json == null || json.getInteger("code", -1) != 0) {
|
||||
return Future.failedFuture(shareV2FailureMessage(json, request.token));
|
||||
}
|
||||
String stop = trafficStopMessage(json.getJsonObject("data"));
|
||||
if (stop != null) {
|
||||
return Future.failedFuture(stop);
|
||||
}
|
||||
return post.post(download);
|
||||
}).compose(json -> {
|
||||
if (json == null || json.getInteger("code", -1) != 0) {
|
||||
return Future.failedFuture(shareV2FailureMessage(json, request.token));
|
||||
}
|
||||
JsonObject data = json.getJsonObject("data", new JsonObject());
|
||||
JsonArray dispatchList = data.getJsonArray("dispatchList", new JsonArray());
|
||||
String prefix = "";
|
||||
if (!dispatchList.isEmpty() && dispatchList.getJsonObject(0) != null) {
|
||||
prefix = dispatchList.getJsonObject(0).getString("prefix", "");
|
||||
}
|
||||
String url = joinDownloadUrl(data.getString("downloadPath"), prefix);
|
||||
if (StringUtils.isBlank(url)) {
|
||||
return Future.failedFuture("123网盘公开下载接口未返回下载链接");
|
||||
}
|
||||
return Future.succeededFuture(url);
|
||||
});
|
||||
}
|
||||
|
||||
private static MultiMap shareHeaders(String origin, String referer, String token) {
|
||||
MultiMap headers = MultiMap.caseInsensitiveMultiMap();
|
||||
headers.set("Accept", "*/*");
|
||||
headers.set("App-Version", SHARE_WEB_APP_VERSION);
|
||||
headers.set("platform", SHARE_PLATFORM);
|
||||
headers.set("Origin", origin);
|
||||
headers.set("Referer", referer);
|
||||
headers.set("User-Agent", "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/149.0.0.0 Safari/537.36");
|
||||
headers.set("Content-Type", "application/json;charset=UTF-8");
|
||||
String authorization = bearerAuthorization(token);
|
||||
if (authorization != null) {
|
||||
headers.set("Authorization", authorization);
|
||||
}
|
||||
return headers;
|
||||
}
|
||||
|
||||
private static String firstNonBlank(JsonObject json, String... keys) {
|
||||
if (json == null) {
|
||||
return "";
|
||||
}
|
||||
for (String key : keys) {
|
||||
String value = json.getString(key);
|
||||
if (StringUtils.isNotBlank(value)) {
|
||||
return value;
|
||||
}
|
||||
}
|
||||
return "";
|
||||
}
|
||||
|
||||
static String resolveDownloadShareKey(JsonObject paramJson, String fallbackShareKey) {
|
||||
String shareKey = paramJson == null ? null : paramJson.getString("shareKey");
|
||||
if (StringUtils.isBlank(shareKey) && paramJson != null) {
|
||||
shareKey = paramJson.getString("ShareKey");
|
||||
}
|
||||
if (StringUtils.isBlank(shareKey)) {
|
||||
shareKey = fallbackShareKey;
|
||||
}
|
||||
return YeShareHostUtil.normalizeShareKey(shareKey);
|
||||
}
|
||||
|
||||
static boolean usableShareKey(String shareKey) {
|
||||
return StringUtils.isNotBlank(shareKey) && !"-".equals(shareKey);
|
||||
}
|
||||
|
||||
/**
|
||||
* getFileDownInfo / redirectUrl 用 shareKey="-" 占位,错误文案会变成 /s/-。
|
||||
* 目录参数里已有真实 shareKey 时,只替换这个占位地址。
|
||||
*/
|
||||
static void applyResolvedShareKey(ShareLinkInfo info, String shareKey) {
|
||||
if (info == null || !usableShareKey(shareKey)) {
|
||||
return;
|
||||
}
|
||||
info.setShareKey(shareKey);
|
||||
String rebuilt = "https://www.123pan.com/s/" + shareKey;
|
||||
if (isPlaceholderYeShareUrl(info.getShareUrl())) {
|
||||
info.setShareUrl(rebuilt);
|
||||
}
|
||||
if (isPlaceholderYeShareUrl(info.getStandardUrl())) {
|
||||
info.setStandardUrl(rebuilt);
|
||||
}
|
||||
}
|
||||
|
||||
static boolean isPlaceholderYeShareUrl(String url) {
|
||||
return StringUtils.isNotBlank(url) && (url.endsWith("/s/-") || url.endsWith("/s/-.html"));
|
||||
}
|
||||
|
||||
static String bearerAuthorization(String token) {
|
||||
return hasUsableToken(token) ? "Bearer " + token : null;
|
||||
}
|
||||
|
||||
/**
|
||||
* v2 非 0 的说明。5112 仍用现有登录提示;5113、5066 原样留在 v2 错误里,不再改写成个人文件接口的文案。
|
||||
*/
|
||||
static String shareV2FailureMessage(JsonObject json, String token) {
|
||||
Integer code = json == null ? null : json.getInteger("code");
|
||||
String message = json == null ? null : json.getString("message");
|
||||
if (isYeLoginRequired(code, message)) {
|
||||
return loginRequiredDownloadMessage(hasUsableToken(token), message);
|
||||
}
|
||||
return "v2接口返回异常: " + (json == null ? "null" : json.encode());
|
||||
}
|
||||
|
||||
private static boolean hasUsableToken(String token) {
|
||||
return StringUtils.isNotBlank(token) && !"nologin".equals(token);
|
||||
}
|
||||
|
||||
private void setFileTimes(JsonObject item, FileInfo fileInfo) {
|
||||
|
||||
@@ -18,6 +18,8 @@ public class Ye2LoginHintTest {
|
||||
assertTrue(Ye2Tool.isYeLoginRequired(0, "需要登录才能下载"));
|
||||
assertFalse(Ye2Tool.isYeLoginRequired(0, "ok"));
|
||||
assertFalse(Ye2Tool.isYeLoginRequired(null, null));
|
||||
assertFalse(Ye2Tool.isYeLoginRequired(5113, "分享方提取流量包不足"));
|
||||
assertFalse(Ye2Tool.isYeLoginRequired(5066, "该文件暂不支持在当前版本下载"));
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
@@ -0,0 +1,410 @@
|
||||
package cn.qaiu.parser.impl;
|
||||
|
||||
import cn.qaiu.entity.ShareLinkInfo;
|
||||
import io.vertx.core.Future;
|
||||
import io.vertx.core.json.JsonArray;
|
||||
import io.vertx.core.json.JsonObject;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.atomic.AtomicInteger;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertNull;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
/**
|
||||
* 123 分享单文件下载规则。不访问网络。
|
||||
* mvn -pl parser -DskipTests=false -Dtest=Ye2ToolTest,Ye2LoginHintTest test
|
||||
*/
|
||||
public class Ye2ToolTest {
|
||||
|
||||
@Test
|
||||
public void downloadUsesShareKeyEncodedInDirectoryFileParameter() {
|
||||
JsonObject directoryFileParameter = new JsonObject()
|
||||
.put("shareKey", "iaKtVv-6OECd.html?from=dir")
|
||||
.put("fileId", 123);
|
||||
|
||||
assertEquals("iaKtVv-6OECd",
|
||||
Ye2Tool.resolveDownloadShareKey(directoryFileParameter, "-"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void downloadFallsBackToParserShareKeyWhenParameterHasNone() {
|
||||
assertEquals("iaKtVv-6OECd",
|
||||
Ye2Tool.resolveDownloadShareKey(new JsonObject(), "iaKtVv-6OECd.html"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void downloadAcceptsCapitalShareKeyFromParameter() {
|
||||
JsonObject directoryFileParameter = new JsonObject()
|
||||
.put("ShareKey", "iaKtVv-r4aCd");
|
||||
|
||||
assertEquals("iaKtVv-r4aCd",
|
||||
Ye2Tool.resolveDownloadShareKey(directoryFileParameter, "-"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void anonymous123RequestsDoNotSendFakeBearerTokens() {
|
||||
assertNull(Ye2Tool.bearerAuthorization(null));
|
||||
assertNull(Ye2Tool.bearerAuthorization(""));
|
||||
assertNull(Ye2Tool.bearerAuthorization("nologin"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void configured123TokenKeepsExistingBearerAuthentication() {
|
||||
assertEquals("Bearer configured-token",
|
||||
Ye2Tool.bearerAuthorization("configured-token"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shareDownloadUsesCurrentWebAppVersion() {
|
||||
assertEquals("149", Ye2Tool.SHARE_WEB_APP_VERSION);
|
||||
assertTrue(Ye2Tool.usableShareKey("iaKtVv-r4aCd"));
|
||||
assertFalse(Ye2Tool.usableShareKey("-"));
|
||||
assertFalse(Ye2Tool.usableShareKey(""));
|
||||
assertFalse(Ye2Tool.usableShareKey(null));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void placeholderShareUrlIsReplacedWithShareKeyFromFileParameter() {
|
||||
ShareLinkInfo info = ShareLinkInfo.newBuilder()
|
||||
.type("ye")
|
||||
.shareKey("-")
|
||||
.shareUrl("https://www.123pan.com/s/-")
|
||||
.standardUrl("https://www.123pan.com/s/-")
|
||||
.build();
|
||||
|
||||
Ye2Tool.applyResolvedShareKey(info, "iaKtVv-r4aCd");
|
||||
|
||||
assertEquals("iaKtVv-r4aCd", info.getShareKey());
|
||||
assertEquals("https://www.123pan.com/s/iaKtVv-r4aCd", info.getShareUrl());
|
||||
assertEquals("https://www.123pan.com/s/iaKtVv-r4aCd", info.getStandardUrl());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void realShareUrlIsKeptWhenResolvingDirectoryFile() {
|
||||
String original = "https://1815268665.mshare.123pan.cn/123pan/iaKtVv-r4aCd";
|
||||
ShareLinkInfo info = ShareLinkInfo.newBuilder()
|
||||
.type("ye")
|
||||
.shareKey("iaKtVv-r4aCd")
|
||||
.shareUrl(original)
|
||||
.standardUrl("https://www.123pan.com/s/iaKtVv-r4aCd")
|
||||
.build();
|
||||
|
||||
Ye2Tool.applyResolvedShareKey(info, "iaKtVv-r4aCd");
|
||||
|
||||
assertEquals(original, info.getShareUrl());
|
||||
assertEquals("https://www.123pan.com/s/iaKtVv-r4aCd", info.getStandardUrl());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void placeholderStandardUrlDoesNotReplaceOriginalShareUrl() {
|
||||
String original = "https://1815268665.mshare.123pan.cn/123pan/iaKtVv-r4aCd";
|
||||
ShareLinkInfo info = ShareLinkInfo.newBuilder()
|
||||
.type("ye")
|
||||
.shareKey("-")
|
||||
.shareUrl(original)
|
||||
.standardUrl("https://www.123pan.com/s/-")
|
||||
.build();
|
||||
|
||||
Ye2Tool.applyResolvedShareKey(info, "iaKtVv-r4aCd");
|
||||
|
||||
assertEquals(original, info.getShareUrl());
|
||||
assertEquals("https://www.123pan.com/s/iaKtVv-r4aCd", info.getStandardUrl());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void anonymousV2LoginCodeUsesExistingLoginHint() {
|
||||
JsonObject json = new JsonObject()
|
||||
.put("code", 5112)
|
||||
.put("message", "您需要注册登录或付费后下载");
|
||||
|
||||
String msg = Ye2Tool.shareV2FailureMessage(json, "nologin");
|
||||
|
||||
assertTrue(msg.contains("auths.ye.authorization"));
|
||||
assertTrue(msg.contains("上游信息: 您需要注册登录或付费后下载"));
|
||||
assertFalse(msg.contains("downURLJson"));
|
||||
assertFalse(msg.contains("download_info"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void loggedInV2TrafficShortageStaysOnV2Error() {
|
||||
JsonObject json = new JsonObject()
|
||||
.put("code", 5113)
|
||||
.put("message", "分享方提取流量包不足");
|
||||
|
||||
String msg = Ye2Tool.shareV2FailureMessage(json, "configured-token");
|
||||
|
||||
assertTrue(msg.startsWith("v2接口返回异常:"));
|
||||
assertTrue(msg.contains("5113"));
|
||||
assertTrue(msg.contains("分享方提取流量包不足"));
|
||||
assertFalse(msg.contains("downURLJson"));
|
||||
assertFalse(msg.contains("download_info"));
|
||||
assertFalse(msg.contains("auths.ye.authorization"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void oldClientErrorIsNotRewrittenAsPersonalFileApiFailure() {
|
||||
JsonObject json = new JsonObject()
|
||||
.put("code", 5066)
|
||||
.put("message", "该文件暂不支持在当前版本下载");
|
||||
|
||||
String msg = Ye2Tool.shareV2FailureMessage(json, "configured-token");
|
||||
|
||||
assertTrue(msg.startsWith("v2接口返回异常:"));
|
||||
assertTrue(msg.contains("5066"));
|
||||
assertFalse(msg.contains("downURLJson"));
|
||||
assertFalse(Ye2Tool.isYeLoginRequired(5066, "该文件暂不支持在当前版本下载"));
|
||||
assertFalse(Ye2Tool.isYeLoginRequired(5113, "分享方提取流量包不足"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void signatureUsesActualSharePathPlatformAndVersion() {
|
||||
long time = 1_700_000_000_000L;
|
||||
long randomA = 42L;
|
||||
String traffic = Ye2Tool.signMaterial(
|
||||
Ye2Tool.SHARE_TRAFFIC_CHECK_PATH, Ye2Tool.SHARE_PLATFORM, Ye2Tool.SHARE_WEB_APP_VERSION, time, randomA);
|
||||
String download = Ye2Tool.signMaterial(
|
||||
Ye2Tool.SHARE_DOWNLOAD_INFO_PATH, Ye2Tool.SHARE_PLATFORM, Ye2Tool.SHARE_WEB_APP_VERSION, time, randomA);
|
||||
|
||||
assertTrue(traffic.contains("|/api/share/download/traffic/check|web|149|"));
|
||||
assertTrue(download.contains("|/api/v2/share/download/info|web|149|"));
|
||||
assertFalse(traffic.contains("/b/api/"));
|
||||
assertFalse(download.contains("/b/api/"));
|
||||
assertEquals(Ye2Tool.signQuery(
|
||||
Ye2Tool.SHARE_DOWNLOAD_INFO_PATH, "web", "149", time, randomA),
|
||||
Ye2Tool.signQuery(Ye2Tool.SHARE_DOWNLOAD_INFO_PATH, Ye2Tool.SHARE_PLATFORM,
|
||||
Ye2Tool.SHARE_WEB_APP_VERSION, time, randomA));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void mshareAndPlainSharePageUseDecodedShareHost() {
|
||||
String host = "https://1815268665.share.123pan.cn";
|
||||
assertEquals(host, Ye2Tool.shareApiOrigin(
|
||||
"https://1815268665.mshare.123pan.cn/123pan/iaKtVv-r4aCd",
|
||||
"https://www.123pan.com/s/iaKtVv-r4aCd",
|
||||
"iaKtVv-r4aCd"));
|
||||
assertEquals(host, Ye2Tool.shareApiOrigin(
|
||||
"https://1815268665.share.123pan.cn/123pan/iaKtVv-r4aCd?notoken=1",
|
||||
null,
|
||||
"iaKtVv-r4aCd"));
|
||||
assertEquals(host, Ye2Tool.shareApiOrigin(
|
||||
"https://www.123pan.com/s/iaKtVv-r4aCd",
|
||||
"https://yun.123pan.com/s/iaKtVv-r4aCd",
|
||||
"iaKtVv-r4aCd"));
|
||||
assertFalse(host.contains("mshare"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void maliciousHostIsNotCalled() {
|
||||
AtomicInteger calls = new AtomicInteger();
|
||||
Future<String> blocked = Ye2Tool.executeShareFileDownload(call -> {
|
||||
calls.incrementAndGet();
|
||||
return Future.succeededFuture(new JsonObject().put("code", 0));
|
||||
}, sampleRequest("http://127.0.0.1/latest/meta-data", "iaKtVv-r4aCd", "configured-token"));
|
||||
Future<String> disguised = Ye2Tool.executeShareFileDownload(call -> {
|
||||
calls.incrementAndGet();
|
||||
return Future.succeededFuture(new JsonObject().put("code", 0));
|
||||
}, sampleRequest("https://1815268665.share.123pan.cn.evil.com/123pan/iaKtVv-r4aCd",
|
||||
"iaKtVv-r4aCd", "configured-token"));
|
||||
Future<String> unknownKey = Ye2Tool.executeShareFileDownload(call -> {
|
||||
calls.incrementAndGet();
|
||||
return Future.succeededFuture(new JsonObject().put("code", 0));
|
||||
}, sampleRequest("https://evil.example/123pan/not-a-real-key", "not-a-real-key", "configured-token"));
|
||||
|
||||
assertEquals(0, calls.get());
|
||||
assertTrue(blocked.failed());
|
||||
assertTrue(disguised.failed());
|
||||
assertTrue(unknownKey.failed());
|
||||
assertTrue(blocked.cause().getMessage().contains("分享域名"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void successChecksTrafficThenDownloadsOnShareHost() {
|
||||
List<Ye2Tool.ShareHttpCall> seen = new ArrayList<>();
|
||||
Future<String> result = Ye2Tool.executeShareFileDownload(call -> {
|
||||
seen.add(call);
|
||||
if (seen.size() == 1) {
|
||||
return Future.succeededFuture(new JsonObject()
|
||||
.put("code", 0)
|
||||
.put("data", new JsonObject()
|
||||
.put("isBlocked", false)
|
||||
.put("isTrafficExceeded", false)
|
||||
.put("isPay", false)));
|
||||
}
|
||||
return Future.succeededFuture(new JsonObject()
|
||||
.put("code", 0)
|
||||
.put("data", new JsonObject()
|
||||
.put("downloadPath", "/123/file.zip")
|
||||
.put("dispatchList", new JsonArray()
|
||||
.add(new JsonObject().put("prefix", "https://cdn-a.example/"))
|
||||
.add(new JsonObject().put("prefix", "https://cdn-b.example/")))));
|
||||
}, sampleRequest("https://1815268665.mshare.123pan.cn/123pan/iaKtVv-r4aCd",
|
||||
"iaKtVv-r4aCd", "configured-token"));
|
||||
|
||||
assertTrue(result.succeeded());
|
||||
assertEquals("https://cdn-a.example/123/file.zip", result.result());
|
||||
assertEquals(2, seen.size());
|
||||
|
||||
Ye2Tool.ShareHttpCall traffic = seen.get(0);
|
||||
Ye2Tool.ShareHttpCall download = seen.get(1);
|
||||
assertEquals("https://1815268665.share.123pan.cn", traffic.origin);
|
||||
assertEquals(Ye2Tool.SHARE_TRAFFIC_CHECK_PATH, traffic.path);
|
||||
assertEquals(Ye2Tool.SHARE_DOWNLOAD_INFO_PATH, download.path);
|
||||
assertEquals(traffic.origin, download.origin);
|
||||
assertFalse(traffic.url().contains("api.123278.com"));
|
||||
assertFalse(traffic.url().contains("/b/api/"));
|
||||
assertEquals(Ye2Tool.signQuery(traffic.path, "web", "149", 1_700_000_000_000L, 42L), traffic.query);
|
||||
assertEquals(Ye2Tool.signQuery(download.path, "web", "149", 1_700_000_000_000L, 42L), download.query);
|
||||
|
||||
assertEquals("149", traffic.headers.get("App-Version"));
|
||||
assertEquals("web", traffic.headers.get("platform"));
|
||||
assertEquals("Bearer configured-token", traffic.headers.get("Authorization"));
|
||||
assertEquals("application/json;charset=UTF-8", traffic.headers.get("Content-Type"));
|
||||
assertEquals("https://1815268665.share.123pan.cn", traffic.headers.get("Origin"));
|
||||
assertEquals("https://1815268665.share.123pan.cn/123pan/iaKtVv-r4aCd", traffic.headers.get("Referer"));
|
||||
assertEquals("iaKtVv-r4aCd", traffic.body.getString("shareKey"));
|
||||
assertEquals(Long.valueOf(2468L), traffic.body.getJsonArray("fileIds").getLong(0));
|
||||
assertFalse(traffic.body.containsKey("payType"));
|
||||
|
||||
assertEquals("iaKtVv-r4aCd", download.body.getString("ShareKey"));
|
||||
assertEquals(Long.valueOf(2468L), download.body.getLong("FileID"));
|
||||
assertEquals("etag-flag", download.body.getString("S3keyFlag"));
|
||||
assertEquals(Long.valueOf(6915371L), download.body.getLong("Size"));
|
||||
assertEquals("abcetag", download.body.getString("Etag"));
|
||||
assertFalse(download.body.containsKey("OrderId"));
|
||||
assertFalse(download.body.containsKey("payType"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void directoryDownloadUsesShareKeyHostNotPlaceholderPage() {
|
||||
List<Ye2Tool.ShareHttpCall> seen = new ArrayList<>();
|
||||
Ye2Tool.ShareFileRequest request = sampleRequest(
|
||||
"https://www.123pan.com/s/iaKtVv-r4aCd", "iaKtVv-r4aCd", "configured-token");
|
||||
Future<String> result = Ye2Tool.executeShareFileDownload(call -> {
|
||||
seen.add(call);
|
||||
if (seen.size() == 1) {
|
||||
return Future.succeededFuture(openTraffic());
|
||||
}
|
||||
return Future.succeededFuture(new JsonObject()
|
||||
.put("code", 0)
|
||||
.put("data", new JsonObject()
|
||||
.put("downloadPath", "folder/file.bin")
|
||||
.put("dispatchList", new JsonArray().add(
|
||||
new JsonObject().put("prefix", "https://cdn.example/root")))));
|
||||
}, request);
|
||||
|
||||
assertTrue(result.succeeded());
|
||||
assertEquals("https://cdn.example/root/folder/file.bin", result.result());
|
||||
assertEquals("https://1815268665.share.123pan.cn", seen.get(0).origin);
|
||||
assertFalse(seen.get(0).url().contains("www.123pan.com"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void absoluteDownloadPathIsKept() {
|
||||
Future<String> result = Ye2Tool.executeShareFileDownload(call -> {
|
||||
if (call.path.equals(Ye2Tool.SHARE_TRAFFIC_CHECK_PATH)) {
|
||||
return Future.succeededFuture(openTraffic());
|
||||
}
|
||||
return Future.succeededFuture(new JsonObject()
|
||||
.put("code", 0)
|
||||
.put("data", new JsonObject()
|
||||
.put("downloadPath", "https://cdn.example/already.zip")
|
||||
.put("dispatchList", new JsonArray().add(
|
||||
new JsonObject().put("prefix", "https://ignored.example/")))));
|
||||
}, sampleRequest("https://www.123pan.com/s/iaKtVv-r4aCd", "iaKtVv-r4aCd", "configured-token"));
|
||||
|
||||
assertEquals("https://cdn.example/already.zip", result.result());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void blockedPayAndMissingLinkDoNotContinue() {
|
||||
Future<String> blocked = downloadAfterTraffic(new JsonObject()
|
||||
.put("code", 0)
|
||||
.put("data", new JsonObject().put("isBlocked", true).put("isPay", false)));
|
||||
Future<String> pay = downloadAfterTraffic(new JsonObject()
|
||||
.put("code", 0)
|
||||
.put("data", new JsonObject().put("isPay", true)));
|
||||
Future<String> missing = Ye2Tool.executeShareFileDownload(call -> {
|
||||
if (call.path.equals(Ye2Tool.SHARE_TRAFFIC_CHECK_PATH)) {
|
||||
return Future.succeededFuture(openTraffic());
|
||||
}
|
||||
return Future.succeededFuture(new JsonObject().put("code", 0).put("data", new JsonObject()));
|
||||
}, sampleRequest("https://www.123pan.com/s/iaKtVv-r4aCd", "iaKtVv-r4aCd", "configured-token"));
|
||||
|
||||
Future<String> exceeded = downloadAfterTraffic(new JsonObject()
|
||||
.put("code", 0)
|
||||
.put("data", new JsonObject().put("isTrafficExceeded", true)));
|
||||
|
||||
assertTrue(blocked.cause().getMessage().contains("不会自动下单"));
|
||||
assertTrue(pay.cause().getMessage().contains("不会自动下单"));
|
||||
assertTrue(exceeded.cause().getMessage().contains("不会自动购买"));
|
||||
assertTrue(missing.cause().getMessage().contains("未返回下载链接"));
|
||||
assertFalse(blocked.cause().getMessage().contains("OrderId"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void loginAndTrafficErrorsStayOnTheStepThatReturnedThem() {
|
||||
AtomicInteger calls = new AtomicInteger();
|
||||
Future<String> login = Ye2Tool.executeShareFileDownload(call -> {
|
||||
calls.incrementAndGet();
|
||||
return Future.succeededFuture(new JsonObject()
|
||||
.put("code", 5112)
|
||||
.put("message", "您需要注册登录或付费后下载"));
|
||||
}, sampleRequest("https://www.123pan.com/s/iaKtVv-r4aCd", "iaKtVv-r4aCd", "nologin"));
|
||||
Future<String> traffic = Ye2Tool.executeShareFileDownload(call -> {
|
||||
calls.incrementAndGet();
|
||||
if (call.path.equals(Ye2Tool.SHARE_TRAFFIC_CHECK_PATH)) {
|
||||
assertNull(call.headers.get("Authorization"));
|
||||
return Future.succeededFuture(openTraffic());
|
||||
}
|
||||
return Future.succeededFuture(new JsonObject()
|
||||
.put("code", 5113)
|
||||
.put("message", "分享方提取流量包不足"));
|
||||
}, sampleRequest("https://www.123pan.com/s/iaKtVv-r4aCd", "iaKtVv-r4aCd", "nologin"));
|
||||
|
||||
assertEquals(3, calls.get());
|
||||
assertTrue(login.cause().getMessage().contains("auths.ye.authorization"));
|
||||
assertTrue(traffic.cause().getMessage().contains("5113"));
|
||||
assertFalse(traffic.cause().getMessage().contains("downURLJson"));
|
||||
assertFalse(traffic.cause().getMessage().contains("download_info"));
|
||||
}
|
||||
|
||||
private static Future<String> downloadAfterTraffic(JsonObject trafficJson) {
|
||||
AtomicInteger calls = new AtomicInteger();
|
||||
Future<String> result = Ye2Tool.executeShareFileDownload(call -> {
|
||||
calls.incrementAndGet();
|
||||
return Future.succeededFuture(trafficJson);
|
||||
}, sampleRequest("https://www.123pan.com/s/iaKtVv-r4aCd", "iaKtVv-r4aCd", "configured-token"));
|
||||
assertEquals(1, calls.get());
|
||||
assertTrue(result.failed());
|
||||
return result;
|
||||
}
|
||||
|
||||
private static JsonObject openTraffic() {
|
||||
return new JsonObject()
|
||||
.put("code", 0)
|
||||
.put("data", new JsonObject()
|
||||
.put("isBlocked", false)
|
||||
.put("isTrafficExceeded", false)
|
||||
.put("isPay", false));
|
||||
}
|
||||
|
||||
private static Ye2Tool.ShareFileRequest sampleRequest(String shareUrl, String shareKey, String token) {
|
||||
return new Ye2Tool.ShareFileRequest(
|
||||
shareUrl,
|
||||
"https://www.123pan.com/s/" + shareKey,
|
||||
shareKey,
|
||||
"",
|
||||
2468L,
|
||||
"etag-flag",
|
||||
6915371L,
|
||||
"abcetag",
|
||||
token,
|
||||
1_700_000_000_000L,
|
||||
42L);
|
||||
}
|
||||
}
|
||||
@@ -17,7 +17,7 @@
|
||||
</modules>
|
||||
|
||||
<properties>
|
||||
<revision>0.4.12</revision>
|
||||
<revision>0.4.13</revision>
|
||||
<java.version>17</java.version>
|
||||
<maven.compiler.source>17</maven.compiler.source>
|
||||
<maven.compiler.target>17</maven.compiler.target>
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "nfd-web",
|
||||
"version": "0.4.12",
|
||||
"version": "0.4.13",
|
||||
"private": true,
|
||||
"scripts": {
|
||||
"serve": "vue-cli-service serve",
|
||||
|
||||
Reference in new issue
Block a user