mirror of
https://github.com/qaiu/netdisk-fast-download.git
synced 2026-12-03 10:13:59 +00:00
旧实现通过 GET 请求获取 HTML 并正则提取 JS 变量,但接口已改为返回 JSON, 导致 NumberFormatException。改为 POST 请求 `https://wx.mail.qq.com/s`, body 为 `f=json&k={shareKey}`,解析 JSON 响应中的 body.url/name/size。 - 使用 postAbs() 替代 request() 以正确处理 HTTPS - 使用 asJson() 兼容 gzip 响应 - 使用 complete() 正确存储 downloadUrl - 添加 User-Agent、URL 编码 shareKey
68 lines
2.7 KiB
Java
68 lines
2.7 KiB
Java
package cn.qaiu.parser.impl;
|
|
|
|
import cn.qaiu.entity.FileInfo;
|
|
import cn.qaiu.entity.ShareLinkInfo;
|
|
import io.vertx.core.Future;
|
|
import io.vertx.core.buffer.Buffer;
|
|
import io.vertx.core.json.JsonObject;
|
|
|
|
import java.net.URLEncoder;
|
|
import java.nio.charset.StandardCharsets;
|
|
|
|
public class QQwTool extends QQTool {
|
|
|
|
public QQwTool(ShareLinkInfo shareLinkInfo) {
|
|
super(shareLinkInfo);
|
|
}
|
|
|
|
@Override
|
|
public Future<String> parse() {
|
|
String k = shareLinkInfo.getShareKey();
|
|
String postBody = "f=json&k=" + URLEncoder.encode(k, StandardCharsets.UTF_8);
|
|
|
|
client.postAbs("https://wx.mail.qq.com/s")
|
|
.putHeader("Content-Type", "application/x-www-form-urlencoded")
|
|
.putHeader("Accept", "application/json, text/plain, */*")
|
|
.putHeader("Referer", shareLinkInfo.getShareUrl())
|
|
.putHeader("User-Agent", "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 "
|
|
+ "(KHTML, like Gecko) Chrome/134.0.0.0 Safari/537.36 Edg/134.0.0.0")
|
|
.sendBuffer(Buffer.buffer(postBody))
|
|
.onSuccess(res -> {
|
|
try {
|
|
JsonObject data = asJson(res);
|
|
JsonObject head = data.getJsonObject("head");
|
|
if (head == null || head.getInteger("ret", -1) != 0) {
|
|
String msg = head != null ? head.getString("msg", "未知错误") : "未知错误";
|
|
fail("API错误: " + msg);
|
|
return;
|
|
}
|
|
|
|
JsonObject body = data.getJsonObject("body");
|
|
if (body == null) {
|
|
fail("文件信息为空");
|
|
return;
|
|
}
|
|
|
|
String url = body.getString("url");
|
|
String fn = body.getString("name", "");
|
|
long size = body.getLong("size", 0L);
|
|
|
|
if (url == null || url.isEmpty()) {
|
|
fail("分享链接解析失败, 可能是链接失效");
|
|
return;
|
|
}
|
|
|
|
FileInfo fileInfo = new FileInfo().setFileName(fn).setSize(size);
|
|
shareLinkInfo.getOtherParam().put("fileInfo", fileInfo);
|
|
|
|
String url302 = url.replace("\\x26", "&");
|
|
complete(url302);
|
|
} catch (Exception e) {
|
|
fail(e, "解析响应失败");
|
|
}
|
|
}).onFailure(handleFail());
|
|
|
|
return promise.future();
|
|
}
|
|
}
|