mojo ut8:
[root@jxglapp1 pfwx-master]# vim mojo.pl
[root@jxglapp1 pfwx-master]#
You have new mail in /var/spool/mail/root
[root@jxglapp1 pfwx-master]# cat mojo.pl
use lib "./lib";
use mojo::Client;
use Data::Dumper;
use Mojolicious::Lite;
use JSON qw/encode_json decode_json/;
use Encode;
no strict;
no warnings;
use JSON;
use POSIX;
use JSON::RPC::Client;
use Data::Dumper;
use URI::Escape;
my $client = mojo::Client->new();
print Dumper($client);
get '/api/SMSsendx' => sub {
my $c = shift;
my $sourceip=$c->param('sourceip');
my $message = $c->param('message');
print "Length1==";
print length($message)."
";
print "$message is $message
";
$sms=$message;
my $flag=Encode::is_utf8($message);
print "$flag===$flag
";
if ($flag)
{
Encode::_utf8_off($message);
print "Length2==";
print length($message)."
";
$sms=encode_utf8($sms);
$sms=encode("gbk",decode("utf8",$sms)) }
else
{$message=encode("utf8",decode("gbk",$message)) };
#$message=encode_utf8($message);g===$flag
";
my $phone = $c->param('phone');
$client->SMSsendx("ip:$sourceip,message:$sms","$phone");
#mojo::Client::LoadDb::insertdb(1,$sourceip,$message,$phone);
$client->insertdb($sourceip,$message,$phone);
$c->render(json =>{retcode,0000});
};
get '/api/SMSinfo' => sub {
my $c=shift;
my $sourceip=$c->param('sourceip');
@arr=$client->SMSinfo($sourceip);
$c->render(json =>@arr);
};
app->start;
[Mon Mar 13 10:00:47 2017] [debug] Routing to a callback
Length1==2
$message is 中国
$flag===1
Length2==6
socket$message is ip:8.8.3.99,message:?1
0Xd 5555 N ip:8.8.3.99,message:?1 18072722237
returnLength==50LoadDB::$flag==
4---Length=6Wide character in print at lib/mojo/Client/LoadDb.pm line 28.
insert into SMSsendx_Info values ('8.8.3.99','中国','18072722237',to_date('20170313100047','YYYYMMDDHH24MISS'))
Database success
[Mon Mar 13 10:00:47 2017] [debug] 200 OK (0.086001s, 11.628/s)
mojo gbk:
Length1==4
$message is ?1
$flag===
socket$message is ip:8.8.3.6,message:?1
0Xd 5555 N ip:8.8.3.6,message:?1 18072722237
returnLength==49LoadDB::$flag==
4---Length=6Wide character in print at lib/mojo/Client/LoadDb.pm line 28.
insert into SMSsendx_Info values ('8.8.3.6','中国','18072722237',to_date('20170313100235','YYYYMMDDHH24MISS'))
Database success
[Mon Mar 13 10:02:35 2017] [debug] 200 OK (0.045084s, 22.181/s)
gbk 编码 "中国"长度为4
转成utf8 "中国"长度为6