line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package WebService::Antigate::V2;
|
2
|
|
|
|
|
|
|
|
3
|
2
|
|
|
2
|
|
828
|
use strict;
|
|
2
|
|
|
|
|
5
|
|
|
2
|
|
|
|
|
69
|
|
4
|
2
|
|
|
2
|
|
598
|
use JSON::PP;
|
|
2
|
|
|
|
|
11759
|
|
|
2
|
|
|
|
|
254
|
|
5
|
2
|
|
|
2
|
|
781
|
use MIME::Base64;
|
|
2
|
|
|
|
|
1296
|
|
|
2
|
|
|
|
|
121
|
|
6
|
2
|
|
|
2
|
|
14
|
use parent 'WebService::Antigate';
|
|
2
|
|
|
|
|
3
|
|
|
2
|
|
|
|
|
30
|
|
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
sub new {
|
9
|
1
|
|
|
1
|
1
|
559
|
my ($class, %args) = @_;
|
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
# change some defaults
|
12
|
1
|
50
|
|
|
|
5
|
$args{scheme} = 'https' unless defined $args{scheme};
|
13
|
1
|
50
|
|
|
|
3
|
$args{subdomain} = 'api.' unless defined $args{subdomain};
|
14
|
|
|
|
|
|
|
|
15
|
1
|
|
|
|
|
8
|
$class->SUPER::new(%args);
|
16
|
|
|
|
|
|
|
}
|
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
sub try_upload {
|
19
|
1
|
|
|
1
|
1
|
2
|
my ($self, %opts) = @_;
|
20
|
|
|
|
|
|
|
|
21
|
1
|
50
|
|
|
|
4
|
if ( defined $opts{file} ) {
|
22
|
1
|
|
|
|
|
2
|
$opts{content} = do {
|
23
|
1
|
|
|
|
|
9
|
local $/;
|
24
|
|
|
|
|
|
|
open my $fh, '<:raw', $opts{file}
|
25
|
1
|
50
|
|
|
|
35
|
or Carp::croak "open `$opts{file}': ", $!;
|
26
|
1
|
|
|
|
|
56
|
<$fh>;
|
27
|
|
|
|
|
|
|
};
|
28
|
|
|
|
|
|
|
}
|
29
|
|
|
|
|
|
|
|
30
|
1
|
50
|
|
|
|
4
|
if ( defined $opts{content} ) {
|
31
|
1
|
|
|
|
|
10
|
$opts{body} = encode_base64( $opts{content}, '' );
|
32
|
|
|
|
|
|
|
}
|
33
|
|
|
|
|
|
|
|
34
|
1
|
50
|
33
|
|
|
5
|
if ( defined $opts{body} && !defined $opts{type} ) {
|
35
|
1
|
|
|
|
|
3
|
$opts{type} = 'ImageToTextTask';
|
36
|
|
|
|
|
|
|
}
|
37
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
my $response = $self->{ua}->post(
|
39
|
|
|
|
|
|
|
"$self->{scheme}://$self->{subdomain}$self->{domain}/createTask",
|
40
|
|
|
|
|
|
|
Content => encode_json {
|
41
|
|
|
|
|
|
|
clientKey => $self->{key},
|
42
|
|
|
|
|
|
|
exists $opts{softId} ? ( softId => delete $opts{softId} ) : (),
|
43
|
1
|
50
|
|
|
|
33
|
exists $opts{languagePool} ? ( languagePool => delete $opts{languagePool} ) : (),
|
|
|
50
|
|
|
|
|
|
44
|
|
|
|
|
|
|
task => {
|
45
|
|
|
|
|
|
|
%opts
|
46
|
|
|
|
|
|
|
}
|
47
|
|
|
|
|
|
|
}
|
48
|
|
|
|
|
|
|
);
|
49
|
|
|
|
|
|
|
|
50
|
1
|
50
|
|
|
|
149011
|
unless($response->is_success) {
|
51
|
0
|
|
|
|
|
0
|
$self->{errno} = 'HTTP_ERROR';
|
52
|
0
|
|
|
|
|
0
|
$self->{errstr} = $response->status_line;
|
53
|
0
|
|
|
|
|
0
|
return undef;
|
54
|
|
|
|
|
|
|
}
|
55
|
|
|
|
|
|
|
|
56
|
1
|
|
|
|
|
25
|
my $result = decode_json $response->decoded_content;
|
57
|
1
|
50
|
|
|
|
12834
|
if ($result->{errorId}) {
|
58
|
0
|
|
|
|
|
0
|
$self->{errno} = $result->{errorCode};
|
59
|
0
|
|
|
|
|
0
|
$self->{errstr} = $result->{errorDescription};
|
60
|
0
|
|
|
|
|
0
|
return undef;
|
61
|
|
|
|
|
|
|
}
|
62
|
|
|
|
|
|
|
|
63
|
1
|
|
|
|
|
38
|
return $self->{last_captcha_id} = $result->{taskId};
|
64
|
|
|
|
|
|
|
}
|
65
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
sub try_recognize {
|
67
|
5
|
|
|
5
|
1
|
24
|
my ($self, $id) = @_;
|
68
|
|
|
|
|
|
|
|
69
|
5
|
50
|
|
|
|
35
|
Carp::croak "Captcha id should be specified" unless defined $id;
|
70
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
my $response = $self->{ua}->post(
|
72
|
|
|
|
|
|
|
"$self->{scheme}://$self->{subdomain}$self->{domain}/getTaskResult",
|
73
|
|
|
|
|
|
|
Content => encode_json {
|
74
|
|
|
|
|
|
|
clientKey => $self->{key},
|
75
|
5
|
|
|
|
|
102
|
taskId => $id
|
76
|
|
|
|
|
|
|
}
|
77
|
|
|
|
|
|
|
);
|
78
|
|
|
|
|
|
|
|
79
|
5
|
50
|
|
|
|
31614
|
unless($response->is_success) {
|
80
|
0
|
|
|
|
|
0
|
$self->{errno} = 'HTTP_ERROR';
|
81
|
0
|
|
|
|
|
0
|
$self->{errstr} = $response->status_line;
|
82
|
0
|
|
|
|
|
0
|
return undef;
|
83
|
|
|
|
|
|
|
}
|
84
|
|
|
|
|
|
|
|
85
|
5
|
|
|
|
|
76
|
my $result = decode_json $response->decoded_content;
|
86
|
5
|
100
|
|
|
|
6105
|
if ($result->{errorId}) {
|
87
|
1
|
|
|
|
|
5
|
$self->{errno} = $result->{errorCode};
|
88
|
1
|
|
|
|
|
3
|
$self->{errstr} = $result->{errorDescription};
|
89
|
1
|
|
|
|
|
21
|
return undef;
|
90
|
|
|
|
|
|
|
}
|
91
|
|
|
|
|
|
|
|
92
|
4
|
100
|
|
|
|
18
|
if ($result->{status} ne 'ready') {
|
93
|
2
|
|
|
|
|
6
|
$self->{errno} = 'CAPCHA_NOT_READY';
|
94
|
2
|
|
|
|
|
6
|
$self->{errstr} = 'captcha is not recognized yet';
|
95
|
2
|
|
|
|
|
58
|
return undef;
|
96
|
|
|
|
|
|
|
}
|
97
|
|
|
|
|
|
|
|
98
|
2
|
|
|
|
|
7
|
for my $key ( qw/text gRecaptchaResponse token/ ) {
|
99
|
2
|
50
|
|
|
|
30
|
return $result->{solution}{$key} if exists $result->{solution}{$key};
|
100
|
|
|
|
|
|
|
}
|
101
|
|
|
|
|
|
|
|
102
|
0
|
|
|
|
|
0
|
return $result->{solution};
|
103
|
|
|
|
|
|
|
}
|
104
|
|
|
|
|
|
|
|
105
|
|
|
|
|
|
|
sub abuse {
|
106
|
2
|
|
|
2
|
1
|
7
|
my ($self, $id) = @_;
|
107
|
|
|
|
|
|
|
|
108
|
2
|
50
|
|
|
|
8
|
Carp::croak "Captcha id should be specified" unless defined $id;
|
109
|
|
|
|
|
|
|
|
110
|
|
|
|
|
|
|
my $response = $self->{ua}->post(
|
111
|
|
|
|
|
|
|
"$self->{scheme}://$self->{subdomain}$self->{domain}/reportIncorrectImageCaptcha",
|
112
|
|
|
|
|
|
|
Content => encode_json {
|
113
|
|
|
|
|
|
|
clientKey => $self->{key},
|
114
|
2
|
|
|
|
|
19
|
taskId => $id
|
115
|
|
|
|
|
|
|
}
|
116
|
|
|
|
|
|
|
);
|
117
|
|
|
|
|
|
|
|
118
|
2
|
50
|
|
|
|
10445
|
unless($response->is_success) {
|
119
|
0
|
|
|
|
|
0
|
$self->{errno} = 'HTTP_ERROR';
|
120
|
0
|
|
|
|
|
0
|
$self->{errstr} = $response->status_line;
|
121
|
0
|
|
|
|
|
0
|
return undef;
|
122
|
|
|
|
|
|
|
}
|
123
|
|
|
|
|
|
|
|
124
|
2
|
|
|
|
|
25
|
my $result = decode_json $response->decoded_content;
|
125
|
2
|
100
|
|
|
|
2734
|
if ($result->{errorId}) {
|
126
|
1
|
50
|
|
|
|
6
|
if ($result->{errorCode}) {
|
127
|
1
|
|
|
|
|
6
|
$self->{errno} = $result->{errorCode};
|
128
|
1
|
|
|
|
|
22
|
$self->{errstr} = $result->{errorDescription};
|
129
|
|
|
|
|
|
|
}
|
130
|
|
|
|
|
|
|
else {
|
131
|
0
|
|
|
|
|
0
|
$self->{errno} = 'ERROR_NO_SUCH_CAPCHA_ID';
|
132
|
0
|
|
|
|
|
0
|
$self->{errstr} = 'no such captcha id in the database';
|
133
|
|
|
|
|
|
|
}
|
134
|
1
|
|
|
|
|
13
|
return undef;
|
135
|
|
|
|
|
|
|
}
|
136
|
|
|
|
|
|
|
|
137
|
1
|
|
|
|
|
14
|
return $result->{status};
|
138
|
|
|
|
|
|
|
}
|
139
|
|
|
|
|
|
|
|
140
|
|
|
|
|
|
|
sub balance {
|
141
|
2
|
|
|
2
|
1
|
5
|
my $self = shift;
|
142
|
|
|
|
|
|
|
|
143
|
|
|
|
|
|
|
my $response = $self->{ua}->post(
|
144
|
|
|
|
|
|
|
"$self->{scheme}://$self->{subdomain}$self->{domain}/getBalance",
|
145
|
|
|
|
|
|
|
Content => encode_json {
|
146
|
|
|
|
|
|
|
clientKey => $self->{key},
|
147
|
|
|
|
|
|
|
}
|
148
|
2
|
|
|
|
|
15
|
);
|
149
|
|
|
|
|
|
|
|
150
|
2
|
50
|
|
|
|
10047
|
unless($response->is_success) {
|
151
|
0
|
|
|
|
|
0
|
$self->{errno} = 'HTTP_ERROR';
|
152
|
0
|
|
|
|
|
0
|
$self->{errstr} = $response->status_line;
|
153
|
0
|
|
|
|
|
0
|
return undef;
|
154
|
|
|
|
|
|
|
}
|
155
|
|
|
|
|
|
|
|
156
|
2
|
|
|
|
|
26
|
my $result = decode_json $response->decoded_content;
|
157
|
2
|
100
|
|
|
|
2350
|
if ($result->{errorId}) {
|
158
|
1
|
|
|
|
|
4
|
$self->{errno} = $result->{errorCode};
|
159
|
1
|
|
|
|
|
3
|
$self->{errstr} = $result->{errorDescription};
|
160
|
1
|
|
|
|
|
12
|
return undef;
|
161
|
|
|
|
|
|
|
}
|
162
|
|
|
|
|
|
|
|
163
|
1
|
|
|
|
|
12
|
return $result->{balance};
|
164
|
|
|
|
|
|
|
}
|
165
|
|
|
|
|
|
|
|
166
|
|
|
|
|
|
|
1;
|
167
|
|
|
|
|
|
|
|
168
|
|
|
|
|
|
|
__END__
|