@@ -13,16 +13,16 @@ class ImageToText extends Uncaptcha{
1313 private $ maxLength = 0 ;
1414 private $ language = 0 ;
1515
16- function genTaskPost ( ): array {
16+ function genCreateTaskPost ( array $ post = [] ): array {
1717 switch ($ this ->v ){
1818 case 1 :
1919 $ post = [
20- 'type ' => 'base64 ' ,
21- 'body ' => str_replace ( "\n" , '' , $ this ->body ) ,
20+ 'method ' => 'base64 ' ,
21+ 'body ' => $ this ->body ,
2222 'phrase ' => (int )$ this ->phrase ,
2323 'regsense ' => (int )$ this ->case ,
2424 'numeric ' => $ this ->numeric ,
25- 'math ' => (bool )$ this ->math ,
25+ 'calc ' => (int )$ this ->math ,
2626 'min_len ' => $ this ->minLength ,
2727 'max_len ' => $ this ->maxLength ,
2828 'language ' => $ this ->language
@@ -39,7 +39,7 @@ function genTaskPost(): array{
3939 case 2 :
4040 $ post = [
4141 'type ' => 'ImageToTextTask ' ,
42- 'body ' => str_replace ( "\n" , '' , $ this ->body ) ,
42+ 'body ' => $ this ->body ,
4343 'phrase ' => $ this ->phrase ,
4444 'case ' => $ this ->case ,
4545 'numeric ' => $ this ->numeric ,
@@ -51,66 +51,68 @@ function genTaskPost(): array{
5151 break ;
5252 }
5353
54- return parent ::genTaskPost ($ post );
54+ $ this ->debugLog ('<img src="data:image/jpeg;base64, ' .$ this ->body .'"> ' );
55+
56+ return parent ::genCreateTaskPost ($ post );
5557 }
5658
5759 function setBody (string $ base64Data ): void {
5860 $ this ->body = $ base64Data ;
5961 }
6062
6163 function setBodyFromFile (string $ fileName ): bool {
62- if (!file_exists ($ fileName )){
63- $ this ->setErrorMessage ("File $ fileName not found " );
64-
65- return false ;
66- }
64+ $ this ->body = base64_encode (file_get_contents ($ fileName ));
6765
68- if (filesize ( $ fileName ) > 100 ){
66+ if (strlen ( $ this -> body ) < 100 ){
6967 $ this ->setErrorMessage ("File $ fileName too small " );
7068
7169 return false ;
7270 }
7371
74- $ this ->body = base64_encode (file_get_contents ($ fileName ));
75-
7672 return (bool )$ this ->body ;
7773 }
7874
79- function setPhraseFlag (bool $ phrase ): void {
75+ function setPhrase (bool $ phrase ): void {
8076 $ this ->phrase = $ phrase ;
8177 }
8278
83- function setCaseFlag (bool $ case ): void {
79+ function setCase (bool $ case ): void {
8480 $ this ->case = $ case ;
8581 }
8682
87- function setNumericFlag (int $ numeric ): void {
83+ function setNumeric (int $ numeric ): void {
8884 $ this ->numeric = $ numeric ;
8985 }
9086
91- function setMathFlag (bool $ value ): void {
87+ function setMath (bool $ value ): void {
9288 $ this ->math = $ value ;
9389 }
9490
95- function setMinLengthFlag (int $ minLength ): void {
91+ function setMinLength (int $ minLength ): void {
9692 $ this ->minLength = $ minLength ;
9793 }
9894
99- function setMaxLengthFlag (int $ maxLength ): void {
95+ function setMaxLength (int $ maxLength ): void {
10096 $ this ->maxLength = $ maxLength ;
10197 }
10298
10399 function setLanguage (int $ language ): void {
104100 $ this ->language = $ language ;
105101 }
106102
107- function reportBad (){
108- if ($ this ->v == 1 ) return parent ::reportBad ();
103+ function reportBad (): ?bool {
104+ if (
105+ $ this ->v == 1 or
106+ $ this ->host != 'api.anti-captcha.com '
107+ ) return parent ::reportBad ();
109108
110109 if ($ this ->v == 2 ){
111- if (!$ this ->taskid ) throw new Exception ('Task does not exists ' );
110+ if (!$ this ->taskId ) return $ this ->setErrorMessage ('Task does not exists ' );
111+
112+ $ label = $ this ->genDebugLabel ();
113+ $ this ->debugLog ("<b>Captcha reportBad</b>: $ label / $ this ->taskId " );
112114
113- return $ this ->call ('reportIncorrectImageCaptcha ' , ['taskId ' => $ this ->taskid ]);
115+ return ( bool ) $ this ->call ('reportIncorrectImageCaptcha ' , ['taskId ' => $ this ->taskId ]);
114116 }
115117 }
116118
0 commit comments