[APPEARANCE]
COLOR = 155, 20, 40;
SIZE_X = 8;
SIZE_Y =4;
[END]

[INTERFACE]
DIALOG, "Решение текстовой капчи rucaptcha.com или anti-captcha.com", 704, 260;
STATIC, "Капча в", 4, 4, 48, 20;
COMBO, "Активный по Экрану""Активный по Указателю""Фоновый по Указателю""По Скриншоту", 60, 4, 164, 100, int EW;
STATIC, "Указатель на окно", 240, 4, 100, 20;
EDIT, 344, 4, 116, 20, win W;
STATIC, "Указатель на скрин", 480, 4, 104, 20;
EDIT, 592, 4, 100, 20, int Screen;
STATIC, "Ключ в", 4, 28, 40, 20;
COMBO, "rucaptcha.com" "anti-captcha.com", 48, 28, 160, 80, string SERV;
EDIT, 212, 28, 480, 20, string Key;
STATIC, "Максимальное время ожидания", 4, 52, 168, 20;
EDIT, 176, 52, 100, 20, int T;
STATIC, "Зона капчи старт", 4, 76, 96, 20;
EDIT, 104, 76, 116, 20, int eX1;
EDIT, 224, 76, 116, 20, int eY1;
STATIC, "Зона капчи финиш", 352, 76, 100, 20;
EDIT, 456, 76, 116, 20, int eX2;
EDIT, 576, 76, 116, 20, int eY2;
CHECK, "Совершить математическое действие с цифрами на капче", 4, 100, 328, 20, int Mach;
CHECK, "Учитывать регистр", 360, 100, 128, 20, int REGSENSE;
STATIC, "Дополнительный комментарий для работника разгадывающего капчу", 4, 124, 360, 20;
EDIT, 368, 124, 324, 20, string COMM;
STATIC, "Решенная капча в", 4, 148, 96, 20;
EDIT, 104, 148, 160, 20, string Rez;
STATIC, "Комментарий", 4, 172, 76, 20;
EDIT, 84, 172, 608, 20, unknown Comment;
BUTTON_OK, "Принять", 488, 204, 100, 20;
BUTTON_CANCEL, "Закрыть", 592, 204, 100, 20;
[END]

[INFO]
[ENDL]>>Comment
[END]

[ASSOC_NUMBER]
Path
[END]

[ASSOC_VAR]
EW=0;
W=W_Kib;
Screen=Screen;
SERV="rucaptcha.com";
Key="dce6bcbb1a728ea8d563de6d169a2057";
T=60000;
eX1=300;
eY1=500;
eX2=580;
eY2=610;
Mach=0;
REGSENSE=1;
COMM="";
Rez=T_Captcha;
W_V = #~W~;
V_X=~W~.leftclient;
V_Y=~W~.topclient;
V_Screen=#~Screen~;
V_Rez=#~Rez~;
Comment=;
[END]

[GLOBAL_VAR]
win ~W~;
int ~Screen~[3000][3000];  
string ~Rez~;
[END]

[EVENT]
IF (I_MODE_BIND_WINDOW!=0)SENDBUTTON(GETID(EW), S_MODE_BIND_WINDOW);
IF (I_MODE_BIND_WINDOW!=0)SENDEDIT(GETID(W), W_Kib);
IF (I_MODE_BIND_WINDOW!=0)ENABLE(GETID(EW), 0);
IF (I_MODE_BIND_WINDOW!=0)ENABLE(GETID(W), 0);
IF (I_MODE_BIND_WINDOW!=0)ENABLE(GETID(Screen), 0);
[END]

[FUNCTION_BODY]
function(int ew, int #Scr, win #w, int v_x, int v_y, string serv, int t, string KEY, int regsense, int mach, string comm, string #Ot, int sx, int sy, int fx, int fy)
{
if (ew==0) savescreen(JPG, pathfolder()+"temp_capcha.jpg", sx, sy, fx, fy, -1);
if (ew==1) savescreen(JPG, pathfolder()+"temp_capcha.jpg", v_x+sx, v_y+sy, v_x+fx, v_y+fy, -1);
if (ew==2) savescreen(JPG, pathfolder()+"temp_capcha.jpg", sx, sy, fx, fy, w);
if (ew==3) saveimage(JPG, #Scr[0][0], pathfolder()+"temp_capcha.jpg", sx, sy, fx, fy);
char BYTE[200000];
int size_file=0;
string id;
string Header;
string REZ;
  if (serv=="anti-captcha.com")
  {
    if (fopen (pathfolder()+"temp_capcha.jpg", "rb")!=0)
    {
    size_file=freadb(#BYTE[0], 200000);
    fclose();
    }
    else return -5;
  string file64=base64code (#BYTE[0], size_file);
  string Mach="false";
  if (mach)Mach="true";
  string json;
  json="{^"clientKey^":^""+KEY+"^"," +
  "^"task^":{^"type^":^"ImageToTextTask^"" +
  ",^"body^":^""+file64+"^",^"math^":"+Mach+",";
  json=json+"^"minLength^":0,^"maxLength^":0";
  if (comm!="")json=json+",^"comment^":^""+ansitoutf8(comm)+"^"";
  if (regsense)json=json+",^"case^":^"true^"";
  else json=json+",^"case^":^"false^"";
  json=json+"}}";
  int aW=size(json);
  strcpy(#BYTE[0], json);
  Header="Content-Type: application/x-www-form-urlencoded";
  int K=0;
  A: sendgetweb(#REZ, "My bot", "POST", "http:/^/api.anti-captcha.com", "createTask", Header, #BYTE[0], aW);
    if (parserjson(Rez_Json, REZ)!=1)
    {
      if (K>2)
      {
      Ot="Не подключились к сервису";
      return -1;
      }
    K++;
    pause(2000);
    goto A;
    }
    if (Rez_Json.errorId=="0")
    {
    id=Rez_Json.taskId;
    pause(3000);
    if (t==0) t=1;
      looptime(t)
      {
      pause(2000);
      json="{^"clientKey^":^""+KEY+"^",^"taskId^": "+id+"}";
      aW=size(json);
      strcpy(#BYTE[0], json);
      sendgetweb(#REZ, "My bot", "POST", "http:/^/api.anti-captcha.com", "getTaskResult", Header, #BYTE[0], aW);
      if (parserjson(Rez_Json, REZ)!=1)continue;
        if (Rez_Json.errorId!="0")
        {
        Ot=Rez_Json.errorId;
        return -2;
        }
        if (Rez_Json.status=="ready")
        {
        Ot=Rez_Json.solution.text;
        return 1;
        }
      }
    }
    else
    {
    Ot=Rez_Json.errorCode;
    return -3;
    }
  Ot="Ошибка";
  return -4;
  }
  if (serv=="rucaptcha.com")
  {
  string H="--kibor-post^r^n";
  H=H+"Content-Disposition: form-data; name=^"method^"^r^n^r^n";
  H=H+"post^r^n";
  H=H+"--kibor-post^r^n";
  H=H+"Content-Disposition: form-data; name=^"key^"^r^n^r^n";
  H=H+KEY+"^r^n";
    if (comm!="")
    {
    H=H+"--kibor-post^r^n";
    H=H+"Content-Disposition: form-data; name=^"textinstructions^"^r^n^r^n";
    H=H+ansitoutf8(comm)+"^r^n";
    }
    if (regsense)
    {
    H=H+"--kibor-post^r^n";
    H=H+"Content-Disposition: form-data; name=^"regsense^"^r^n^r^n";
    H=H+"1^r^n";
    }
    if (mach)
    {
    H=H+"--kibor-post^r^n";
    H=H+"Content-Disposition: form-data; name=^"calc^"^r^n^r^n";
    H=H+"1^r^n";
    }
  H=H+"--kibor-post^r^n";
  H=H+"Content-Disposition: form-data; name=^"file^"; filename=^"temp_capcha.jpg^"^r^n";
  H=H+"Content-Type: image/jpeg^r^n^r^n";
  strcpy(#BYTE[0], H);
  int S=size(H);
    if (fopen (pathfolder()+"temp_capcha.jpg", "rb")!=0)
    {
    size_file=freadb(#BYTE[S], 200000-S);
    fclose();
    }
    else return -5;
  size_file=size_file+S;
  strcpy(#BYTE[size_file], "^r^n--kibor-post");
  size_file=size_file+14;
  Header="Content-Type: multipart/form-data; boundary=kibor-post";
    if (sendgetweb(#REZ, "My bot", "POST", "https:/^/rucaptcha.com", "in.php", Header, #BYTE[0], size_file))
    {
    if (regexsearch(1, #id, REZ, "(?<=OK\|)(\d+)")==0){Ot=REZ; return -1;}
    pause(3000);
    if (t==0) t=1;
      looptime(t)
      {
      pause(2000);  
        if (sendgetweb(#REZ, "My bot", "POST", "https:/^/rucaptcha.com", "res.php?key="+KEY+"&action=get&id="+id))
        {
        if (regexsearch(1, #Ot, REZ, "ERROR")){Ot=REZ; return -6;}
          if (regexsearch(1, #Ot, REZ, "(?<=OK\|)(.*)+"))
          {
          Ot=utf8toansi(Ot);
          return 1;
          }
        }
      }
    }
    else
    {
    Ot=REZ;
    return -3;
    }
  Ot="Ошибка";
  return -4;
  }
}
[END]

[CALL]
(EW, V_Screen[0][0], W_V, V_X, V_Y, SERV, T, Key, REGSENSE, Mach, COMM, V_Rez, eX1, eY1, eX2, eY2)
[END]

[FUNCTION_LOGIC]  
>0
[END]








