diff --git a/application/third_party/tuniu/controllers/tuniu_train.php b/application/third_party/tuniu/controllers/tuniu_train.php index 559fba16..79e251e3 100644 --- a/application/third_party/tuniu/controllers/tuniu_train.php +++ b/application/third_party/tuniu/controllers/tuniu_train.php @@ -59,27 +59,38 @@ class Tuniu_train extends CI_Controller{ "sign": "'.$sign.'", "timestamp": "'.$time.'", "data": { "trainDate": "'.$date.'", "fromStation": "'.$fromStation.'", "toStation": "'.$toStation.'", "trainCode": "" } - }'; + }'; + //设置请求接口时间 + $api_start_time = microtime(true); + $back_data = post_tuniu($url,$post_data,$method = 'POST'); + $back_data = null; + //接口结束时间 + $api_end_time = microtime(true); + + //计算响应时间 + $api_responsive_time = $api_end_time - $api_start_time; - log_message('error','tuniutrain 原始数据:'.$back_data); - //print_r(json_decode($back_data));die(); - //$log_info = ''; + if(!empty($back_data)){ + $tn_info = json_decode($back_data); + $retrun_code = $tn_info->returnCode; + $return_msg = $tn_info->errorMsg; + }else{ + $retrun_code = '404'; + $return_msg = '途牛接口未响应'; + } + //记录数据格式 |出发站|到达站|发车时间|接口响应时间|接口返回代码|接口返回信息 + log_message('error','tuniutrain|'.$fromStation.'|'.$toStation.'|'.$date.'|'.$api_responsive_time.'|'.$retrun_code.'|'.$return_msg); - $tn_info = json_decode($back_data); - $retrun_code = $tn_info->returnCode; - $return_msg = $tn_info->errorMsg; if(isset($tn_info->data)){ if(empty(json_decode($back_data)->data)){ $isCache = true; - //$log_info = 'tuniutrain data缺失|数据源:'.$fromStation.'|'.$toStation.'|'.$date.'|retrun_code:'.$retrun_code.'|return_msg:'.$return_msg; }else{ $this->tuniuprice_model->addOrUpdate($fromStation,$toStation,$back_data); } }else{ $isCache = true; - //$log_info = 'tuniutrain 接口未响应|数据源:'.$fromStation.'|'.$toStation.'|'.$date.'|retrun_code:'.$retrun_code.'|return_msg:'.$return_msg; } if($isCache){ @@ -90,12 +101,8 @@ class Tuniu_train extends CI_Controller{ if(!empty($trainCache)){ $back_data = $trainCache->tpc_content; $isCache = true; - //$log_info .= '|调用缓存'; - //log_message('error',$log_info); }else{ $back_data = null; - //$log_info .= '|缓存为空'; - //log_message('error',$log_info); } } } diff --git a/application/third_party/tuniu/helpers/tuniu_helper.php b/application/third_party/tuniu/helpers/tuniu_helper.php index eb76527d..55a44a9c 100644 --- a/application/third_party/tuniu/helpers/tuniu_helper.php +++ b/application/third_party/tuniu/helpers/tuniu_helper.php @@ -44,8 +44,8 @@ curl_setopt($curl, CURLOPT_POSTFIELDS, $data); // Post提交的数据包 curl_setopt($curl, CURLOPT_HTTPHEADER, array('Content-Type:application/json')); } - curl_setopt($curl, CURLOPT_TIMEOUT, 25); // 设置超时限制防止死循环 - curl_setopt($curl, CURLOPT_TIMEOUT_MS, 25000); // 设置超时限制防止死循环 + curl_setopt($curl, CURLOPT_TIMEOUT, 40); // 设置超时限制防止死循环 + curl_setopt($curl, CURLOPT_TIMEOUT_MS, 40000); // 设置超时限制防止死循环 curl_setopt($curl, CURLOPT_HEADER, 0); // 显示返回的Header区域内容 curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1); // 获取的信息以文件流的形式返回 $tmpInfo = curl_exec($curl); // 执行操作