zoukankan      html  css  js  c++  java
  • 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: 
    

  • 相关阅读:
    springmvc中request的线程安全问题
    SpringMVC数据验证
    Spring验证的错误返回------BindingResult
    chrome扩展
    北京联想招聘-Android高级工程师(5-7年) 加入qq 群:220486180 或者直接在此 留言咨询
    北京联想招聘-Android Framework高级工程师(7-10年) 加入qq 群:220486180 或者直接在此 留言咨询
    北京联想招聘-java 云服务开发工程师 加入qq 群:220486180 或者直接在此 留言咨询
    北京联想招聘-IOS高级 加入qq 群:220486180 或者直接在此 留言咨询
    css 兼容
    appium 几点总结(转)
  • 原文地址:https://www.cnblogs.com/hzcya1995/p/13349223.html
Copyright © 2011-2022 走看看