diff --git a/application/third_party/train/controllers/index.php b/application/third_party/train/controllers/index.php index 04074e90..48d2673b 100644 --- a/application/third_party/train/controllers/index.php +++ b/application/third_party/train/controllers/index.php @@ -127,7 +127,7 @@ class Index extends CI_Controller{ $to_date=$this->input->post("to_date"); $examine=$this->input->post("examine"); $reback=array();//返回的数据 - $reback["from_date"]=$from_date; + $reback["from_date"]=$from_date; $reback["to_date"]=$to_date; $reback["examine"]=$examine; if(!empty($from_date) && !empty($to_date)){ diff --git a/application/third_party/train/controllers/search.php b/application/third_party/train/controllers/search.php index dee7bf9d..18109911 100644 --- a/application/third_party/train/controllers/search.php +++ b/application/third_party/train/controllers/search.php @@ -10,8 +10,11 @@ class search extends CI_Controller{ } //查询聚合余票接口,对返回的数据进行处理 - public function index($train_date,$fromStation,$toStation){ - $url = 'http://op.juhe.cn/trainTickets/ticketsAvailable?key='.JUHE_TRAIN_API_KEY.'&train_date='.$train_date.'&from_station='.$fromStation.'&to_station='.$toStation; + public function index($train_date=null,$fromStation=null,$toStation=null){ + 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); //print_r(json_decode($back_data)); $return_data = new stdClass(); @@ -100,6 +103,7 @@ class search extends CI_Controller{ } $return_data->data->map = (object)$obj; print_r(json_encode($return_data)); + } } //获取价格 @@ -108,12 +112,16 @@ class search extends CI_Controller{ toStationCode:终点站三字码 trainCode:车次号 */ - public function get_price($fromStationCode,$toStationCode,$trainCode){ - $return_data = $this->BIZ_train_model->get_price($fromStationCode,$toStationCode,$trainCode); - if(!empty($return_data)){ - print_r(json_decode($return_data->TPL_Price)); + public function get_price($fromStationCode=null,$toStationCode=null,$trainCode=null){ + if(!$fromStationCode || !$toStationCode || !$trainCode){ + exit('传参错误!'); }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('没有数据返回'); + } } } diff --git a/application/third_party/tuniu/controllers/tuniu_train.php b/application/third_party/tuniu/controllers/tuniu_train.php index 1b54e761..1eb329e6 100644 --- a/application/third_party/tuniu/controllers/tuniu_train.php +++ b/application/third_party/tuniu/controllers/tuniu_train.php @@ -35,8 +35,11 @@ class Tuniu_train extends CI_Controller{ } //获取余票 - public function search($date,$fromStation,$toStation){ - $sign = $this->create_sign(); + public function search($date=null,$fromStation=null,$toStation=null){ + if(!$date || !$fromStation || !$toStation){ + exit('传参错误!'); + }else{ + $sign = $this->create_sign(); $url = TUNIU_URL.'/train/search'; $time = date('Y-m-d H:i:s',time()); $post_data = '{ @@ -135,6 +138,7 @@ class Tuniu_train extends CI_Controller{ } $return_data->data->map = (object)$obj; print_r(json_encode($return_data)); + } } //获取价格 @@ -143,9 +147,13 @@ class Tuniu_train extends CI_Controller{ toStationCode:终点站三字码 trainCode:车次 */ - public function get_price($fromStationCode,$toStationCode,$trainCode){ - $return_data = $this->tuniuprice_model->get_price($fromStationCode,$toStationCode,$trainCode); - print_r(json_decode($return_data->TPL_Price)); + public function get_price($fromStationCode=null,$toStationCode=null,$trainCode=null){ + if(!$fromStationCode || !$toStationCode || !$trainCode){ + 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); } + //车站三字码查询 + 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(){ //$name = $this->input->post('name');