优化接口的容错机制

hotfix/远程访问多媒体中心
cyc 8 years ago
parent 910bfe042a
commit f2d269aca3

@ -127,7 +127,7 @@ class Index extends CI_Controller{
$to_date=$this->input->post("to_date"); $to_date=$this->input->post("to_date");
$examine=$this->input->post("examine"); $examine=$this->input->post("examine");
$reback=array();//返回的数据 $reback=array();//返回的数据
$reback["from_date"]=$from_date; $reback["from_date"]=$from_date;
$reback["to_date"]=$to_date; $reback["to_date"]=$to_date;
$reback["examine"]=$examine; $reback["examine"]=$examine;
if(!empty($from_date) && !empty($to_date)){ if(!empty($from_date) && !empty($to_date)){

@ -10,8 +10,11 @@ class search extends CI_Controller{
} }
//查询聚合余票接口,对返回的数据进行处理 //查询聚合余票接口,对返回的数据进行处理
public function index($train_date,$fromStation,$toStation){ public function index($train_date=null,$fromStation=null,$toStation=null){
$url = 'http://op.juhe.cn/trainTickets/ticketsAvailable?key='.JUHE_TRAIN_API_KEY.'&train_date='.$train_date.'&from_station='.$fromStation.'&to_station='.$toStation; if(!$train_date || !$fromStation || !$toStation){
exit('传参错误!');
}else{
$url = 'http://op.juhe.cn/trainTickets/ticketsAvailable?key='.JUHE_TRAIN_API_KEY.'&train_date='.$train_date.'&from_station='.$fromStation.'&to_station='.$toStation;
$back_data = $this->get_http($url); $back_data = $this->get_http($url);
//print_r(json_decode($back_data)); //print_r(json_decode($back_data));
$return_data = new stdClass(); $return_data = new stdClass();
@ -100,6 +103,7 @@ class search extends CI_Controller{
} }
$return_data->data->map = (object)$obj; $return_data->data->map = (object)$obj;
print_r(json_encode($return_data)); print_r(json_encode($return_data));
}
} }
//获取价格 //获取价格
@ -108,12 +112,16 @@ class search extends CI_Controller{
toStationCode:终点站三字码 toStationCode:终点站三字码
trainCode:车次号 trainCode:车次号
*/ */
public function get_price($fromStationCode,$toStationCode,$trainCode){ public function get_price($fromStationCode=null,$toStationCode=null,$trainCode=null){
$return_data = $this->BIZ_train_model->get_price($fromStationCode,$toStationCode,$trainCode); if(!$fromStationCode || !$toStationCode || !$trainCode){
if(!empty($return_data)){ exit('传参错误!');
print_r(json_decode($return_data->TPL_Price));
}else{ }else{
print_r('没有数据返回'); $return_data = $this->BIZ_train_model->get_price($fromStationCode,$toStationCode,$trainCode);
if(!empty($return_data)){
print_r(json_decode($return_data->TPL_Price));
}else{
print_r('没有数据返回');
}
} }
} }

@ -35,8 +35,11 @@ class Tuniu_train extends CI_Controller{
} }
//获取余票 //获取余票
public function search($date,$fromStation,$toStation){ public function search($date=null,$fromStation=null,$toStation=null){
$sign = $this->create_sign(); if(!$date || !$fromStation || !$toStation){
exit('传参错误!');
}else{
$sign = $this->create_sign();
$url = TUNIU_URL.'/train/search'; $url = TUNIU_URL.'/train/search';
$time = date('Y-m-d H:i:s',time()); $time = date('Y-m-d H:i:s',time());
$post_data = '{ $post_data = '{
@ -135,6 +138,7 @@ class Tuniu_train extends CI_Controller{
} }
$return_data->data->map = (object)$obj; $return_data->data->map = (object)$obj;
print_r(json_encode($return_data)); print_r(json_encode($return_data));
}
} }
//获取价格 //获取价格
@ -143,9 +147,13 @@ class Tuniu_train extends CI_Controller{
toStationCode:终点站三字码 toStationCode:终点站三字码
trainCode:车次 trainCode:车次
*/ */
public function get_price($fromStationCode,$toStationCode,$trainCode){ public function get_price($fromStationCode=null,$toStationCode=null,$trainCode=null){
$return_data = $this->tuniuprice_model->get_price($fromStationCode,$toStationCode,$trainCode); if(!$fromStationCode || !$toStationCode || !$trainCode){
print_r(json_decode($return_data->TPL_Price)); exit('传参错误!');
}else{
$return_data = $this->tuniuprice_model->get_price($fromStationCode,$toStationCode,$trainCode);
print_r(json_decode($return_data->TPL_Price));
}
} }
//占座下单 //占座下单
@ -282,6 +290,21 @@ class Tuniu_train extends CI_Controller{
print_r($back_data); print_r($back_data);
} }
//车站三字码查询
public function telecodeQuery(){
$sign = $this->create_sign();
$url = TUNIU_URL.'/train/telecodeQuery';
$time = date('Y-m-d H:i:s',time());
$post_data = '{
"apiKey": "'.TUNIU_KEY.'",
"sign": "'.$sign.'",
"timestamp": "'.$time.'",
"data": null
}';
$back_data = post_tuniu($url,$post_data,$method = 'POST');
print_r($back_data);
}
//身份验证 //身份验证
public function validate(){ public function validate(){
//$name = $this->input->post('name'); //$name = $this->input->post('name');

Loading…
Cancel
Save