首先,打开一个带密码的文件,然后输入密码。得到了一处请求:
请求1
GET请求地址:https://www.123pan.com/b/api/share/get?limit=100&next=1&orderBy=share_id&orderDirection=desc&shareKey=AHC0Vv-5HIc&SharePwd=&ParentFileId=0&Page=1
其中shareKey为分享地址中的参数,SharePwd参数如果分享地址中有密码的话,填写,没有的话置为空即可。
得到数据:
{"code":0,"message":"ok","data":{"Next":"-1","Len":1,"IsFirst":true,"Expired":false,"InfoList":[{"FileId":2192571,"FileName":"AsteriskPassword.exe","Type":0,"Size":616448,"ContentType":"0","S3KeyFlag":"1655422-0","CreateAt":"2023-05-21T22:50:43+08:00","UpdateAt":"2023-05-24T15:59:23+08:00","Etag":"63cdedcf3d850fba4b063a02dd6ae8d9","DownloadUrl":"","Status":2,"ParentFileId":2116081,"Category":11,"PunishFlag":0,"StorageNode":"m0"}]}}
在上面的data.InfoList[0].Type节点中,数值为1为文件夹,数据为0为文件,文件可直接进行下载。
记录下来:data.InfoList[0].FileId、data.InfoList[0].Etag、data.InfoList[0].S3KeyFlag、data.InfoList[0].Size,还有一个ShareKey参数,请通过用户所输入的数据获取。
获取这五个数据的目的,是为了下个请求做准备。
请求2
POST请求地址:https://www.123pan.com/b/api/share/download/info
请求数据:
{"ShareKey":"AHC0Vv-UyJc","FileID":2118436,"S3keyFlag":"1812615452-0","Size":8039163,"Etag":"312362766406e2c425147b5e5a6729d0"}
带入UA和Content-Type。
UA随意,Content-Type为:application/json;charset=UTF-8
将请求1获取的五个参数,给替换即可。
得到数据:
{"code":0,"message":"success","data":{"DownloadURL":"https://web-pro2.cjjd18.com/download-v2/?params=aHR0cHM6Ly9kb3dubG9hZC1jZG4uMTIzcGFuLmNuLzEyMy00NjQvMzEyMzYyNzYvMTgxMjYxNTQ1Mi0wLzMxMjM2Mjc2NjQwNmUyYzQyNTE0N2I1ZTVhNjcyOWQwL2MtbTI/dj01JnQ9MTY4NTIzNzM4NiZzPTE2ODUyMzczODZiNTc4MDg3MDVhZTY3MDBkYzEzOGQwNTg2OTk2M2FkZiZyPU43R0c4TCZmaWxlbmFtZT1JWE0ucmFyJngtbWYtYml6LWNpZD01OTg1Y2YyOC1jMGFjLTQxZDUtYWQ3MS05ZDI0ODkyOWJmMTctNmVhYTc3\u0026is_s3=0"}}
在data.DownloadURL节点中获取URL,将URL中的params参数进行base64解码,如何取出,可以在软件中使用正则表达式进行取出。
得到:
https://download-cdn.123pan.cn/123-464/31236276/1812615452-0/312362766406e2c425147b5e5a6729d0/c-m2?v=5&t=1685237386&s=1685237386b57808705ae6700dc138d05869963adf&r=N7GG8L&filename=IXM.rar&x-mf-biz-cid=5985cf28-c0ac-41d5-ad71-9d248929bf17-6eaa77
在上面的地址中判断是否有auto_redirect参数,如果没有的话,加入auto_redirect参数。
地址为:https://download-cdn.123pan.cn/123-464/31236276/1812615452-0/312362766406e2c425147b5e5a6729d0/c-m2?v=5&t=1685237386&s=1685237386b57808705ae6700dc138d05869963adf&r=N7GG8L&filename=IXM.rar&x-mf-biz-cid=5985cf28-c0ac-41d5-ad71-9d248929bf17-6eaa77&auto_redirect=0
请求3
GET请求地址:https://download-cdn.123pan.cn/123-464/31236276/1812615452-0/312362766406e2c425147b5e5a6729d0/c-m2?v=5&t=1685237386&s=1685237386b57808705ae6700dc138d05869963adf&r=N7GG8L&filename=IXM.rar&x-mf-biz-cid=5985cf28-c0ac-41d5-ad71-9d248929bf17-6eaa77&auto_redirect=0
得到数据:
{"code":0,"message":"ok","data":{"redirect_url":"https:\/\/221-206-125-6.d.cjjd15.com:30443\/download-cdn.123pan.cn\/123-464\/31236276\/1812615452-0\/312362766406e2c425147b5e5a6729d0\/c-m2?v=5&t=1685237386&s=1685237386b57808705ae6700dc138d05869963adf&r=N7GG8L&filename=IXM.rar&x-mf-biz-cid=5985cf28-c0ac-41d5-ad71-9d248929bf17-6eaa77&auto_redirect=0&xmfcid=0ff4cc07-ef2b-455c-b244-63f76d3b2c11-abf611255-8571-86"}}
其中data['redirect_url']节点的数据为123盘下载的直链。
获取到的直链,可以通过IDM直接进行下载了。
程序运行图
源码
源码文本
整体运行代码,适合没有VS IDE的用户看一下。
[Visual Basic .NET] 纯文本查看 复制代码
Imports System.IO
Imports System.Net
Imports System.Text
Imports System.Text.RegularExpressions
Public Class Form1
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
' 使用正则表达式提取URL
TextBox2.Clear()
Label3.Text = ""
Dim share_id As String
Dim share_Code As String
Dim pattern As String = "(?<=/s/)[^./]+"
Dim match As Match = Regex.Match(TextBox1.Text, pattern)
If match.Success Then
share_id = match.Value
Dim extractCodePattern As String = "提取码:(\w+)"
Dim extractCodeMatch As Match = Regex.Match(TextBox1.Text, extractCodePattern)
If extractCodeMatch.Success Then
share_Code = extractCodeMatch.Groups(1).Value
If share_Code = "" Then
Label3.Text = ""
Else
Label3.Text = "提取码:" & share_Code
End If
Else
'没有提取码,取消
End If
Else
MsgBox("出错:没有找到123盘的网址!")
End If
'获取用户信息
get_info(share_id, share_Code)
End Sub
Function get_info(ByVal share_id As String, ByVal share_Code As String)
ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12
Dim requestUrl As String = "https://www.123pan.com/b/api/share/get?limit=100&next=1&orderBy=share_id&orderDirection=desc&shareKey=" & share_id & "&SharePwd=" & share_Code & "&ParentFileId=0&Page=1"
Dim request As HttpWebRequest = CType(WebRequest.Create(requestUrl), HttpWebRequest)
request.UserAgent = "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"
Dim response As HttpWebResponse = CType(request.GetResponse(), HttpWebResponse)
Using stream As System.IO.Stream = response.GetResponseStream()
Using reader As New System.IO.StreamReader(stream)
Dim responseText As String = reader.ReadToEnd()
解析get_info(responseText, share_id)
End Using
End Using
response.Close()
End Function
Sub 解析get_info(ByVal str As String, ByVal share_id As String)
Dim ScriptObj As Object
ScriptObj = CreateObject("MSScriptControl.ScriptControl")
ScriptObj.AllowUI = True
ScriptObj.Language = "JavaScript"
ScriptObj.AddCode("var data = " & str & ";")
Dim code = ScriptObj.Eval("data.code")
If code = 0 Then
'返回正确,获取关键数据
Dim Type = ScriptObj.Eval("data.data.InfoList[0].Type")
If Type = 0 Then
'文件
Dim FileId = ScriptObj.Eval("data.data.InfoList[0].FileId")
Dim Size = ScriptObj.Eval("data.data.InfoList[0].Size")
Dim S3KeyFlag = ScriptObj.Eval("data.data.InfoList[0].S3KeyFlag")
Dim Etag = ScriptObj.Eval("data.data.InfoList[0].Etag")
'进行第二步,二次获取
'share_id
Combined_data(share_id, FileId, Size, S3KeyFlag, Etag)
Else
TextBox2.Text = "错误:软件目前不支持文件夹解析。"
End If
Else
Dim message = ScriptObj.Eval("data.message")
MsgBox("错误:错误代码" & code & "//" & message)
End If
End Sub
Function Combined_data(ByVal share_id As String, ByVal FileId As Integer, ByVal Size As Integer, ByVal S3KeyFlag As String, ByVal Etag As String)
Dim request As HttpWebRequest = WebRequest.Create("https://www.123pan.com/b/api/share/download/info")
request.Method = "POST"
request.UserAgent = "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"
request.ContentType = "application/json;charset=UTF-8"
Dim postData As String = "{""ShareKey"":""" & share_id & """,""FileID"":" & FileId & ",""S3keyFlag"":""" & S3KeyFlag & """,""Size"":" & Size & ",""Etag"":""" & Etag & """}"
Dim byteArray As Byte() = Encoding.UTF8.GetBytes(postData)
Using dataStream As Stream = request.GetRequestStream()
dataStream.Write(byteArray, 0, byteArray.Length)
End Using
Dim responseString As String
Using response As HttpWebResponse = CType(request.GetResponse(), HttpWebResponse)
If response.StatusCode = HttpStatusCode.OK Then
'读取响应流中的数据
Using streamReader As New StreamReader(response.GetResponseStream())
responseString = streamReader.ReadToEnd()
解析DownloadURL(responseString)
End Using
Else
responseString = "Error: " & response.StatusCode.ToString()
End If
End Using
End Function
Sub 解析DownloadURL(ByVal str As String)
Dim ScriptObj As Object
ScriptObj = CreateObject("MSScriptControl.ScriptControl")
ScriptObj.AllowUI = True
ScriptObj.Language = "JavaScript"
ScriptObj.AddCode("var data = " & str & ";")
Dim code = ScriptObj.Eval("data.code")
If code = 0 Then
Dim DownloadURL = ScriptObj.Eval("data.data.DownloadURL")
DownloadURL = 提取下载链接(DownloadURL)
get_xz_url(DownloadURL)
'解析出来,需要进行提取params参数
Else
Dim message = ScriptObj.Eval("data.message")
MsgBox("错误:错误代码" & code & "//" & message)
End If
End Sub
Function 提取下载链接(ByVal str)
Dim pattern As String = "params=([^&]+)"
Dim match As Match = Regex.Match(str, pattern)
If match.Success Then
Dim paramsValue As String = match.Groups(1).Value
Dim decodedBytes As Byte() = Convert.FromBase64String(paramsValue)
Dim decodedString As String = System.Text.Encoding.UTF8.GetString(decodedBytes)
'判断是否有auto_redirect参数
If Not decodedString.Contains("auto_redirect") Then
If decodedString.Contains("?") Then
decodedString &= "&auto_redirect=0"
Else
decodedString &= "?auto_redirect=0"
End If
End If
Return decodedString
Else
MsgBox("提取DownloadURL失败")
End If
End Function
Function get_xz_url(ByVal requestUrl As String)
ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12
Dim request As HttpWebRequest = CType(WebRequest.Create(requestUrl), HttpWebRequest)
request.UserAgent = "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"
Dim response As HttpWebResponse = CType(request.GetResponse(), HttpWebResponse)
Using stream As System.IO.Stream = response.GetResponseStream()
Using reader As New System.IO.StreamReader(stream)
Dim responseText As String = reader.ReadToEnd()
解析直链(responseText)
End Using
End Using
response.Close()
End Function
Sub 解析直链(ByVal str As String)
Dim ScriptObj As Object
ScriptObj = CreateObject("MSScriptControl.ScriptControl")
ScriptObj.AllowUI = True
ScriptObj.Language = "JavaScript"
ScriptObj.AddCode("var data = " & str & ";")
Dim code = ScriptObj.Eval("data.code")
If code = 0 Then
'直链提取完毕
Dim redirect_url = ScriptObj.Eval("data.data.redirect_url")
TextBox2.Text = redirect_url
Else
Dim message = ScriptObj.Eval("data.message")
MsgBox("错误:错误代码" & code & "//" & message)
End If
End Sub
Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
TextBox1.Clear()
TextBox2.Clear()
End Sub
End Class