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

  • 相关阅读:
    升级edk2源码的一点补充
    关于Ubuntu系统忘记密码的解决方法合集
    UEFI Shell 下的程序设计
    Windows下EDK2环境的搭建以及经典的程序设计Print Hello World !-----(Linux下的待后续熟练了再更新)
    一个刚入行的BIOS工程师的自我简介
    反爬虫,非标准的json格式解析
    Scrapy+selenium爬取简书全站-爬虫
    Scrapy
    Python 爬取豆瓣电影Top250排行榜,爬虫初试
    Linux(Ubuntu) MySQL数据库安装与卸载
  • 原文地址:https://www.cnblogs.com/hzcya1995/p/13349821.html
Copyright © 2011-2022 走看看