line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
sub Mojo::Webqq::Model::_get_user_friends{ |
2
|
0
|
|
|
0
|
|
|
my $self = shift; |
3
|
0
|
|
|
|
|
|
my $callback = shift; |
4
|
0
|
|
|
|
|
|
my $api_url = 'http://s.web2.qq.com/api/get_user_friends2'; |
5
|
0
|
|
|
|
|
|
my $headers = { |
6
|
|
|
|
|
|
|
Referer=>'http://s.web2.qq.com/proxy.html?v=20130916001&callback=1&id=1', |
7
|
|
|
|
|
|
|
json=>1, |
8
|
|
|
|
|
|
|
ua_request_timeout => $self->model_update_timeout, |
9
|
|
|
|
|
|
|
ua_retry_times => 3, |
10
|
|
|
|
|
|
|
}; |
11
|
0
|
|
|
|
|
|
my %r = ( |
12
|
|
|
|
|
|
|
hash => $self->hash($self->ptwebqq,$self->uid), |
13
|
|
|
|
|
|
|
vfwebqq => $self->vfwebqq, |
14
|
|
|
|
|
|
|
); |
15
|
|
|
|
|
|
|
|
16
|
0
|
0
|
|
|
|
|
my $is_blocking = ref $callback eq "CODE"?0:1; |
17
|
|
|
|
|
|
|
my $handle = sub{ |
18
|
0
|
|
|
0
|
|
|
my $json = shift; |
19
|
0
|
|
|
|
|
|
my $friends_state = shift; |
20
|
0
|
0
|
|
|
|
|
return undef unless defined $json; |
21
|
0
|
0
|
|
|
|
|
return undef if $json->{retcode}!=0 ; |
22
|
0
|
|
|
|
|
|
my %categories ; |
23
|
|
|
|
|
|
|
my %info; |
24
|
0
|
|
|
|
|
|
my %marknames; |
25
|
0
|
|
|
|
|
|
my %vipinfo; |
26
|
0
|
|
|
|
|
|
my %state; |
27
|
0
|
0
|
0
|
|
|
|
if(defined $friends_state and ref $friends_state eq "ARRAY"){ |
28
|
0
|
|
|
|
|
|
for(@{$friends_state}){ |
|
0
|
|
|
|
|
|
|
29
|
0
|
|
|
|
|
|
$state{$_->{uin}}{state} = $_->{state}; |
30
|
0
|
|
|
|
|
|
$state{$_->{uin}}{client_type} = $_->{client_type}; |
31
|
|
|
|
|
|
|
} |
32
|
|
|
|
|
|
|
} |
33
|
0
|
|
|
|
|
|
for(@{ $json->{result}{categories}}){ |
|
0
|
|
|
|
|
|
|
34
|
0
|
|
|
|
|
|
$categories{ $_->{'index'} } = {'sort'=>$_->{'sort'},name=>$_->{name} }; |
35
|
|
|
|
|
|
|
} |
36
|
0
|
0
|
|
|
|
|
$categories{0} = {sort=>0,name=>'我的好友'} if not defined $categories{0}; |
37
|
0
|
|
|
|
|
|
for(@{ $json->{result}{info}}){ |
|
0
|
|
|
|
|
|
|
38
|
0
|
|
|
|
|
|
$info{$_->{uin}} = {face=>$_->{face},flag=>$_->{flag},nick=>$_->{nick}}; |
39
|
|
|
|
|
|
|
} |
40
|
0
|
|
|
|
|
|
for(@{ $json->{result}{marknames} }){ |
|
0
|
|
|
|
|
|
|
41
|
0
|
|
|
|
|
|
$marknames{$_->{uin}} = {markname=>$_->{markname},type=>$_->{type}}; |
42
|
|
|
|
|
|
|
} |
43
|
0
|
|
|
|
|
|
for(@{ $json->{result}{vipinfo} }){ |
|
0
|
|
|
|
|
|
|
44
|
0
|
|
|
|
|
|
$vipinfo{$_->{u}} = {vip_level=>$_->{vip_level},is_vip=>$_->{is_vip}}; |
45
|
|
|
|
|
|
|
} |
46
|
0
|
|
|
|
|
|
for(@{$json->{result}{friends}}){ |
|
0
|
|
|
|
|
|
|
47
|
0
|
|
|
|
|
|
my $uin = $_->{uin}; |
48
|
0
|
0
|
|
|
|
|
if(exists $state{$_->{uin}}){ |
49
|
0
|
|
|
|
|
|
$_->{state} = $state{$uin}{state}; |
50
|
0
|
|
|
|
|
|
$_->{client_type} = $state{$uin}{client_type}; |
51
|
|
|
|
|
|
|
} |
52
|
|
|
|
|
|
|
else{ |
53
|
0
|
|
|
|
|
|
$_->{state} = 'offline'; |
54
|
0
|
|
|
|
|
|
$_->{client_type} = 'unknown'; |
55
|
|
|
|
|
|
|
} |
56
|
0
|
|
|
|
|
|
$_->{category} = $self->xmlescape_parse($categories{$_->{categories}}{name}); |
57
|
0
|
|
|
|
|
|
$_->{name} = $self->xmlescape_parse($info{$uin}{nick}); |
58
|
0
|
|
|
|
|
|
$_->{face} = $info{$uin}{face}; |
59
|
0
|
|
|
|
|
|
$_->{markname} = $self->xmlescape_parse($marknames{$uin}{markname}); |
60
|
0
|
|
|
|
|
|
$_->{is_vip} = $vipinfo{$uin}{is_vip}; |
61
|
0
|
|
|
|
|
|
$_->{vip_level} = $vipinfo{$uin}{vip_level}; |
62
|
0
|
|
|
|
|
|
delete $_->{categories}; |
63
|
0
|
|
|
|
|
|
$_->{id} = delete $_->{uin}; |
64
|
|
|
|
|
|
|
} |
65
|
0
|
|
|
|
|
|
return $json->{result}{friends}; |
66
|
0
|
|
|
|
|
|
}; |
67
|
0
|
0
|
|
|
|
|
if($is_blocking){ |
68
|
0
|
|
|
|
|
|
my $json = $self->http_post($api_url,$headers,form=>{r=>$self->to_json(\%r)},); |
69
|
0
|
|
|
|
|
|
my $friends_state = $self->_get_friends_state(); |
70
|
0
|
|
|
|
|
|
return $handle->($json,$friends_state); |
71
|
|
|
|
|
|
|
} |
72
|
|
|
|
|
|
|
else{ |
73
|
|
|
|
|
|
|
$self->steps( |
74
|
|
|
|
|
|
|
sub{ |
75
|
0
|
|
|
0
|
|
|
my $delay = shift; |
76
|
0
|
|
|
|
|
|
$self->http_post($api_url,$headers,form=>{r=>$self->to_json(\%r)},$delay->begin(0,1)); |
77
|
0
|
|
|
|
|
|
$self->_get_friends_state($delay->begin(0,1)); |
78
|
|
|
|
|
|
|
}, |
79
|
|
|
|
|
|
|
sub{ |
80
|
0
|
|
|
0
|
|
|
my($delay,$json,$friends_state) = @_; |
81
|
0
|
0
|
|
|
|
|
$callback->( $handle->($json,$friends_state) ) if ref $callback eq "CODE"; |
82
|
|
|
|
|
|
|
}, |
83
|
0
|
|
|
|
|
|
); |
84
|
|
|
|
|
|
|
} |
85
|
|
|
|
|
|
|
} |
86
|
|
|
|
|
|
|
1; |