[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 "\n";
};
sub sendelk{
use IO::Socket::INET;
$|=1;
$sock = IO::Socket::INET->new(PeerAddr => '10.10.10.10',
PeerPort => '9988',
Proto=>'tcp'
) or die "$!\n";
my $req=shift;
my $size = $sock->send($req);
print "sent data of length $size\n";
## 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\n";
$sock->close();
};
my $sth = $dbh->prepare($sql);
$sth->execute();
$sth->bind_columns(undef, \$system, \$count);
$sth->execute();
while( $sth->fetch() ){
print "$system\t\t $count\n";
chomp $count;
if ($count >=0){
my $message="告警[$system]3分钟内超时笔数为[$count],请注意观察!!!";
my $c=$message;
print $c."\n";
print length($c)."\n";
my $d=decode_utf8($message);
print length($d)."\n";
print $d."\n";
&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:
perl utf8 中文乱码
转载本文章为转载内容,我们尊重原作者对文章享有的著作权。如有内容错误或侵权问题,欢迎原作者联系我们进行内容更正或删除文章。
提问和评论都可以,用心的回复会被更多人看到
评论
发布评论
相关文章
-
有趣的CSS - 一串乱码
通过 css 来实现一段不停变化的 bug 乱码效果。
css 动效 乱码效果 ux 动画