Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- unit antigate;
- interface
- uses HTTPSend, SSL_OpenSSL, Classes, SysUtils, SynAUtil;
- function Recognize(capa: TMemoryStream; Key:string; rucaptcha:boolean):string;
- function RecognizeRC(SiteKey, PageURL, APIKey:string; rucaptcha:boolean):string;
- const
- CRLF=#$0D#$0A;
- sleep_ms = 5000;
- implementation
- function GetFormValue(Bound, Parametr, Value:String): String;
- begin
- Result:='--'+Bound+CRLF+'Content-Disposition: form-data; name="'+Parametr+'"'+CRLF+CRLF+Value+CRLF;
- end;
- function Recognize(capa: TMemoryStream; Key:string; rucaptcha:boolean):string;
- var Bound, ftype, s, CaptchaID, url:string; soft_id:integer;
- i:Integer;
- Resp:TStringList;
- Image:TMemoryStream;
- HTTP:THTTPSend;
- begin
- ftype:='image/png';
- if rucaptcha then begin
- url:='http://rucaptcha.com/';
- soft_id:=902;
- end else begin
- url:='http://antigate.com/';
- soft_id:=362;
- end;
- Resp:=TStringList.Create;
- Image:=TMemoryStream.Create;
- Image.LoadFromStream(capa);
- HTTP:=THTTPSend.Create;
- Randomize;
- Bound:='-----' +IntToHex(random(65535), 8)+'_boundary';
- Resp.Text:=GetFormValue(Bound, 'method', 'post');
- Resp.Text:=Resp.Text+GetFormValue(Bound, 'key', key);
- Resp.Text:=Resp.Text+GetFormValue(Bound, 'soft_id', IntToStr(soft_id));
- Resp.Text:=Resp.Text+'--'+Bound+CRLF;
- Resp.Text:=Resp.Text+'Content-Disposition: form-data; name="file"; filename="image.gif"'+CRLF+'Content-Type: '+ftype+CRLF+CRLF;
- WriteStrToStream(HTTP.Document, Resp.Text);
- HTTP.Document.CopyFrom(Image, 0);
- Resp.Text:=CRLF+'--'+Bound+'--'+CRLF;
- WriteStrToStream(HTTP.Document, Resp.Text);
- HTTP.MimeType:='multipart/form-data; boundary='+Bound;
- if (HTTP.HTTPMethod('POST', url+'in.php')) then begin
- Resp.LoadFromStream(HTTP.Document);
- s:=Resp.Strings[0];
- Result:=s;
- CaptchaID:='';
- if (Pos('ERROR_', s) < 1) then begin
- if (Pos('OK|', s) > 0) then CaptchaID:=StringReplace(s, 'OK|', '', [rfReplaceAll]);
- if (CaptchaID <> '') then begin
- Result:=CaptchaID;
- for i:=0 to 20 do begin
- Sleep(sleep_ms);
- HTTP.Clear;
- if (HTTP.HTTPMethod('GET', url+'res.php?key='+key+'&action=get&id='+CaptchaID)) then begin
- Resp.LoadFromStream(HTTP.Document);
- s:=Resp.Strings[0];
- if (Pos('ERROR_', s) > 0) then begin
- result:= s;
- break;
- end;
- if (Pos('OK|', s) > 0) then begin
- result:=StringReplace(s, 'OK|', '', [rfReplaceAll]);
- break;
- end;
- end;
- result:= 'ERROR_TIMEOUT';
- end;
- end else result:= 'ERROR_BAD_CAPTCHA_ID';
- end;
- end else result:= 'ERROR_CONNECT';
- Resp.Free;
- Image.Free;
- HTTP.Free;
- end;
- function Pars(T_, ForS, _T:string):string;
- var a, b:integer;
- begin
- Result := '';
- if (T_='') or (ForS='') or (_T='') then Exit;
- a:=Pos(T_, ForS);
- if a=0 then Exit else a:=a+Length(T_);
- ForS:=Copy(ForS, a, Length(ForS)-a+1);
- b:=Pos(_T, ForS);
- if b>0 then
- Result:=Copy(ForS, 1, b - 1);
- end;
- function RecognizeRC(SiteKey, PageURL, APIKey:string; rucaptcha:boolean):string;
- var page, CaptchaID:string; soft_id, i:integer;
- Resp:TStringList; send:TStringStream; HTTP:THTTPSend;
- begin
- if rucaptcha then begin
- soft_id:=902;
- end else begin
- soft_id:=362;
- end;
- case soft_id of
- 902:begin
- HTTP:=THTTPSend.Create;
- HTTP.Protocol:='1.1';
- HTTP.HTTPMethod('GET', 'http://rucaptcha.com/in.php?soft_id='+IntToStr(soft_id)+'&key='+APIKey+'&method=userrecaptcha&googlekey='+SiteKey+'&pageurl='+PageURL);
- Resp:=TStringList.Create;
- Resp.LoadFromStream(HTTP.Document);
- CaptchaID:=Copy(Resp[0], 4, Length(Resp[0]));
- Resp.Free;
- HTTP.Free;
- for i:=0 to 20 do begin
- sleep(sleep_ms);
- HTTP:=THTTPSend.Create;
- HTTP.Protocol:='1.1';
- HTTP.HTTPMethod('GET', 'http://rucaptcha.com/res.php?key='+APIKey+'&action=get&id='+CaptchaID);
- Resp:=TStringList.Create;
- Resp.LoadFromStream(HTTP.Document);
- result:=Resp[0];
- Resp.Free;
- HTTP.Free;
- if pos('OK|', result)>0 then begin
- Delete(result, 1, 3);
- break;
- end;
- end;
- end;
- 362:begin
- Resp:=TStringList.Create;
- HTTP:=THTTPSend.Create;
- HTTP.AddPortNumberToHost:=false;
- HTTP.Protocol:='1.1';
- HTTP.MimeType:='application/x-www-form-urlencoded';
- send:=TStringStream.Create('');
- send.WriteString('{'+
- '"clientKey":"'+APIKey+'",'+
- '"task":{'+
- '"type":"NoCaptchaTaskProxyless",'+
- '"websiteURL":"'+StringReplace(PageURL, '/', '\/', [rfReplaceAll])+'",'+
- '"websiteKey":"'+SiteKey+'"'+
- '},'+
- '"softId":'+IntToStr(soft_id)+','+
- '"languagePool":"en"'+
- '}');
- HTTP.Document.LoadFromStream(send);
- send.Free;
- if (HTTP.HTTPMethod('POST', 'https://api.anti-captcha.com/createTask')) then begin
- Resp.LoadFromStream(HTTP.Document);
- page:=StringReplace(Resp[0], ' ', '', [rfReplaceAll]);
- if pos('"errorId":0', page)>0 then begin
- CaptchaID:=Pars('"taskId":', page, '}');
- send:=TStringStream.Create('');
- send.WriteString('{"clientKey":"'+APIKey+'","taskId":'+CaptchaID+'}');
- for i:=0 to 20 do begin
- sleep(sleep_ms);
- HTTP.Document.Clear;
- HTTP.Headers.Clear;
- HTTP.Document.LoadFromStream(send);
- HTTP.HTTPMethod('POST', 'https://api.anti-captcha.com/getTaskResult');
- Resp:=TStringList.Create;
- Resp.LoadFromStream(HTTP.Document);
- page:=Resp.Text;
- Resp.Free;
- if pos('"status":"ready"', page)>0 then begin
- result:=Pars('"gRecaptchaResponse":"', page, '"');
- break;
- end;
- end;
- send.Free;
- end else begin
- result:= 'ERROR_'+Pars('"errorId":', page, ',');
- end;
- end else result:= 'ERROR_CONNECT';
- HTTP.Free;
- end;
- end;
- end;
- end.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement