|
1
|
|
|
<?php |
|
2
|
|
|
namespace LaravelAnticaptcha\Anticaptcha; |
|
3
|
|
|
|
|
4
|
|
|
class ImageToText extends Anticaptcha implements AntiCaptchaTaskProtocol { |
|
5
|
|
|
|
|
6
|
|
|
private $body; |
|
7
|
|
|
private $phrase = false; |
|
8
|
|
|
private $case = false; |
|
9
|
|
|
private $numeric = false; |
|
10
|
|
|
private $math = 0; |
|
11
|
|
|
private $minLength = 0; |
|
12
|
|
|
private $maxLength = 0; |
|
13
|
|
|
|
|
14
|
|
|
|
|
15
|
|
|
public function getPostData() { |
|
16
|
|
|
return array( |
|
17
|
|
|
"type" => "ImageToTextTask", |
|
18
|
|
|
"body" => str_replace("\n", "", $this->body), |
|
19
|
|
|
"phrase" => $this->phrase, |
|
20
|
|
|
"case" => $this->case, |
|
21
|
|
|
"numeric" => $this->numeric, |
|
22
|
|
|
"math" => $this->math, |
|
23
|
|
|
"minLength" => $this->minLength, |
|
24
|
|
|
"maxLength" => $this->maxLength |
|
25
|
|
|
); |
|
26
|
|
|
} |
|
27
|
|
|
|
|
28
|
|
|
public function getTaskSolution() { |
|
29
|
|
|
return $this->taskInfo->solution->text; |
|
30
|
|
|
} |
|
31
|
|
|
|
|
32
|
|
|
public function setFile($fileName) { |
|
33
|
|
|
|
|
34
|
|
|
if (file_exists($fileName)) { |
|
35
|
|
|
|
|
36
|
|
|
if (filesize($fileName) > 100) { |
|
37
|
|
|
$this->body = base64_encode(file_get_contents($fileName)); |
|
38
|
|
|
return true; |
|
39
|
|
|
} else { |
|
40
|
|
|
$this->setErrorMessage("file $fileName too small or empty"); |
|
41
|
|
|
} |
|
42
|
|
|
|
|
43
|
|
|
} else { |
|
44
|
|
|
$this->setErrorMessage("file $fileName not found"); |
|
45
|
|
|
} |
|
46
|
|
|
return false; |
|
47
|
|
|
|
|
48
|
|
|
} |
|
49
|
|
|
|
|
50
|
|
|
public function setPhraseFlag($value) { |
|
51
|
|
|
$this->phrase = $value; |
|
52
|
|
|
} |
|
53
|
|
|
|
|
54
|
|
|
public function setCaseFlag($value) { |
|
55
|
|
|
$this->case = $value; |
|
56
|
|
|
} |
|
57
|
|
|
|
|
58
|
|
|
public function setNumericFlag($value) { |
|
59
|
|
|
$this->numeric = $value; |
|
60
|
|
|
} |
|
61
|
|
|
|
|
62
|
|
|
public function setMathFlag($value) { |
|
63
|
|
|
$this->math = $value; |
|
64
|
|
|
} |
|
65
|
|
|
|
|
66
|
|
|
public function setMinLengthFlag($value) { |
|
67
|
|
|
$this->minLength = $value; |
|
68
|
|
|
} |
|
69
|
|
|
|
|
70
|
|
|
public function setMaxLengthFlag($value) { |
|
71
|
|
|
$this->maxLength = $value; |
|
72
|
|
|
} |
|
73
|
|
|
|
|
74
|
|
|
} |
|
75
|
|
|
|