line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package WebService::DeathByCaptcha; |
2
|
|
|
|
|
|
|
|
3
|
1
|
|
|
1
|
|
44554
|
use strict; |
|
1
|
|
|
|
|
9
|
|
|
1
|
|
|
|
|
22
|
|
4
|
1
|
|
|
1
|
|
20
|
use 5.008_005; |
|
1
|
|
|
|
|
3
|
|
5
|
|
|
|
|
|
|
our $VERSION = '0.02'; |
6
|
|
|
|
|
|
|
|
7
|
1
|
|
|
1
|
|
5
|
use Carp 'croak'; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
34
|
|
8
|
1
|
|
|
1
|
|
403
|
use LWP::UserAgent; |
|
1
|
|
|
|
|
33688
|
|
|
1
|
|
|
|
|
28
|
|
9
|
1
|
|
|
1
|
|
379
|
use JSON; |
|
1
|
|
|
|
|
6710
|
|
|
1
|
|
|
|
|
5
|
|
10
|
1
|
|
|
1
|
|
102
|
use Try::Tiny; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
41
|
|
11
|
|
|
|
|
|
|
|
12
|
1
|
|
|
1
|
|
4
|
use vars qw/$errstr/; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
352
|
|
13
|
0
|
|
|
0
|
0
|
|
sub errstr { $errstr } |
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
sub new { |
16
|
0
|
|
|
0
|
0
|
|
my $class = shift; |
17
|
0
|
0
|
|
|
|
|
my %args = @_ % 2 ? %{$_[0]} : @_; |
|
0
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
|
19
|
0
|
0
|
|
|
|
|
$args{username} or croak "username is required.\n"; |
20
|
0
|
0
|
|
|
|
|
$args{password} or croak "password is required.\n"; |
21
|
0
|
|
0
|
|
|
|
$args{ua} ||= LWP::UserAgent->new; |
22
|
0
|
|
|
|
|
|
$args{ua}->default_header('Accept' => 'application/json'); |
23
|
0
|
|
0
|
|
|
|
$args{url} ||= 'http://api.dbcapi.me/api/captcha'; |
24
|
0
|
|
0
|
|
|
|
$args{sleep} ||= 3; |
25
|
|
|
|
|
|
|
|
26
|
0
|
|
|
|
|
|
return bless \%args, $class; |
27
|
|
|
|
|
|
|
} |
28
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
sub recaptcha { |
30
|
0
|
|
|
0
|
0
|
|
my $self = shift; |
31
|
0
|
0
|
|
|
|
|
my %params = @_ % 2 ? %{$_[0]} : @_; |
|
0
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
|
33
|
0
|
0
|
|
|
|
|
$params{googlekey} or croak "googlekey is required.\n"; |
34
|
0
|
0
|
|
|
|
|
$params{pageurl} or croak "pageurl is required.\n"; |
35
|
|
|
|
|
|
|
|
36
|
0
|
|
|
|
|
|
return $self->request( |
37
|
|
|
|
|
|
|
__method => 'POST', |
38
|
|
|
|
|
|
|
type => 4, |
39
|
|
|
|
|
|
|
token_params => encode_json(\%params) |
40
|
|
|
|
|
|
|
); |
41
|
|
|
|
|
|
|
} |
42
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
sub get { |
44
|
0
|
|
|
0
|
0
|
|
my ($self, $id) = @_; |
45
|
|
|
|
|
|
|
|
46
|
0
|
|
|
|
|
|
return $self->request( |
47
|
|
|
|
|
|
|
url => "http://api.dbcapi.me/api/captcha/$id" |
48
|
|
|
|
|
|
|
); |
49
|
|
|
|
|
|
|
} |
50
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
sub request { |
52
|
0
|
|
|
0
|
0
|
|
my ($self, %params) = @_; |
53
|
|
|
|
|
|
|
|
54
|
0
|
|
0
|
|
|
|
$params{username} ||= $self->{username}; |
55
|
0
|
|
0
|
|
|
|
$params{password} ||= $self->{password}; |
56
|
0
|
|
0
|
|
|
|
my $url = delete $params{url} || $self->{url}; |
57
|
|
|
|
|
|
|
|
58
|
0
|
|
|
|
|
|
my $res; |
59
|
0
|
|
0
|
|
|
|
my $method = delete $params{__method} || 'GET'; |
60
|
0
|
0
|
|
|
|
|
if ($method eq 'POST') { |
61
|
0
|
|
|
|
|
|
$res = $self->{ua}->post($url, \%params); |
62
|
|
|
|
|
|
|
} else { |
63
|
0
|
|
|
|
|
|
my $uri = URI->new($url); |
64
|
0
|
|
|
|
|
|
$uri->query_form(%params); |
65
|
0
|
|
|
|
|
|
$res = $self->{ua}->get($uri->as_string); |
66
|
|
|
|
|
|
|
} |
67
|
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
# print Dumper(\$res); use Data::Dumper; |
69
|
|
|
|
|
|
|
|
70
|
0
|
|
|
0
|
|
|
my $res = try { decode_json($res->content) }; |
|
0
|
|
|
|
|
|
|
71
|
0
|
0
|
|
|
|
|
return $res if $res; |
72
|
|
|
|
|
|
|
|
73
|
0
|
|
|
|
|
|
$errstr = "Failed to $method $url: " . $res->status_line; |
74
|
0
|
|
|
|
|
|
return; |
75
|
|
|
|
|
|
|
} |
76
|
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
1; |
78
|
|
|
|
|
|
|
__END__ |