写在前边
- 这里用Delphi演示下获取百度网盘的真实地址,里面一些参数拼接是根据浏览器抓包来的。这里给出了部分源码。
- url网址使用于百度分享的地址。暂时没有适配有提取码的地址。
测试环境
- Delphi 10.2.3 Tokyo
- Windows 7

部分代码
获取api地址
var
panUrlRe: string;
begin
try
try
panUrlRe := FIDHttp.Get(panUrl);
sign := GetMidString(panUrlRe, 'sign":"', '",');
timestamp := GetMidString(panUrlRe, 'timestamp":', ',');
app_id := GetMidString(panUrlRe, 'app_id":"', '",');
bdstoken := GetMidString(panUrlRe, 'bdstoken":', ',');
fid_list := GetMidString(panUrlRe, '"fs_id":', ',');
primaryid := GetMidString(panUrlRe, 'shareid":', ',');
uk := GetMidString(panUrlRe, 'uk=', '&');
apiurl := 'https://pan.baidu.com/api/sharedownload?sign=' + sign +
'×tamp=' + timestamp + '&channel=chunlei&web=1' + '&app_id=' +
app_id + '&bdstoken=' + bdstoken;
wa := '1';
end;
except
on e: exception do
TThread.Synchronize(TThread.CurrentThread,
procedure
begin
MainForm.Memo1.Lines.Add(e.Message);
end);
end;
finally
TThread.Synchronize(TThread.CurrentThread,
procedure
begin
MainForm.ActivityIndicator1.Animate := False;
end);
end;
var
VcodUrl: string;
begin
try
try
postinstr := TstringList.Create;
postinstr.Add('encrypt=' + '0');
postinstr.Add('fid_list=[' + fid_list + ']');
postinstr.Add('path_list=');
postinstr.Add('primaryid=' + primaryid);
postinstr.Add('product=' + 'share');
postinstr.Add('uk=' + uk);
postResult := Fidhttp.Post(apiurl, postinstr);
realUrl := StringReplace(GetMidString(postResult, 'dlink":"', '",'), '\',
'', [rfReplaceAll]);
if pos('-20', postResult) > 0 then
begin
VcodUrl :=
'https://pan.baidu.com/api/getvcode?prod=pan&channel=chunlei&web=1&app_id='
+ app_id + '&bdstoken=' + bdstoken;
vcodeRe := Fidhttp.Get(VcodUrl);
vcode_str := GetMidString(vcodeRe, 'vcode":"', '",');
imageUrl := StringReplace(GetMidString(vcodeRe, 'img":"', '"}'), '\',
'', [rfReplaceAll]);
TThread.Synchronize(TThread.CurrentThread,
procedure
begin
MainForm.ActivityIndicator1.Animate := False;
vcodeForm.ShowModal;
end);
end
else
begin
TThread.Synchronize(TThread.CurrentThread,
procedure
begin
MainForm.Memo1.Lines.Add('百度真实地址为(8小时有效):' + realUrl);
MainForm.Edit2.Text := realUrl;
end);
IdSSLIOHandlerSocketOpenSSL1.DisposeOf;
Fidhttp.DisposeOf;
end;
except
on e: exception do
TThread.Synchronize(TThread.CurrentThread,
procedure
begin
MainForm.Memo1.Lines.Add(e.Message);
end);
end;
finally
TThread.Synchronize(TThread.CurrentThread,
procedure
begin
MainForm.ActivityIndicator1.Animate := False;
MainForm.Button1.Enabled := True;
end);
postinstr.DisposeOf;
end;
end;
下载3次会弹出验证码
var
postinstr2: TstringList;
VcodUrl: string;
begin
try
try
postinstr2 := TstringList.Create;
postinstr2.Add('encrypt=' + '0');
postinstr2.Add('fid_list=[' + fid_list + ']');
postinstr2.Add('path_list=');
postinstr2.Add('primaryid=' + primaryid);
postinstr2.Add('product=' + 'share');
postinstr2.Add('uk=' + uk);
postinstr2.Add('vcode_input=' + vcode_input);
postinstr2.Add('vcode_str=' + vcode_str);
postResult2 := Fidhttp.Post(apiurl, postinstr2);
realUrl := StringReplace(GetMidString(postResult2, 'dlink":"', '",'), '\',
'', [rfReplaceAll]);
if realUrl <> '' then
TThread.Synchronize(TThread.CurrentThread,
procedure
begin
MainForm.Memo1.Lines.Add('百度真实地址为(8小时有效):' + realUrl);
MainForm.Edit2.Text := realUrl;
end)
else
TThread.Synchronize(TThread.CurrentThread,
procedure
begin
MainForm.Memo1.Lines.Add('获取失败,请尝试重新获取');
end)
except
on e: exception do
TThread.Synchronize(TThread.CurrentThread,
procedure
begin
MainForm.Memo1.Lines.Add(e.Message);
end);
end;
finally
TThread.Synchronize(TThread.CurrentThread,
procedure
begin
MainForm.ActivityIndicator1.Animate := False;
MainForm.Button1.Enabled := True;
postinstr2.DisposeOf;
end);
end;
end;
相关下载
点击下载