• mojo 编码处理


    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
    
    

  • 相关阅读:
    js 左键点击页面时显示“您好”,右键点击时显示“禁止右键”。并在2分钟后自动关闭页面。
    搜藏 SQL
    邮件发送 图片
    超市购物打印小票的简单程序 记录下来
    KFC打印
    printf和scanf对于各种格式说明符
    Unity3d Camera size
    C#笔记
    CSV文件读写注意
    cocos2dx相关网址
  • 原文地址:https://www.cnblogs.com/hzcya1995/p/13349821.html
Copyright © 2020-2023  润新知