line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package XiaoI;
|
2
|
|
|
|
|
|
|
|
3
|
1
|
|
|
1
|
|
2340
|
use 5.008005;
|
|
1
|
|
|
|
|
4
|
|
|
1
|
|
|
|
|
41
|
|
4
|
1
|
|
|
1
|
|
5
|
use strict;
|
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
28
|
|
5
|
1
|
|
|
1
|
|
4
|
use warnings;
|
|
1
|
|
|
|
|
5
|
|
|
1
|
|
|
|
|
30
|
|
6
|
1
|
|
|
1
|
|
1254
|
use JSON;
|
|
1
|
|
|
|
|
19884
|
|
|
1
|
|
|
|
|
6
|
|
7
|
|
|
|
|
|
|
require Exporter;
|
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
our @ISA = qw(Exporter);
|
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
our $VERSION = '0.03';
|
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
# Preloaded methods go here.
|
15
|
1
|
|
|
1
|
|
1287
|
use LWP::UserAgent;
|
|
1
|
|
|
|
|
63133
|
|
|
1
|
|
|
|
|
40
|
|
16
|
1
|
|
|
1
|
|
1419
|
use Encode qw/encode decode/;
|
|
1
|
|
|
|
|
17040
|
|
|
1
|
|
|
|
|
96
|
|
17
|
1
|
|
|
1
|
|
1015
|
use Data::Dumper;
|
|
1
|
|
|
|
|
6516
|
|
|
1
|
|
|
|
|
723
|
|
18
|
|
|
|
|
|
|
sub new {
|
19
|
1
|
|
|
1
|
0
|
9
|
my ($class) = @_;
|
20
|
1
|
|
|
|
|
10
|
my $ua = LWP::UserAgent->new;
|
21
|
1
|
|
|
|
|
3950
|
$ua->cookie_jar({});
|
22
|
|
|
|
|
|
|
|
23
|
1
|
|
|
|
|
9480
|
my $self = {ua => $ua};
|
24
|
1
|
|
|
|
|
4
|
bless $self, $class;
|
25
|
1
|
|
|
|
|
6
|
$self->login;
|
26
|
1
|
|
|
|
|
5
|
return $self;
|
27
|
|
|
|
|
|
|
}
|
28
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
sub login {
|
32
|
1
|
|
|
1
|
0
|
2
|
my $self = shift;
|
33
|
1
|
|
|
|
|
9
|
my $ua = $self->{ua};
|
34
|
1
|
|
|
|
|
6
|
my $login_page = $ua->get('http://webbot.xiaoi.com/engine/flashrobot2/webbot.js?encoding=utf-8')->content;
|
35
|
1
|
50
|
|
|
|
75782
|
if ($login_page =~ m{L_IDS_SEND_MESSAGE_URL\s*=\s*"(.*?)";.*?L_IDS_RECV_MESSAGE_URL\s*=\s*"(.*?)";.*?L_IDS_GET_RESOURCE_URL\s*=\s*"(.*?)";.*?__sessionId\s*=\s*"(.*?)";}is) {
|
36
|
0
|
|
|
|
|
0
|
my ($send_url, $recv_url, $resource_url, $sessionid) = ($1, $2, $3, $4);
|
37
|
0
|
|
|
|
|
0
|
$self->{send_url} = $send_url;
|
38
|
0
|
|
|
|
|
0
|
$self->{recv_url} = $recv_url;
|
39
|
0
|
|
|
|
|
0
|
$self->{resource_url} = $resource_url;
|
40
|
0
|
|
|
|
|
0
|
$self->{sessionid} = $sessionid;
|
41
|
0
|
|
|
|
|
0
|
my $res = $ua->get( $self->join_url());
|
42
|
|
|
|
|
|
|
|
43
|
0
|
|
|
|
|
0
|
$self->{last_login_time} = time;
|
44
|
|
|
|
|
|
|
} else {
|
45
|
1
|
|
|
|
|
11
|
print "login failed\n";
|
46
|
|
|
|
|
|
|
}
|
47
|
|
|
|
|
|
|
}
|
48
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
sub check_need_login {
|
50
|
0
|
|
|
0
|
0
|
|
my $self = shift;
|
51
|
0
|
0
|
|
|
|
|
if (time - $self->{last_login_time} > 60 * 60 * 5 ) {
|
52
|
0
|
|
|
|
|
|
$self->login;
|
53
|
|
|
|
|
|
|
}
|
54
|
|
|
|
|
|
|
}
|
55
|
|
|
|
|
|
|
|
56
|
|
|
|
|
|
|
sub get_robot_text {
|
57
|
0
|
|
|
0
|
0
|
|
my $self = shift;
|
58
|
0
|
|
|
|
|
|
my $msg = shift;
|
59
|
0
|
|
|
|
|
|
my $try_times = 5;
|
60
|
0
|
|
|
|
|
|
my $text;
|
61
|
0
|
|
|
|
|
|
for (1..$try_times) {
|
62
|
0
|
|
|
|
|
|
$text = $self->_invoke_robot($msg);
|
63
|
0
|
0
|
|
|
|
|
if ($text eq '') {
|
64
|
0
|
|
|
|
|
|
$self->login;
|
65
|
|
|
|
|
|
|
} else {
|
66
|
0
|
|
|
|
|
|
last;
|
67
|
|
|
|
|
|
|
}
|
68
|
|
|
|
|
|
|
}
|
69
|
0
|
|
|
|
|
|
return $text;
|
70
|
|
|
|
|
|
|
}
|
71
|
|
|
|
|
|
|
sub _invoke_robot {
|
72
|
0
|
|
|
0
|
|
|
my $self = shift;
|
73
|
0
|
|
|
|
|
|
my $msg = shift;
|
74
|
|
|
|
|
|
|
|
75
|
|
|
|
|
|
|
#$self->check_need_login;
|
76
|
0
|
|
|
|
|
|
my $ua = $self->{ua};
|
77
|
0
|
|
|
|
|
|
my $res = $ua->get( $self->send_message_url($msg));
|
78
|
0
|
0
|
|
|
|
|
return '' if ($res->code ne '200');
|
79
|
0
|
|
|
|
|
|
$res = $ua->get( $self->recv_message_url());
|
80
|
0
|
0
|
|
|
|
|
return '' if ($res->code ne '200');
|
81
|
0
|
|
|
|
|
|
my $text = $res->content;
|
82
|
0
|
0
|
|
|
|
|
if ($text =~ m{processMessageReceived\((.*)\)}s) {
|
83
|
0
|
|
|
|
|
|
my $json_text = $1;
|
84
|
0
|
|
|
|
|
|
my $ra = JSON->new->utf8(0)->decode($json_text);
|
85
|
0
|
0
|
0
|
|
|
|
if (@$ra > 0 and $ra->[0]->{CMD} eq 'CHAT') {
|
86
|
0
|
|
|
|
|
|
return encode('utf8', decode('utf8', $ra->[0]->{MSG}) );
|
87
|
|
|
|
|
|
|
}
|
88
|
|
|
|
|
|
|
}
|
89
|
|
|
|
|
|
|
|
90
|
0
|
|
|
|
|
|
return '';
|
91
|
|
|
|
|
|
|
}
|
92
|
|
|
|
|
|
|
|
93
|
|
|
|
|
|
|
|
94
|
|
|
|
|
|
|
sub join_url {
|
95
|
0
|
|
|
0
|
0
|
|
my $self = shift;
|
96
|
0
|
|
|
|
|
|
my $url = sprintf('%sSID=%s&USR=%s&CMD=JOIN&r=0.%s', $self->{send_url}, $self->{sessionid}, $self->{sessionid}, int(rand(100000)));
|
97
|
|
|
|
|
|
|
|
98
|
|
|
|
|
|
|
}
|
99
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
sub send_message_url {
|
101
|
0
|
|
|
0
|
0
|
|
my $self = shift;
|
102
|
0
|
|
|
|
|
|
my $msg = shift;
|
103
|
0
|
|
|
|
|
|
my $url = sprintf('%sSID=%s&USR=%s&CMD=CHAT&MSG=%s&r=0.%s', $self->{send_url}, $self->{sessionid}, $self->{sessionid}, $msg, int(rand(100000)));
|
104
|
|
|
|
|
|
|
|
105
|
|
|
|
|
|
|
}
|
106
|
|
|
|
|
|
|
|
107
|
|
|
|
|
|
|
sub recv_message_url {
|
108
|
0
|
|
|
0
|
0
|
|
my $self = shift;
|
109
|
|
|
|
|
|
|
|
110
|
0
|
|
|
|
|
|
my $url = sprintf('%sSID=%s&USR=%s&r=0.%s', $self->{recv_url}, $self->{sessionid}, $self->{sessionid},int(rand(100000)) );
|
111
|
|
|
|
|
|
|
|
112
|
|
|
|
|
|
|
}
|
113
|
|
|
|
|
|
|
|
114
|
|
|
|
|
|
|
1;
|
115
|
|
|
|
|
|
|
__END__
|