• perl utf8 中文乱码


    [oracle@yyjk esb]$ cat a1.pl
    use DBI;    
    use HTTP::Date qw(time2iso str2time time2iso time2isoz);  
    use Net::SMTP;
    use Encode;
    my $dbName = 'ESBDB';    
    my $dbUser = 'esbdata';
    my $dbUserPass = 'esbdata';    
    my $dbh = DBI->connect("dbi:Oracle:$dbName", $dbUser, $dbUserPass) or die "can't connect to database ";  
    my $sql = "select logicsystem,count(*) from  esb2_trans_log t where t.trans_date >= sysdate - 30 / 1440 and t.respcode ='500101092209' and t.logicsystem<>'TLCHAT' group by logicsystem having count(*)>0";
    sub sendsms{
       use  LWP::UserAgent;   
       use LWP;  
       use Encode;  
       use LWP::Simple;  
       use LWP::UserAgent;  
       use HTTP::Cookies;  
       use HTTP::Headers;  
       use HTTP::Response;  
       use Encode;  
       use URI::Escape;  
       use URI::URL;  
       use JSON;  
         my $ua = LWP::UserAgent->new;  
      $ua->agent("Mozilla/5.0 (Windows NT 6.1; rv:30.0) Gecko/20100101 Firefox/30.0");  
      my $cookie_jar = HTTP::Cookies->new(  
         file=>'lwp_cookies.txt',  
         autosave=>1,  
         ignore_discard=>1);  
         $ua->cookie_jar($cookie_jar);  
       my $token_url= 'http://10.10.10.10:8080/tlcbspt/sendText';  
       my $a=shift;
       my $b=shift;               
       my $res = $ua->post($token_url,  
                    {  
                    'phoneNo'=>$a,  
                    'message'=>$b
                    });  
       print $res->content();  
       print "
    "; 
    };
    sub sendelk{
    use IO::Socket::INET;
    $|=1;
      $sock = IO::Socket::INET->new(PeerAddr => '10.10.10.10',
                                       PeerPort => '9988',
                                       Proto=>'tcp'
                                   ) or die "$!
    ";
     my $req=shift;
     my $size = $sock->send($req);
      print "sent data of length $size
    ";
     ## notify server that request has been sent
      shutdown($sock, 1);
      ## receive a response of up to 1024 characters from server
      my $response = "";
      $sock->recv($response, 1024);
      print "received response: $response
    ";
      $sock->close();
    };
    my $sth = $dbh->prepare($sql);    
       $sth->execute(); 
       $sth->bind_columns(undef, $system,  $count); 
       $sth->execute(); 
       while( $sth->fetch() ){ 
           print "$system		 $count
    "; 
           chomp $count;
           if ($count >=0){
               my $message="告警[$system]3分钟内超时笔数为[$count],请注意观察!!!";
               my $c=$message;
               print $c."
    ";
               print length($c)."
    ";
               my $d=decode_utf8($message);
               print length($d)."
    ";
               print $d."
    ";
               &sendsms('18072xx2237',"$d");
               #my $e=decode_utf8($c);
               &sendelk("$c");
    }}; 
     
    $sth->finish; 
    
     my $d=decode_utf8($message);
    decode_utf8 解码成unicode 字符集
    
    $message 本身是utf-8字符集
    
    [oracle@yyjk esb]$ perl a1.pl
    SSRS		 2
    告警[SSRS]3分钟内超时笔数为[2],请注意观察!!!
    59
    29
    Wide character in print at a1.pl line 73.
    告警[SSRS]3分钟内超时笔数为[2],请注意观察!!!
    
    sent data of length 59
    received response: 
    CIPS		 2
    告警[CIPS]3分钟内超时笔数为[2],请注意观察!!!
    59
    29
    Wide character in print at a1.pl line 73.
    告警[CIPS]3分钟内超时笔数为[2],请注意观察!!!
    
    sent data of length 59
    received response: 
    

  • 相关阅读:
    没有加注解的后果
    异常:javax.servlet.jsp.JspTagException: Don't know how to iterate over supplied "items" in &lt;forEach&gt;
    页面的跳转
    SpringBoot的修改操作
    抛出异常
    SpringBoot中的控制层的程序中的方法有返回值的原因
    Maven创建的项目使用SpringBoot框架运行时Progress窗口出现的过程
    @Entity注解不同来源
    maven项目不能正常导入到eclipse中
    使用mpvue开发小程序特别需要注意生命周期勾子created和beforeCreate问题
  • 原文地址:https://www.cnblogs.com/hzcya1995/p/13349223.html
Copyright © 2020-2023  润新知