Skip to content

Instantly share code, notes, and snippets.

@shalk
Created April 23, 2015 05:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save shalk/b5f82af7c3e9da32c632 to your computer and use it in GitHub Desktop.
Save shalk/b5f82af7c3e9da32c632 to your computer and use it in GitHub Desktop.
use Webqq::Client;
use Digest::MD5 qw(md5_hex);
my $qq = 171214273;
my $pwd = md5_hex('XXXXXXXX');
#通过new来初始化一个客户端对象
##debug=>1来打印debug信息方便调试
my $client = Webqq::Client->new(debug=>0);
#
# #通过login进行登录
$client->login( qq=> $qq, pwd => $pwd);
$client->on_receive_message = sub{
#当收到消息后,传递给回调函数的唯一参数是原始消息的一个hash引用
my $msg = shift;
#你可以对收到的消息进行任意的处理
#你也可以使用Data::Dumper这样的模块来查看消息的结构,比如
use Data::Dumper;
print Dumper $msg;
};
for my $each_friend (@{ $client->{qq_database}{friends} }) {
if( $each_friend->{nick} eq "宝儿" ){
print "宝儿所属的分组是:",$each_friend->{categories},"\n"
}
}
my $gid ;
for my $each_group (@{ $client->{qq_database}{group_list} }){
if($each_group->{number} eq "69188942" ){
$gid = $each_group->{gid}
}
}
if($gid){
$client->send_group_message(
$client->create_group_msg(to_uin=>$gid, content=>"hello world")
);
}
#客户端进入事件循环,正式开始运行
$client->run();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment