Realize QQ robot Alarm

Source: Internet
Author: User

Title, nonsense not to say, directly on the code. The first is to login QQ small script

#!/usr/bin/perluse webqq::client;use data::D umper;use digest::md5 qw (Md5_hex); Use LWP ::useragent;use json;my  $qq  = qq,;my  $pwd  = md5_hex (' qq password ');my  $client  = webqq::client->new (debug=>0), #等于1开启debug ############ #验证码 ############## $client->load (" Postimgverifycode "); $client->on_input_img_verifycode ()  = sub{    my  ($ Img_verifycode_file)  = @_;    my  $smtp  = {         smtp    => ' mailbox SMTP server ',         user    => ' Email user ',         Pass    => ' email pass ',        from     => ' Email address ',        to       = ' Email address ',         from_title =>  ' QQ robot ',         subject =>  ' Verification code ',     };    return &{$ Client->plugin ("Postimgverifycode")} ($client, $img _verifycode_file, $SMTP);}; ##################################### #登录QQ的时候可能会用到验证码, need to be sent in the form of mail to the mailbox, open the message inside the link address to submit. $client->login ( qq=>  $qq, pwd =>  $pwd);sub tuling{     my  $info  = $_[0];    my  $UA  = LWP::UserAgent->new;     my  $response  =  $UA->get ("  #这里调用的事图灵机器人接口   Intelligent Dialog features   Use the words   go to apply for the address   do not delete the function      my  $str  =  $response->content;     my  $json  = new JSON;    my  $json _obj  =  $json->decode ("$str");    return  $json _OBJ-&GT {' Text '}} $client->on_receive_message = sub{    my  $msg  = shift;my  $group _uin =  $msg->{from_uin};if  ($msg->{content} =~ m! (. *) @ Little silly (. *)!)  {   #定义 @ What content will trigger the following reply here is defined by the @ Little fool   can make changes as needed my  $msg _content = $1 . $2; my  $s _msg_content = tuling ("$msg _content");my  $s _msg =  $client->create_group_ MSG (to_uin=> "$group _uin", content=>  "$s _msg_content"); $client->send_group_message ($s _msg);}}; $client->load ("Openqq"), $client->on_run = sub{$client->call ("openqq",host=> "0.0.0.0", port=>5000);   # #这里是开启api, after opening the local will listen to a port   send a query through the port a series of operations}; $client->run ();
# #之后就是调用api发送qq消息的脚本啦   below #!/usr/bin/perluse strict;use warnings;use lwp::useragent;use  JSON;use URI::Escape;sub get_gid {    my  $group _name =  $_[0];    my  $UA  = lwp::useragent->new;    my   $response  =  $UA->get ("  #定义api地址    only need to replace ip    my  $STR  =  $response->content;    my  $json  = new JSON;     my  $json _obj =  $json->decode ("$str");    foreach  my  $group   (@{  $json _obj }) {if  ($group->{' ginfo '}->{' name '} eq  ' $group _name ") {return  $group->{' ginfo '}->{' gid '} ;}} sub send_qq_mess {    my  $content  = $_[0];     my  $gid  = get_gid ($_[1]);     my $ua = lwp::useragent->new;    my  $response  =  $UA->get ("   #定义api地址   only need to replace ip    return  $response->content;} my  $c  = uri_escape ($ARGV [0]);p rint send_qq_mess ($c, "Monitoring_alarm")  ;  #   Here Monitoring_alarm refers to the name of the group to send the alarm    must be the group QQ is located

The first script to run the words Plus nohup no person verification code will be lost in the TMP directory will not send mail QQ login Success Check whether to listen to the 5000 port (can be changed), everything OK to execute the second script, for example, the name is send, then the execution format is send your_send_content Then you just defined the group name of the group will receive the message this script because there are APIs can be arbitrarily called, the novice perl big God do not laughed at.


Finally thanks to the Webqq::client module provider.


This article is from the "perling" blog, make sure to keep this source http://zhaolin.blog.51cto.com/9397923/1630115

Realize QQ robot Alarm

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.