Created
February 7, 2015 09:45
-
-
Save wxg4net/b8a2e79b75ba09a06826 to your computer and use it in GitHub Desktop.
初始化好友在线状态
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# _get_online_list_info.pm | |
use JSON; | |
use Webqq::Client::Util qw(console); | |
sub Webqq::Client::_get_online_list_info { | |
my $self = shift; | |
return undef if $self->{type} ne 'smartqq'; | |
my $ua = $self->{ua}; | |
my $api_url = 'http://d.web2.qq.com/channel/get_online_buddies2'; | |
my %r = ( | |
vfwebqq => $self->{qq_param}{vfwebqq}, | |
clientid => $self->{qq_param}{clientid}, | |
psessionid => $self->{qq_param}{psessionid}, | |
t => time(), | |
); | |
my @headers = (Referer => 'http://s.web2.qq.com/proxy.html?v=20130916001&callback=1&id=1'); | |
my $response = $ua->post($api_url,[r=>JSON->new->utf8->encode(\%r)], @headers); | |
if($response->is_success){ | |
my $json; | |
eval{ | |
$json = JSON->new->utf8->decode($response->content()) ; | |
}; | |
if($self->{debug}){ | |
console $@."\n" if $@; | |
} | |
return undef if $json->{retcode} !=0; | |
my $online_list = $json->{result}; | |
return $online_list; | |
} | |
else{return undef;} | |
} | |
1; | |
# 更新函数 | |
sub update_online_info { | |
my $self = shift; | |
console "更新在线状态列表信息...\n"; | |
my $online_list_info = $self->_get_online_list_info(); | |
if(defined $online_list_info){ | |
my %online_list; | |
for(@{ $online_list_info }) { | |
$online_list{$_->{uin}} = $_; | |
} | |
for(@{ $self->{qq_database}{friends} }){ | |
my $uin = $_->{uin}; | |
my $typeid = $online_list{$uin}{client_type}; | |
$_->{status} = $online_list{$uin}{status}; | |
$_->{client_type} = $self->{client_type}{$typeid} | |
? $self->{client_type}{$typeid} | |
: '未知('.$typeid.')'; | |
} | |
} | |
else{console "更新在线状态列表信息失败\n";} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment