• 利用微信机器人,自动发送验证码


    <pre name="code" class="sql"> use Weixin::Client;
     use Encode;
     #目前只能用于群回复
        my $client = Weixin::Client->new(debug=>0);
    
        #加载ShowMsg插件,用于打印消息
        $client->load("ShowMsg");
    
        #客户端登录
        $client->login();   
    
        #设置客户端接收消息回调函数
        $client->on_receive_msg = sub{
    	     my $msg = shift ;
    	    # my ($client,$msg)=@_;
    	## 消息内容
    
            #打印收到的消息
    	 $client->call("ShowMsg",$msg);
    	$recm= $msg->{Content};
        $recm=encode("gbk",decode("utf8","$recm"));  
    if   ($recm =~/中均s+d{11}/i){
            $recm =~ s/^s+//;
            $number =(split(/s+/,"$recm"))[1];
    $i=0;
    @arr=();
    @tmp1=();
    @tmp2=();
    use Encode;
    
    open (LOG1 ,"<",'\\192.168.32.101log01zj-api01-catalina.out') or die  $!;
                        while (<LOG1>) {
                      
    					 
    					if (($_ =~/$number/) and ($_ =~/SMSSendThread/i) ){$str=encode("gbk",decode("utf8","$_"));
    						       # print "$str is $str
    ";
    						 next if ($str !~ /验证/);
    					push (@tmp1 ,$str);
    					}};
    					
    					close LOG1;
    					
    					
    					
    					open (LOG2 ,"<",'\\192.168.32.101log01zj-api02-catalina.out') or die  $!;
                        while (<LOG2>) {
                      
    					 
    					if (($_ =~/$number/) and ($_ =~/SMSSendThread/i)  ){$str=encode("gbk",decode("utf8","$_"));
    						        print "$str is $str
    ";
    							 next if ($str !~ /验证/);
    					push (@tmp2  ,$str);
    					}};
    					
    						close LOG2;
    					#print "$tmp1[-1] is $tmp1[-1]
    ";
    					
    					#print "$tmp2[-1] is $tmp2[-1]
    ";
    		@arr=($tmp1[-1], $tmp2[-1]);			
    			print "@arr is @arr
    ";		
    
    if  (defined($tmp1[-1]) or  defined($tmp2[-1])){
    
    foreach (@arr){  
    ##2015-11-04 15:51:54,134 DEBUG com.zjzc.thirdparty.sms.SMSSendThread 
       if ($_ =~  /([0-9]{4}-[0-9]{1,2}-[0-9]{2}s+[0-9]{2}:[0-9]{2}:[0-9]{2}.*?)s+(.*?Send message:)s*(.*?)(tos+phoneNo:s*[0-9]{11}).*/){
    	
    	$a1=$1;
    	$a2=$2;
    	$a3=$3;
    	$a4=$4;
    	print "$a1 is $a1
    ";
    #	print "$a2 is $a2
    ";
           
    	print "$a3 is $a3
    ";
    	print "$a4 is $a4
    ";
    	##微信是UTF-8字符集
    	if ($a3 =~/验证/){ $a3=encode("utf8",decode("gbk","$a3"));
    	$client->reply_msg($msg,"$a1-$a3-$a4")
    }};
    
    #	$client->reply_msg($msg,$number)
               }
    }else{$a5=encode("utf8",decode("gbk","没有找到需要的验证码信息"));$client->reply_msg($msg,"$a5")};
    
    
    }
            #对收到的消息,以相同的内容回复
    elsif ($recm =~/温金s+d{11}/i)
    {  
    $recm =~ s/^s+//;
    $number =(split(/s+/,"$recm"))[1];	
       
    $i=0;
    @arr=();
    @tmp1=();
    @tmp2=();
    use Encode;
    
    open (LOG1 ,"<",'\\192.168.32.101log01wj-api01-catalina.out') or die  $!;
                        while (<LOG1>) {
                      
    					 
    					if (($_ =~/$number/) and ($_ =~/SMSSendThread/) ){$str=encode("gbk",decode("utf8","$_"));
    						        print "$str is $str
    ";
    						 next if ($str !~ /验证/);
    					push (@tmp1 ,$str);
    					}};
    					
    					close LOG1;
    					
    					
    					
    					open (LOG2 ,"<",'\\192.168.32.101log01wj-api02-catalina.out') or die  $!;
                        while (<LOG2>) {
                      
    					 
    					if (($_ =~/$number/) and ($_ =~/SMSSendThread/)  ){$str=encode("gbk",decode("utf8","$_"));
    						        print "$str is $str
    ";
    							 next if ($str !~ /验证/);
    					push (@tmp2  ,$str);
    					}};
    					
    						close LOG2;
    					print "$tmp1[-1] is $tmp1[-1]
    ";
    					
    					print "$tmp2[-1] is $tmp2[-1]
    ";
    		@arr=($tmp1[-1], $tmp2[-1]);			
    			print "@arr is @arr
    ";		
    
    
    if  (defined($tmp1[-1]) or  defined($tmp2[-1]))
    {foreach (@arr){  
    ##2015-11-04 15:51:54,134 DEBUG com.zjzc.thirdparty.sms.SMSSendThread 
       if ($_ =~  /([0-9]{4}-[0-9]{1,2}-[0-9]{2}s+[0-9]{2}:[0-9]{2}:[0-9]{2}.*?)s+(.*?Send message:)s*(.*?)(tos+phoneNo:s*[0-9]{11}).*/){
    	
    	$a1=$1;
    	$a2=$2;
    	$a3=$3;
    	$a4=$4;
    	print "$a1 is $a1
    ";
    #	print "$a2 is $a2
    ";
           
    	print "$a3 is $a3
    ";
    	print "$a4 is $a4
    ";
    	##微信是UTF-8字符集
    	if ($a3 =~/验证/){ $a3=encode("utf8",decode("gbk","$a3"));
    	$client->reply_msg($msg,"$a1-$a3-$a4")
    }};
    
    #	$client->reply_msg($msg,$number)
    }
    }else{$a5=encode("utf8",decode("gbk","没有找到需要的验证码信息"));$client->reply_msg($msg,"$a5")};
    
    
     
         
    	   }
    elsif($recm =~/gps+d{1,11}/i){
    	   $recm =~ s/^s+//;
    $number =(split(/s+/,"$recm"))[1];
    use  LWP::UserAgent;
     
    my $ua = LWP::UserAgent->new;
    $ua->timeout(10);
    $ua->env_proxy;
    $ua->agent("Mozilla/8.0");
    
    my $response = $ua->get("http://hq.sinajs.cn/list=sh$number");
    
    
    $gupiao=$response->decoded_content;
    
    if ($response->is_success) {
     print $response->decoded_content;  # or whatever
    }
    else {
     die $response->status_line;
    }
    $price =(split(/,/,"$gupiao "))[3];
    
    
    
    
    $var= "$recm  当前价格是$price";
    
    print "$recm  当前价格是$price
    ";
    
    $var=encode("utf8",decode("gbk","$var"));
    
    
    if (defined($price)){
    
    $client->reply_msg($msg,"$var")
    }else{my $response = $ua->get("http://hq.sinajs.cn/list=sz$number");
    $gupiao=$response->decoded_content;
    $price =(split(/,/,"$gupiao "))[3];
    $var= "$recm  当前价格是$price";
    
    print "$recm  当前价格是$price
    ";
    
    $var=encode("utf8",decode("gbk","$var"));
    
     if (defined($price)){
    
         
    $client->reply_msg($msg,"$var")}
     else{reply_msg($msg,"not suport")}
    
    }
    
    };
    
    
    #else {$a5=encode("utf8",decode("gbk","格式为:中均/温金 客户手机号"));$client->reply_msg($msg,"$a5")};
    
    
        #设置客户端发送消息回调函数
        $client->on_send_msg = sub { 
            my $msg = shift;    
    	#  打印发送的消息
    	   $client->call("ShowMsg",$msg);
        
             }
    };
        #客户端进入事件循环,开始运行
         $client->run();
    


    
    
    
                                        
    
  • 相关阅读:
    基于WS流的RTSP监控,H5低延时,Web无插件,手机,微信ONVIF操控摄像头方案
    H5微信视频,直播低延时,IOS限制全屏播放,自动播放问题处理。
    最新IOS,safari11中对webrtc支持,IOS和android视频聊天,web低延时视频教学技术分析
    MySql 用户篇
    Sql Server 数据库帮助类
    [C#基础知识]转载 private、protected、public和internal的区别
    Mysql 插入语句
    .net core identityserver4 学习日志
    mysql 事务模板
    .net core 生成二维码
  • 原文地址:https://www.cnblogs.com/hzcya1995/p/13351149.html
Copyright © 2020-2023  润新知