diff --git a/web-service/src/main/java/cn/qaiu/lz/common/parser/impl/YeTool.java b/web-service/src/main/java/cn/qaiu/lz/common/parser/impl/YeTool.java index 022b049..905586b 100644 --- a/web-service/src/main/java/cn/qaiu/lz/common/parser/impl/YeTool.java +++ b/web-service/src/main/java/cn/qaiu/lz/common/parser/impl/YeTool.java @@ -1,6 +1,7 @@ package cn.qaiu.lz.common.parser.impl; import cn.qaiu.lz.common.parser.IPanTool; +import cn.qaiu.lz.common.util.AESUtils; import cn.qaiu.lz.common.util.CommonUtils; import cn.qaiu.lz.common.util.PanExceptionUtils; import cn.qaiu.vx.core.util.VertxHolder; @@ -29,6 +30,8 @@ public class YeTool implements IPanTool { "=file_name&orderDirection=asc&shareKey={shareKey}&SharePwd={pwd}&ParentFileId=0&Page=1&event" + "=homeListFile&operateType=1"; + private static final String DOWNLOAD_API_URL = "https://www.123pan.com/b/api/share/download/info?auth-key={authKey}"; + public Future parse(String data, String code) { String dataKey = CommonUtils.adaptShortPaths(SHARE_URL_PREFIX, data); @@ -88,21 +91,39 @@ public class YeTool implements IPanTool { private static void getDownUrl(Promise promise, WebClient client, JsonObject reqBodyJson) { log.info(reqBodyJson.encodePrettily()); - client.postAbs("https://www.123pan.com/a/api/share/download/info").sendJsonObject(reqBodyJson).onSuccess(res2 -> { - JsonObject downURLJson = res2.bodyAsJsonObject(); - System.out.println(downURLJson); - if (downURLJson.getInteger("code") != 0) { - return; - } - String downURL = downURLJson.getJsonObject("data").getString("DownloadURL"); - try { - Map urlParams = CommonUtils.getURLParams(downURL); - String params = urlParams.get("params"); - byte[] decodeByte = Base64.getDecoder().decode(params); - promise.complete(new String(decodeByte)); - } catch (MalformedURLException e) { - promise.fail("urlParams解析异常" + e.getMessage()); - } - }).onFailure(t -> promise.fail(PanExceptionUtils.fillRunTimeException("Ye", reqBodyJson.encodePrettily(), t))); + client.postAbs(UriTemplate.of(DOWNLOAD_API_URL)) + .setTemplateParam("authKey", AESUtils.getAuthKey()) + .putHeader("Platform", "web") + .putHeader("App-Version", "3") + .sendJsonObject(reqBodyJson).onSuccess(res2 -> { + JsonObject downURLJson = res2.bodyAsJsonObject(); + + if (downURLJson.getInteger("code") != 0) { + promise.fail("Ye: downURLJson返回值异常->" + downURLJson); + return; + } + String downURL = downURLJson.getJsonObject("data").getString("DownloadURL"); + try { + Map urlParams = CommonUtils.getURLParams(downURL); + String params = urlParams.get("params"); + byte[] decodeByte = Base64.getDecoder().decode(params); + String downUrl2 = new String(decodeByte); + + // 获取直链 + client.getAbs(downUrl2).send().onSuccess(res3 -> { + JsonObject res3Json = res3.bodyAsJsonObject(); + if (res3Json.getInteger("code") != 0) { + promise.fail("Ye: downUrl2返回值异常->" + res3Json); + return; + } + promise.complete(res3Json.getJsonObject("data").getString("redirect_url")); + + }).onFailure(t -> promise.fail(PanExceptionUtils.fillRunTimeException("Ye", + reqBodyJson.encodePrettily(), t))); + + } catch (MalformedURLException e) { + promise.fail("urlParams解析异常" + e.getMessage()); + } + }).onFailure(t -> promise.fail(PanExceptionUtils.fillRunTimeException("Ye", reqBodyJson.encodePrettily(), t))); } } diff --git a/web-service/src/main/java/cn/qaiu/lz/common/util/AESUtils.java b/web-service/src/main/java/cn/qaiu/lz/common/util/AESUtils.java index b95d762..f837cc5 100644 --- a/web-service/src/main/java/cn/qaiu/lz/common/util/AESUtils.java +++ b/web-service/src/main/java/cn/qaiu/lz/common/util/AESUtils.java @@ -4,11 +4,14 @@ import org.apache.commons.lang3.StringUtils; import javax.crypto.*; import javax.crypto.spec.SecretKeySpec; +import java.math.BigInteger; import java.nio.charset.StandardCharsets; import java.security.InvalidKeyException; import java.security.Key; +import java.security.MessageDigest; import java.security.NoSuchAlgorithmException; import java.util.Base64; +import java.util.Date; import java.util.HexFormat; import java.util.Random; @@ -257,5 +260,31 @@ public class AESUtils { } + //=============================== 123pan加密相关 =============================== + + public static String getMD5Str(String str) { + byte[] digest; + try { + MessageDigest md5 = MessageDigest.getInstance("md5"); + digest = md5.digest(str.getBytes(StandardCharsets.UTF_8)); + } catch (NoSuchAlgorithmException e) { + throw new RuntimeException(e); + } + //16是表示转换为16进制数 + return new BigInteger(1, digest).toString(16); + } + + public static String getAuthKey() { + String _0x2207af = "/b/api/share/download/info"; + String _0x467baa = "web"; + int _0x4965f1 = 3; + + String _0x430930 = String.valueOf(Math.round(0x989680 * Math.random())); + String _0x53928f = String.valueOf(new Date().getTime() / 0x3e8); + String _0x49ec94 = getMD5Str(_0x53928f + "|" + _0x430930 + "|" + _0x2207af + "|" + _0x467baa + "|" + _0x4965f1 + + "|8-8D$sL8gPjom7bk#cY"); + + return _0x53928f + "-" + _0x430930 + "-" + _0x49ec94; + } } diff --git a/web-service/src/main/resources/http-tools/pan-ye.http b/web-service/src/main/resources/http-tools/pan-ye.http index 89d71f5..c6ec7fa 100644 --- a/web-service/src/main/resources/http-tools/pan-ye.http +++ b/web-service/src/main/resources/http-tools/pan-ye.http @@ -82,3 +82,26 @@ Content-Type:application/json;charset=UTF-8 }, "publicPath": "https://www.123pan.com/a/api/" } + + +### +https://www.123pan.com/b/api/share/get?limit=100&next=1&orderBy=file_name&orderDirection=asc&shareKey=iaKtVv-6OECd&SharePwd=DcGe&ParentFileId=0&Page=1&event=homeListFile&operateType=1&auth-key=1689990170-3703305-62c1030a465013b7c18eddb49156b67b + + +# 23/07/22 123pan添加header +### +POST https://www.123pan.com/b/api/share/download/info?auth-key=1689996626-2926572-49f4cde9a911469869ee264cb6ae8426 +App-Version:3 +Platform:web + +{"ShareKey":"iaKtVv-6OECd","FileID":2193732,"S3keyFlag":"1811834632-0","Size":4203111,"Etag":"69c94adbc0b9190cf23c4e958d8c7c53"} + + + + +### + +https://www.123pan.com/a/api/share/get?limit=100&next=1&orderBy=file_name&orderDirection=asc&shareKey=iaKtVv-6OECd&SharePwd=DcGe&ParentFileId=0&Page=1&event=homeListFile&operateType=1 + + + diff --git a/web-service/src/main/resources/http-tools/test.http b/web-service/src/main/resources/http-tools/test.http index 280a7b7..e9b50a8 100644 --- a/web-service/src/main/resources/http-tools/test.http +++ b/web-service/src/main/resources/http-tools/test.http @@ -76,12 +76,14 @@ GET http://127.0.0.1:6400/fc/e5079007dc31226096628870c7@QAIU #https://v2.fangcloud.com/sharing/e5079007dc31226096628870c7 + +# https://www.123pan.com/s/iaKtVv-ICECd.html ### 123 -GET http://127.0.0.1:6400/json/ye/iaKtVv-qOECd +GET http://127.0.0.1:6400/json/ye/iaKtVv-ICECd ### 123 # @no-redirect -GET http://127.0.0.1:6400/ye/iaKtVv-qOECd@asdads +GET http://127.0.0.1:6400/ye/iaKtVv-qOECd ### 123 # @no-redirect diff --git a/web-service/src/test/java/cn/qaiu/web/test/TestAESUtil.java b/web-service/src/test/java/cn/qaiu/web/test/TestAESUtil.java index 7d0cdda..92c5c80 100644 --- a/web-service/src/test/java/cn/qaiu/web/test/TestAESUtil.java +++ b/web-service/src/test/java/cn/qaiu/web/test/TestAESUtil.java @@ -62,4 +62,19 @@ public class TestAESUtil { System.out.println(AESUtils.getRandomString()); System.out.println(AESUtils.getRandomString()); } + + @Test + public void testKeyAuth(){ + System.out.println(AESUtils.getAuthKey()); + System.out.println(AESUtils.getAuthKey()); + System.out.println(AESUtils.getAuthKey()); + } + + + @Test + public void testAES2() throws NoSuchPaddingException, IllegalBlockSizeException, NoSuchAlgorithmException, + BadPaddingException, InvalidKeyException { + System.out.println(AESUtils.encryptBase64ByAES("AAAAA", "123123")); + System.out.println(AESUtils.encryptBase64ByAES("AAAAA", AESUtils.generateKey("123123"))); + } }