mojo 接口示例
<pre name="code" class="python">use Mojolicious::Lite;
use JSON qw/encode_json decode_json/;
use Encode;
no strict;
no warnings;
use JSON;
use POSIX;
# /foo?user=sri
get '/api/env' => sub {
my $c = shift;
my $env = $c->param('env');
my $ip = $c->param('ip'); if ($env){
use DBI;
my $dbName = 'oadb';
my $dbUser = 'query';
my $dbUserPass = 'kjk7787czcb';
my @arr2="";
my $dbh = DBI->connect("dbi:Oracle:$dbName", $dbUser, $dbUserPass) or die "can't connect to database " ;
my $hostSql = qq{select IP,INFO,ENV from machine_info where ENV='env-$env' };
my ($a1, $a2, $a3,$a4,$a5,$a6,$a7,$a8,$a9);
my $selStmt = $dbh->prepare($hostSql);
$selStmt->bind_columns( \$a1, \$a2, \$a3);
$selStmt->execute();
while( $selStmt->fetch() ){ push (@arr2, "$a1 $a2 $a3" ); };
$c->render(json => \@arr2);
}elsif($ip){ use DBI;
my $dbName = 'oadb';
my $dbUser = 'query';
my $dbUserPass = 'kjk7787czcb';
my $dbh = DBI->connect("dbi:Oracle:$dbName", $dbUser, $dbUserPass) or die "can't connect to database " ;
my $hostSql = qq{select IP,INFO,ENV from machine_info where IP='$ip' };
my ($a1, $a2, $a3,$a4,$a5,$a6,$a7,$a8,$a9);
my @arr2="";
my $selStmt = $dbh->prepare($hostSql);
$selStmt->bind_columns(undef, \$a1, \$a2, \$a3);
$selStmt->execute();
while( $selStmt->fetch() ){
push (@arr2, "$a1 $a2 $a3" )
};
#sleep (30);
$c->render(json => \@arr2);
}}; get '/api/bus' => sub {
my $c = shift;
my $bus= $c->param('bus');
my $flag=$c->param('flag');
if( ($bus) || ($flag) ) {
use URI::Escape;
use Encode;
use JSON qw/encode_json decode_json/;
my $area="杭州";
$area=uri_escape_utf8("$area");
use LWP::UserAgent;
my $ua = LWP::UserAgent->new;
my @header = (
'accept'=> "application/json",
'content-type'=> "application/json",
'apikey'=> "3074a7f9926a4bbb484aa8bb366e5b87",
'User-Agent' => "Mozilla/8.0"
);
my $url = "http://apis.baidu.com/xiaota/bus_lines/buses_lines?city=$area&bus=$bus&direction=$flag";
my $request = HTTP::Request->new(GET=>"$url");
$request->header(@header);
my $response = $ua->request($request);
$content= $response->decoded_content;
$content =~ s/\\u([0-9a-fA-F]{4})/pack("U",,hex($1))/eg;
$content = encode_utf8($content);
my $json_out = $content ; $json_out = decode_json($content); @bus="";
#
foreach (@{($json_out->{data}->{stations})}){$bus="$_->{stateName}";push (@bus ,$bus)};
#$client->reply_msg($msg,"@bus")
print "\@bus is @bus\n";
$c->render(json => \@bus); };
}; get '/api/ipsearch' => sub {
my $c = shift;
my $ip=$c->param('ip');
if ($ip){
use LWP::UserAgent;
my $ua = LWP::UserAgent->new; my $host = "http://ip.taobao.com/service/getIpInfo.php?ip=$ip";
my $request = HTTP::Request->new(GET=>"$host");
my $response = $ua->request($request);
my $content= $response->decoded_content;
$content =~ s/\\u([0-9a-fA-F]{4})/pack("U",,hex($1))/eg;
$content=encode(utf8,$content);
$json_out = decode_json($content); $c->render(json => $json_out->{data} );
};
}; get '/api/update' => sub {
my $dbName = 'oadb';
my $dbUser = 'query';
my $dbUserPass = 'kjk7787czcb';
my $dbh = DBI->connect("dbi:Oracle:$dbName", $dbUser, $dbUserPass,{
RaiseError => 1,
AutoCommit => 0
}) or die "can't connect to database " ;
my $c = shift;
my $id=$c->param('id');
eval{
$dbh->do("update query.test set id=100 where id =$id") or $!;
$dbh->commit();
$c->render(text => "update successed" ); }; if( $@ ) {
#warn "Database error: $DBI::errstr\n";
$dbh->rollback(); #just die if rollback is failing
$c->render(text => "update failed" );
};
}; get '/api/getcode' => sub{
my $c = shift;
my $env = $c->param('env');
my $phone = $c->param('phone');
print "\$env is $env\n";
print "\$phone is $phone\n"; if ($env eq "zj"){
@arr1=();
@arr2=();
$str="";
@arr_out=();
@arr=(); my $starttime=strftime("%Y%m%d%H%M%S",localtime());
print "starttime is $starttime\n";
open (LOG1 ,"<",'/data01/applog_backup/zj-api01-catalina.out') or die $!;
while (<LOG1>) {
#2016-03-09 09:35:12,380 INFO com.zjzc.thirdparty.sms.SMSUtils - Send message:您的验证码为132435,本验证码5分钟内有效。 to phoneNo:18072722237 succeed! if ( ($phone) and ($_ =~/$phone/) and ($_ =~/SMSUtils/) ){$str=$_; my $d=encode_utf8('验证');
next if ($str !~ /$d/);
print "\$str is $str\n";
push (@arr1 ,$str);
}}; close LOG1; open (LOG2 ,"<",'/data01/applog_backup/zj-api02-catalina.out') or die $!;
while (<LOG2>) { if (($phone) and ($_ =~/$phone/) and ($_ =~/SMSUtils/) ){$str= $_; my $d=encode_utf8('验证');
next if ($str !~ /$d/);
print "\$str is $str\n";
push (@arr2 ,$str);
}}; close LOG2; my @arr=($arr1[-1], $arr2[-1]);
print "\@arr ---> @arr\n"; if (($arr1[-1]) or ($arr2[-1])){ foreach (@arr){
##2015-11-04 15:51:54,134 DEBUG com.zjzc.thirdparty.sms.SMSSendThread ##2016-03-09 09:35:12,380 INFO com.zjzc.thirdparty.sms.SMSUtils - Send message:您的验证码为132435,本验证码5分钟内有效。 to phoneNo:18072722237 succeed!
if ($_ =~ /([0-9]{4}-[0-9]{1,2}-[0-9]{2}\s+[0-9]{2}:[0-9]{2}:[0-9]{2}.*?)\s+(.*?Send message:)\s*(.*?)(to\s+phoneNo:\s*[0-9]{11}).*/){ $a1=$1;
$a2=$2;
$a3=$3;
$a4=$4; ##微信是UTF-8字符集 my $endtime=strftime("%Y%m%d%H%M%S",localtime()); my $d=encode_utf8('验证');
if ($a3 =~/$d/){
#$msg->reply("\@$friend $a1-$a3-$a4");
print "come in\n"; $a3=decode_utf8("$a3");
##encode("utf8",decode("gbk","格式为:中均/温金 客户手机号"))
#@content=($a1,$a3,$a4);
my @content=("$a1","$a3","$a4");
my $href= \@content;
push (@arr_out ,$href); print "endtime is $endtime\n";
}
};
};
$c->render(json => \@arr_out ); }
else{ $a5="$phone--ZJ没有找到需要的验证码信息"; $c->render(text => "$a5" ); }
}elsif($env eq "wj"){
@arr1=();
@arr2=();
$str="";
@arr_out=();
@arr=(); my $starttime=strftime("%Y%m%d%H%M%S",localtime());
print "starttime is $starttime\n";
open (LOG1 ,"<",'/data01/applog_backup/wj-api01-catalina.out') or die $!;
while (<LOG1>) {
#2016-03-09 09:35:12,380 INFO com.zjzc.thirdparty.sms.SMSUtils - Send message:您的验证码为132435,本验证码5分钟内有效。 to phoneNo:18072722237 succeed! if ( ($phone) and ($_ =~/$phone/) and ($_ =~/SMSUtils/) ){$str=$_;
my $d=encode_utf8('验证');
next if ($str !~ /$d/);
print "\$str is $str\n";
push (@arr1 ,$str);
}}; close LOG1; open (LOG2 ,"<",'/data01/applog_backup/wj-api02-catalina.out') or die $!;
while (<LOG2>) { if ( ($phone) and ($_ =~/$phone/) and ($_ =~/SMSUtils/) ){$str=$_;
my $d=encode_utf8('验证');
next if ($str !~ /$d/);
print "\$str is $str\n";
push (@arr2 ,$str);
}}; close LOG2; my @arr=($arr1[-1], $arr2[-1]);
print "\@arr ---> @arr\n"; if (($arr1[-1]) or ($arr2[-1])){ foreach (@arr){
##2015-11-04 15:51:54,134 DEBUG com.zjzc.thirdparty.sms.SMSSendThread ##2016-03-09 09:35:12,380 INFO com.zjzc.thirdparty.sms.SMSUtils - Send message:您的验证码为132435,本验证码5分钟内有效。 to phoneNo:18072722237 succeed!
if ($_ =~ /([0-9]{4}-[0-9]{1,2}-[0-9]{2}\s+[0-9]{2}:[0-9]{2}:[0-9]{2}.*?)\s+(.*?Send message:)\s*(.*?)(to\s+phoneNo:\s*[0-9]{11}).*/){ $a1=$1;
$a2=$2;
$a3=$3;
$a4=$4; ##微信是UTF-8字符集 my $endtime=strftime("%Y%m%d%H%M%S",localtime()); my $d=encode_utf8('验证');
if ($a3 =~/$d/){
#$msg->reply("\@$friend $a1-$a3-$a4");
print "come in\n"; $a3=decode_utf8("$a3");
##encode("utf8",decode("gbk","格式为:中均/温金 客户手机号"))
#@content=($a1,$a3,$a4);
my @content=($a1,$a3,$a4);
my $href= \@content;
push (@arr_out ,$href);
# print "\@arr_out is @arr_out\n";
#$c->render(text => ("$a1,$a3,$a4") ); print "endtime is $endtime\n";
}
};
};
$c->render(json => \@arr_out ); }
else{ $a5="$phone--WJ没有找到需要的验证码信息"; $c->render(text => "$a5" ); } } }; app->start;
mojo 接口示例的更多相关文章
- php中创建和调用webservice接口示例
php中创建和调用webservice接口示例 这篇文章主要介绍了php中创建和调用webservice接口示例,包括webservice基本知识.webservice服务端例子.webservi ...
- php 接口示例
php 接口示例: public function dev(){ $m=new Model('machine_info'); $ip=$_GET['ip']; echo $ip; //$arr=$m- ...
- 微信js-sdk开发获取签名和获取地理位置接口示例
###微信js-sdk开发获取签名和获取地理位置接口示例 前言:在做微信公众号开发时需要获取用户的地理位置信息,之前通过高德或者百度.腾讯等地图的api时发现经常获取不到,毕竟第三方的东西,后来改为采 ...
- webservice接口示例(spring+xfire+webservice)
webservice接口示例(spring+xfire+webservice) CreateTime--2018年4月2日17:36:07 Author:Marydon 一.准备工作 1.1 ja ...
- 微信JS-SDK分享接口示例中jsapi_ticket.php和access_token.php说明
关于如何使用微信JS-SDK,可以查看官方介绍说明:查看链接 在使用分享接口的过程中,查看了示例代码,其中包含两个文件jsapi_ticket.php和access_token.php,记录一下这两个 ...
- SkylineGlobe TerraExplorer for Web 7.1.0版本 接口示例
在SkylineGlobe TerraExplorer for Web 7.1.0版本(俗称H5免插件版本)中,如何使用SGWorld接口的三维视域分析方法呢? 请参考下面的示例: 通过下面的代码大家 ...
- Spring JDBC RowMapper接口示例
JdbcTemplate类使用org.springframework.jdbc.core.RowMapper <T>接口在每行的基础上映射ResultSet的行.该接口的实现执行将每行映射 ...
- Spring JDBC ResultSetExtractor接口示例
org.springframework.jdbc.core.ResultSetExtractor接口是JdbcTemplate的查询方法使用的回调接口.此接口的实现执行从ResultSet提取结果的实 ...
- Spring JDBC PreparedStatementSetter接口示例
org.springframework.jdbc.core.PreparedStatementSetter接口充当JdbcTemplate类使用的一般回调接口.该接口在JdbcTemplate类提供的 ...
随机推荐
- Android Fragment真正意义上的onResume和onPause
Fragment虽然有onResume和onPause的,但是这两个方法是Activity的方法,调用时机也是与Activity相同,和ViewPager搭配使用这个方法就很鸡肋了,根本不是你想要的效 ...
- jquery中的全局事件
ajaxStart(callback):Ajax请求开始时触发该事件 ajaxSend(callback):Ajax请求发送前触发该事件 ajaxSuccess(callback):Ajax请求成功时 ...
- 鼠标拖放div 实现
Javascript的mousemove事件类型是一个实时响应的事件,当鼠标指针的位置发生变化时(至少移动1个像素),就会触发mousemove事件.该事件响应的灵敏度主要参考鼠标指针移动速度的快慢, ...
- iOS多线程总结(二)NSOperation
NSOperation.h定义了NSOperation,内容非常的简洁,NSOperation本身是一个抽象类,定义了一个要执行的Task,NSOperationQueue是一个Task队列,当Tas ...
- makefile编写差异
由于zlib动态库在linux下引用的问题引出了对于简练的makefile的学习.之前通过看网络上的一些文章自己也算简单了解如何编写一个makefile,可总是不那么美观,今天经过辉哥的指点,对于ma ...
- Spring、AOP详解
如何配置AOP查看:Spring.Hello AOP 1.对于拦截规则@Pointcut的介绍: @Pointcut("execution (* cn.raffaello.service.. ...
- linux 学习之七-部分ssh命令
ssh命令 /etc/init.d/sshd restart|start|stop 重启|开始|关闭SSH的服务 ssh IP地址 连接SSH Linux scp命令用于Linux之间复制文件和目 ...
- UVA LA 7146 2014上海亚洲赛(贪心)
option=com_onlinejudge&Itemid=8&page=show_problem&category=648&problem=5158&mosm ...
- java web从零单排第十七期《struts2》数据标签库(1)
1.s:action标签: 此标签的作用是在JSP页面中访问action类的数据,执行某些操作,并返回相应的数据.其属性及意义如下: 属性名 是否必需 默认值 类型 说明介绍 executeResul ...
- jquery设置文本框值 与获取文本框的值
<!DOCTYPE html> <html> <head lang="en"> <meta charset="UTF-8&quo ...