delphi对接滑块打码
时间: 2023-10-01 12:09:49 浏览: 201
要对接滑块验证码识别,可以使用第三方的打码平台来实现。以下是一个使用易源云打码平台的 Delphi 示例代码:
```delphi
unit Unit1;
interface
uses
Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics, Vcl.Controls, Vcl.Forms,
Vcl.Dialogs, IdBaseComponent, IdComponent, IdTCPConnection, IdTCPClient, IdHTTP, Vcl.StdCtrls, IdURI;
type
TForm1 = class(TForm)
Image1: TImage;
IdHTTP1: TIdHTTP;
Button1: TButton;
Memo1: TMemo;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
function PostData(AURL: string; AFields: TStrings): string;
var
HTTP: TIdHTTP;
Params: TStringList;
begin
Result := '';
Params := TStringList.Create;
try
Params.AddStrings(AFields);
HTTP := TIdHTTP.Create(nil);
try
Result := HTTP.Post(AURL, Params);
except
on E: Exception do
Result := E.Message;
end;
finally
Params.Free;
HTTP.Free;
end;
end;
procedure TForm1.Button1Click(Sender: TObject);
var
Resp: string;
Params: TStringList;
URL: string;
Base64Str: string;
begin
// 获取验证码图片
IdHTTP1.Get('https://www.xxx.com/getcaptcha.php', Image1.Picture.Bitmap);
// 识别验证码
Params := TStringList.Create;
try
Base64Str := '';
Image1.Picture.Bitmap.SaveToStream(TMemoryStream(Params), TEncoding.ASCII);
Base64Str := EncodeString(Params.DataString);
URL := 'http://api.ysdm.net/create.json';
Params.Clear;
Params.Add('username=用户名');
Params.Add('password=密码');
Params.Add('appid=1');
Params.Add('appkey=22cc5376925e9387a23cf797cb9ba745');
Params.Add('yzmtype=1');
Params.Add('timeout=60');
Params.Add('codetype=2003');
Params.Add('len_min=0');
Params.Add('len_max=0');
Params.Add('file_base64=' + Base64Str);
Resp := PostData(URL, Params);
Memo1.Lines.Add(Resp);
finally
Params.Free;
end;
end;
end.
```
其中,`TImage` 控件用于显示验证码图片,`IdHTTP1` 组件用于获取验证码图片,`Memo1` 控件用于显示识别结果。在 `Button1Click` 事件中,先获取验证码图片,然后将图片转成 Base64 字符串,再调用易源云打码平台的 API 进行识别,并将结果显示到 `Memo1` 控件中。需要替换的地方是用户名、密码和易源云打码平台的 appkey。
阅读全文