| 1 | 1 | ▶ | use JSON; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 2 | 1 | ▶ | use Webqq::Client::Util qw(hash); | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 3 | 0 | ▶ | sub Webqq::Client::_get_user_friends{ | ||||||||
|
Subroutine
_get_user_friends: not called CC=14 SCAR=53.5
| |||||||||||
| 4 | 0 | my $self = shift; | |||||||||
| 5 | 0 | my $api_url = 'http://s.web2.qq.com/api/get_user_friends2'; | |||||||||
| 6 | 0 | my $ua = $self->{ua}; | |||||||||
| 7 | 0 | ▶ | my @headers = $self->{type} eq 'webqq'? (Referer=>'http://s.web2.qq.com/proxy.html?v=20110412001&callback=1&id=3') | ||||||||
|
Branch: 1 branch
| |||||||||||
| 8 | : (Referer=>'http://s.web2.qq.com/proxy.html?v=20130916001&callback=1&id=1') | ||||||||||
| 9 | ; | ||||||||||
| 10 | my %r = ( | ||||||||||
| 11 | hash => hash($self->{qq_param}{ptwebqq},$self->{qq_param}{qq}), | ||||||||||
| 12 | vfwebqq => $self->{qq_param}{vfwebqq}, | ||||||||||
| 13 | 0 | ); | |||||||||
| 14 | 0 | ▶ | if($self->{type} eq 'webqq'){ | ||||||||
|
Branch: 1 branch
| |||||||||||
| 15 | 0 | $r{"h"} = "hello"; | |||||||||
| 16 | } | ||||||||||
| 17 | 0 | my $response = $ua->post($api_url,[r=>JSON->new->utf8->encode(\%r)],@headers); | |||||||||
| 18 | 0 | ▶ | if($response->is_success){ | ||||||||
|
Branch: 1 branch
| |||||||||||
| 19 | 0 | ▶ | print $response->content(),"\n" if $self->{debug}; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 20 | 0 | my $json = JSON->new->utf8->decode($response->content()); | |||||||||
| 21 | 0 | ▶ | return undef if $json->{retcode}!=0 ; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 22 | 0 | my $friends_state = $self->_get_friends_state(); | |||||||||
| 23 | 0 | my %categories ; | |||||||||
| 24 | my %info; | ||||||||||
| 25 | 0 | my %marknames; | |||||||||
| 26 | 0 | my %vipinfo; | |||||||||
| 27 | 0 | my %state; | |||||||||
| 28 | 0 | ▶ | if(defined $friends_state){ | ||||||||
|
Branch: 1 branch
| |||||||||||
| 29 | 0 | for(@{$friends_state}){ | |||||||||
| 30 | 0 | $state{$_->{uin}}{state} = $_->{state}; | |||||||||
| 31 | 0 | $state{$_->{uin}}{client_type} = $_->{client_type}; | |||||||||
| 32 | } | ||||||||||
| 33 | } | ||||||||||
| 34 | 0 | for(@{ $json->{result}{categories}}){ | |||||||||
| 35 | 0 | $categories{ $_->{'index'} } = {'sort'=>$_->{'sort'},name=>encode("utf8",$_->{name}) }; | |||||||||
| 36 | } | ||||||||||
| 37 | 0 | $categories{0} = {sort=>0,name=>'我的好友'}; | |||||||||
| 38 | 0 | for(@{ $json->{result}{info}}){ | |||||||||
| 39 | 0 | $info{$_->{uin}} = {face=>$_->{face},flag=>$_->{flag},nick=>encode("utf8",$_->{nick}),}; | |||||||||
| 40 | } | ||||||||||
| 41 | 0 | for(@{ $json->{result}{marknames} }){ | |||||||||
| 42 | 0 | $marknames{$_->{uin}} = {markname=>encode("utf8",$_->{markname}),type=>$_->{type}}; | |||||||||
| 43 | } | ||||||||||
| 44 | 0 | for(@{ $json->{result}{vipinfo} }){ | |||||||||
| 45 | 0 | $vipinfo{$_->{u}} = {vip_level=>$_->{vip_level},is_vip=>$_->{is_vip}}; | |||||||||
| 46 | } | ||||||||||
| 47 | 0 | for(@{$json->{result}{friends}}){ | |||||||||
| 48 | 0 | my $uin = $_->{uin}; | |||||||||
| 49 | 0 | ▶ | if(exists $state{$_->{uin}}){ | ||||||||
|
Branch: 1 branch
| |||||||||||
| 50 | 0 | $_->{state} = $state{$uin}{state}; | |||||||||
| 51 | 0 | $_->{client_type} = $state{$uin}{client_type}; | |||||||||
| 52 | } | ||||||||||
| 53 | else{ | ||||||||||
| 54 | 0 | $_->{state} = 'offline'; | |||||||||
| 55 | 0 | $_->{client_type} = 'unknown'; | |||||||||
| 56 | } | ||||||||||
| 57 | 0 | $_->{categorie} = $categories{$_->{categories}}{name}; | |||||||||
| 58 | 0 | $_->{nick} = $info{$uin}{nick}; | |||||||||
| 59 | 0 | $_->{face} = $info{$uin}{face}; | |||||||||
| 60 | 0 | $_->{markname} = $marknames{$uin}{markname}; | |||||||||
| 61 | 0 | $_->{is_vip} = $vipinfo{$uin}{is_vip}; | |||||||||
| 62 | 0 | $_->{vip_level} = $vipinfo{$uin}{vip_level}; | |||||||||
| 63 | 0 | delete $_->{categories}; | |||||||||
| 64 | } | ||||||||||
| 65 | 0 | return $json->{result}{friends}; | |||||||||
| 66 | } | ||||||||||
| 67 | 0 | else{return undef} | |||||||||
| 68 | } | ||||||||||
| 69 | 1 | 1; | |||||||||