hotfix/远程访问多媒体中心
lmr@hainatravel.com 8 years ago
commit 6797c22064

@ -413,6 +413,7 @@ class Information extends CI_Controller {
$this->update_cache($this->input->post('ic_url'), true); $this->update_cache($this->input->post('ic_url'), true);
} }
$meta_amp_status = get_meta($information->ic_id, 'AMP_STATUS');
//德语站FAQ版块需要删除原来的文件才能更新静态 //德语站FAQ版块需要删除原来的文件才能更新静态
$site_code = $this->config->item('site_code'); $site_code = $this->config->item('site_code');
$ic_url = $this->input->post('ic_url'); $ic_url = $this->input->post('ic_url');
@ -420,7 +421,11 @@ class Information extends CI_Controller {
if ($site_code == 'gm' && substr($ic_url, 0, 5) == '/faq/') { if ($site_code == 'gm' && substr($ic_url, 0, 5) == '/faq/') {
$update_info_log = $this->update_cache($ic_url, true); $update_info_log = $this->update_cache($ic_url, true);
} else if (strcasecmp($site_code, "cht") == 0 && !empty($auto_update_cache)) { } else if (strcasecmp($site_code, "cht") == 0 && !empty($auto_update_cache)) {
$update_info_log = $this->update_cache($ic_url); $update_url = $ic_url;
if ($meta_amp_status) {
$update_url = '/amp'.$ic_url;
}
$update_info_log = $this->update_cache($update_url);
} else if (strcasecmp($site_code, "cht") != 0) {//非cht站点 } else if (strcasecmp($site_code, "cht") != 0) {//非cht站点
$update_info_log = $this->update_cache($ic_url); $update_info_log = $this->update_cache($ic_url);
} }

@ -1,292 +1,292 @@
<?php <?php
if (!defined('BASEPATH')) if (!defined('BASEPATH'))
exit('No direct script access allowed'); exit('No direct script access allowed');
class searchnew extends CI_Controller{ class searchnew extends CI_Controller{
public function __construct(){ public function __construct(){
parent::__construct(); parent::__construct();
$this->load->model("BIZ_train_model");//加载模型 $this->load->model("BIZ_train_model");//加载模型
} }
//查询聚合余票接口,对返回的数据进行处理 //查询聚合余票接口,对返回的数据进行处理
public function index($train_date=null,$fromStation=null,$toStation=null){ public function index($train_date=null,$fromStation=null,$toStation=null){
//定义一些变量 //定义一些变量
$cache = 'no'; $cache = 'no';
$flag = true; $flag = true;
$juheTrainInfo = ''; $juheTrainInfo = '';
set_time_limit(0); set_time_limit(0);
//判断数据是否合法 //判断数据是否合法
if(!$train_date || !$fromStation || !$toStation){ if(!$train_date || !$fromStation || !$toStation){
exit('传参不能为空!'); exit('传参不能为空!');
}else{ }else{
if(strlen($fromStation) != 3){ if(strlen($fromStation) != 3){
exit('fromStation:参数错误!'); exit('fromStation:参数错误!');
} }
if(strlen($toStation) != 3){ if(strlen($toStation) != 3){
exit('toStation:参数错误!'); exit('toStation:参数错误!');
} }
$this->train_date = $train_date; $this->train_date = $train_date;
$now_time = time(); $now_time = time();
$differ_time = (strtotime($train_date) - $now_time) / 86400; $differ_time = (strtotime($train_date) - $now_time) / 86400;
if($differ_time <= 29){ if($differ_time <= 29){
//调用聚合搜索模块 //调用聚合搜索模块
$juheTrainInfo = $this->juheSearch($train_date,$fromStation,$toStation); $juheTrainInfo = $this->juheSearch($train_date,$fromStation,$toStation);
if(empty($juheTrainInfo)){ if(empty($juheTrainInfo)){
$flag = 'error'; $flag = 'error';
} }
}else{ }else{
$flag = 'cache'; $flag = 'cache';
} }
//调用数据处理模块。 //调用数据处理模块。
$returnJson = $this->dataOperate($juheTrainInfo,$flag,$fromStation,$toStation); $returnJson = $this->dataOperate($juheTrainInfo,$flag,$fromStation,$toStation);
//调用拼接处理模块 //调用拼接处理模块
$trainjson = $this->createTrainJson($returnJson); $trainjson = $this->createTrainJson($returnJson);
print_r($trainjson); print_r($trainjson);
die(); die();
} }
} }
//搜索模块 //搜索模块
function juheSearch($train_date,$fromStation,$toStation){ function juheSearch($train_date,$fromStation,$toStation){
$url = 'http://139.129.246.118:12309/trainTickets/ticketsAvailable?key='.JUHE_TRAIN_API_KEY.'&train_date='.$train_date.'&from_station='.$fromStation.'&to_station='.$toStation; $url = 'http://139.129.246.118:12309/trainTickets/ticketsAvailable?key='.JUHE_TRAIN_API_KEY.'&train_date='.$train_date.'&from_station='.$fromStation.'&to_station='.$toStation;
$this->url = $url; $this->url = $url;
$juheTrainInfo = $this->get_http($url); $juheTrainInfo = $this->get_http($url);
if($this->validateJuhe($juheTrainInfo)){ if($this->validateJuhe($juheTrainInfo)){
return $juheTrainInfo; return $juheTrainInfo;
}else{ }else{
return null; return null;
} }
} }
//缓存处理模块(包含缓存处理) //缓存处理模块(包含缓存处理)
function dataOperate($trainInfo,$flag,$fromStation,$toStation){ function dataOperate($trainInfo,$flag,$fromStation,$toStation){
if($flag == 'error'){ if($flag == 'error'){
$research = $this->juheSearch($this->train_date,$fromStation,$toStation); $research = $this->juheSearch($this->train_date,$fromStation,$toStation);
if($this->validateJuhe($research)){ if($this->validateJuhe($research)){
$trainInfo = $research; $trainInfo = $research;
}else{ }else{
$flag = 'cache'; $flag = 'cache';
} }
} }
if($flag == 'cache'){ if($flag == 'cache'){
$cacheTrainInfo = $this->BIZ_train_model->get_train_info($fromStation,$toStation); $cacheTrainInfo = $this->BIZ_train_model->get_train_info($fromStation,$toStation);
if(empty($cacheTrainInfo)){ if(empty($cacheTrainInfo)){
return null; return null;
}else{ }else{
$cache_time = $cacheTrainInfo->tpc_datetime; $cache_time = $cacheTrainInfo->tpc_datetime;
$now_time = time(); $now_time = time();
$differ_time = ($now_time - strtotime($cache_time)) / 86400; $differ_time = ($now_time - strtotime($cache_time)) / 86400;
if($differ_time >= 7){ if($differ_time >= 7){
$this->delete_traincache($fromStation,$toStation); $this->delete_traincache($fromStation,$toStation);
$research = $this->juheSearch(strtotime('+7day'),$fromStation,$toStation); $research = $this->juheSearch(strtotime('+7day'),$fromStation,$toStation);
if($this->validateJuhe($research)){ if($this->validateJuhe($research)){
$trainInfo = $research; $trainInfo = $research;
}else{ }else{
return null; return null;
} }
} }
} }
} }
$this->BIZ_train_model->addOrUpdate($fromStation,$toStation,$trainInfo); $this->BIZ_train_model->addOrUpdate($fromStation,$toStation,$trainInfo);
return $trainInfo; return $trainInfo;
} }
//字符串拼接模块 //字符串拼接模块
function createTrainJson($returnJson){ function createTrainJson($returnJson){
if(empty($returnJson)){ if(empty($returnJson)){
}else{ }else{
$return_data = new stdClass(); $return_data = new stdClass();
$return_data->data = new stdClass(); $return_data->data = new stdClass();
$return_data->httpstatus = 200; $return_data->httpstatus = 200;
//$return_data->reason = $reason; //$return_data->reason = $reason;
//$return_data->cache = $cache; //$return_data->cache = $cache;
$return_data->data->result = array(); $return_data->data->result = array();
$return_data->data->map = new stdClass(); $return_data->data->map = new stdClass();
$obj = array(); $obj = array();
$i = 0; $i = 0;
$pricestr = ''; $pricestr = '';
//print_r(json_decode($returnJson)); //print_r(json_decode($returnJson));
//die(); //die();
if(!empty(json_decode($returnJson)->result->list)){ if(!empty(json_decode($returnJson)->result->list)){
foreach (json_decode($returnJson)->result->list as $value){ foreach (json_decode($returnJson)->result->list as $value){
$obj[$value->from_station_code] = $value->from_station_name; $obj[$value->from_station_code] = $value->from_station_name;
$obj[$value->to_station_code] = $value->to_station_name; $obj[$value->to_station_code] = $value->to_station_name;
$seat_type = ''; $seat_type = '';
if(isset($value->gjrw_price)){ if(isset($value->gjrw_price)){
if($value->gjrw_price > 0){ if($value->gjrw_price > 0){
$gjrwPrice = $value->gjrw_price * 10; $gjrwPrice = $value->gjrw_price * 10;
$seat_type .= '"6":"'.$gjrwPrice.'","A6":"¥'.$value->gjrw_price.'",'; $seat_type .= '"6":"'.$gjrwPrice.'","A6":"¥'.$value->gjrw_price.'",';
} }
} }
if(isset($value->qtxb_price)){ if(isset($value->qtxb_price)){
if($value->qtxb_price > 0){ if($value->qtxb_price > 0){
$seat_type .= '"H":"¥'.$value->qtxb_price.'",'; $seat_type .= '"H":"¥'.$value->qtxb_price.'",';
} }
} }
if(isset($value->rw_price)){ if(isset($value->rw_price)){
if($value->rw_price > 0){ if($value->rw_price > 0){
$rwPrice = $value->rw_price * 10; $rwPrice = $value->rw_price * 10;
$seat_type .= '"4":"'.$rwPrice.'","A4":"¥'.$value->rw_price.'",'; $seat_type .= '"4":"'.$rwPrice.'","A4":"¥'.$value->rw_price.'",';
} }
} }
if(isset($value->rz_price)){ if(isset($value->rz_price)){
if($value->rz_price > 0){ if($value->rz_price > 0){
$rzPrice = $value->rz_price * 10; $rzPrice = $value->rz_price * 10;
$seat_type .= '"2":"'.$rzPrice.'","A2":"¥'.$value->rz_price.'",'; $seat_type .= '"2":"'.$rzPrice.'","A2":"¥'.$value->rz_price.'",';
} }
} }
if(isset($value->tdz_price)){ if(isset($value->tdz_price)){
if($value->tdz_price > 0){ if($value->tdz_price > 0){
$seat_type .= '"P":"¥'.$value->tdz_price.'",'; $seat_type .= '"P":"¥'.$value->tdz_price.'",';
} }
} }
if(isset($value->wz_price)){ if(isset($value->wz_price)){
if($value->wz_price > 0){ if($value->wz_price > 0){
$wzPrice = $value->wz_price * 10; $wzPrice = $value->wz_price * 10;
$seat_type .= '"WZ":"¥'.$value->wz_price.'",'; $seat_type .= '"WZ":"¥'.$value->wz_price.'",';
} }
} }
if(isset($value->yw_price)){ if(isset($value->yw_price)){
if($value->yw_price > 0){ if($value->yw_price > 0){
$ywPrice = $value->yw_price * 10; $ywPrice = $value->yw_price * 10;
$seat_type .= '"3":"'.$ywPrice.'","A3":"¥'.$value->yw_price.'",'; $seat_type .= '"3":"'.$ywPrice.'","A3":"¥'.$value->yw_price.'",';
} }
} }
if(isset($value->yz_price)){ if(isset($value->yz_price)){
if($value->yz_price > 0){ if($value->yz_price > 0){
$yzPrice = $value->yz_price * 10; $yzPrice = $value->yz_price * 10;
$seat_type .= '"1":"'.$yzPrice.'","A1":"¥'.$value->yz_price.'",'; $seat_type .= '"1":"'.$yzPrice.'","A1":"¥'.$value->yz_price.'",';
} }
} }
if(isset($value->edz_price)){ if(isset($value->edz_price)){
if($value->edz_price > 0){ if($value->edz_price > 0){
$seat_type .= '"O":"¥'.$value->edz_price.'",'; $seat_type .= '"O":"¥'.$value->edz_price.'",';
} }
} }
if(isset($value->ydz_price)){ if(isset($value->ydz_price)){
if($value->ydz_price > 0){ if($value->ydz_price > 0){
$seat_type .= '"M":"¥'.$value->ydz_price.'",'; $seat_type .= '"M":"¥'.$value->ydz_price.'",';
} }
} }
if(isset($value->swz_price)){ if(isset($value->swz_price)){
if($value->swz_price > 0){ if($value->swz_price > 0){
$swzPrice = $value->swz_price * 10; $swzPrice = $value->swz_price * 10;
$seat_type .= '"9":"'.$swzPrice.'","A9":"¥'.$value->swz_price.'",'; $seat_type .= '"9":"'.$swzPrice.'","A9":"¥'.$value->swz_price.'",';
} }
} }
if(isset($value->dw_price)){ if(isset($value->dw_price)){
if($value->dw_price > 0){ if($value->dw_price > 0){
$seat_type .= '"F":"¥'.$value->dw_price.'",'; $seat_type .= '"F":"¥'.$value->dw_price.'",';
} }
} }
$pricestr = $seat_type.'"train_no":'.'"'.$value->train_no.'"'; $pricestr = $seat_type.'"train_no":'.'"'.$value->train_no.'"';
//余票字符串 //余票字符串
$return_data->data->result[$i] = '|预定|'.$value->train_no.'|'.$value->train_code.'|'.$value->from_station_name.'|'.$value->to_station_name.'|'.$value->from_station_code.'|'.$value->to_station_code.'|'.$value->start_time.'|'.$value->arrive_time.'|'.$value->run_time.'|'.$value->can_buy_now.'||'.$value->train_start_date.'||||||||'.$this->ticket_exchange($value->gjrw_num).'|'.$this->ticket_exchange($value->qtxb_num).'|'.$this->ticket_exchange($value->rw_num).'|'.$this->ticket_exchange($value->rz_num).'|'.$this->ticket_exchange($value->tdz_num).'|'.$this->ticket_exchange($value->wz_num).'||'.$this->ticket_exchange($value->yw_num).'|'.$this->ticket_exchange($value->yz_num).'|'.$this->ticket_exchange($value->edz_num).'|'.$this->ticket_exchange($value->ydz_num).'|'.$this->ticket_exchange($value->swz_num).'|'.$this->ticket_exchange($value->dw_num).'||'; $return_data->data->result[$i] = '|预定|'.$value->train_no.'|'.$value->train_code.'|'.$value->from_station_name.'|'.$value->to_station_name.'|'.$value->from_station_code.'|'.$value->to_station_code.'|'.$value->start_time.'|'.$value->arrive_time.'|'.$value->run_time.'|'.$value->can_buy_now.'||'.$value->train_start_date.'||||||||'.$this->ticket_exchange($value->gjrw_num).'|'.$this->ticket_exchange($value->qtxb_num).'|'.$this->ticket_exchange($value->rw_num).'|'.$this->ticket_exchange($value->rz_num).'|'.$this->ticket_exchange($value->tdz_num).'|'.$this->ticket_exchange($value->wz_num).'||'.$this->ticket_exchange($value->yw_num).'|'.$this->ticket_exchange($value->yz_num).'|'.$this->ticket_exchange($value->edz_num).'|'.$this->ticket_exchange($value->ydz_num).'|'.$this->ticket_exchange($value->swz_num).'|'.$this->ticket_exchange($value->dw_num).'||';
$data = '{"validateMessagesShowId":"_validatorMessage","status":true,"httpstatus":200,"data":{'.$pricestr.'},"messages":[],"validateMessages":{}}'; $data = '{"validateMessagesShowId":"_validatorMessage","status":true,"httpstatus":200,"data":{'.$pricestr.'},"messages":[],"validateMessages":{}}';
$return_data->data->price[$i] = $data; $return_data->data->price[$i] = $data;
$i++; $i++;
} }
} }
$return_data->data->map = (object)$obj; $return_data->data->map = (object)$obj;
print_r($return_data); print_r($return_data);
} }
} }
//获取价格(废弃) //获取价格(废弃)
/* /*
fromStationCode出发站三字码 fromStationCode出发站三字码
toStationCode:终点站三字码 toStationCode:终点站三字码
trainCode:车次号 trainCode:车次号
*/ */
public function get_price($fromStationCode=null,$toStationCode=null,$trainCode=null){ public function get_price($fromStationCode=null,$toStationCode=null,$trainCode=null){
if(!$fromStationCode || !$toStationCode || !$trainCode){ if(!$fromStationCode || !$toStationCode || !$trainCode){
exit('传参错误!'); exit('传参错误!');
}else{ }else{
$return_data = $this->BIZ_train_model->get_price($fromStationCode,$toStationCode,$trainCode); $return_data = $this->BIZ_train_model->get_price($fromStationCode,$toStationCode,$trainCode);
if(!empty($return_data)){ if(!empty($return_data)){
print_r(json_decode($return_data->TPL_Price)); print_r(json_decode($return_data->TPL_Price));
}else{ }else{
print_r('没有数据返回'); print_r('没有数据返回');
} }
} }
} }
//验证聚合返回的信息是否正确 //验证聚合返回的信息是否正确
function validateJuhe($trainInfo){ function validateJuhe($trainInfo){
if(!empty($trainInfo) && !empty(json_decode($trainInfo)->result)){ if(!empty($trainInfo) && !empty(json_decode($trainInfo)->result)){
return true; return true;
}else{ }else{
return false; return false;
} }
} }
//余票转换 //余票转换
function ticket_exchange($num){ function ticket_exchange($num){
if(isset($this->cache)){ if(isset($this->cache)){
$time = strtotime($this->train_date) - time(); $time = strtotime($this->train_date) - time();
$day = $time / 86400; $day = $time / 86400;
if($day > 15){ if($day > 15){
return '有'; return '有';
}else{ }else{
return $num; return $num;
} }
}else{ }else{
if(is_numeric($num)){ if(is_numeric($num)){
if($num == 0){ if($num == 0){
return '无'; return '无';
}elseif($num >= 99){ }elseif($num >= 99){
return '有'; return '有';
}else{ }else{
return $num; return $num;
} }
}else{ }else{
if($num == '--'){ if($num == '--'){
return ''; return '';
} }
} }
} }
} }
//发送请求 //发送请求
function get_http($url, $data = '', $method = 'GET') { function get_http($url, $data = '', $method = 'GET') {
$curl = curl_init(); // 启动一个CURL会话 $curl = curl_init(); // 启动一个CURL会话
curl_setopt($curl, CURLOPT_URL, $url); // 要访问的地址 curl_setopt($curl, CURLOPT_URL, $url); // 要访问的地址
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, 0); // 对认证证书来源的检查 curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, 0); // 对认证证书来源的检查
curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, 0); // 从证书中检查SSL加密算法是否存在 curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, 0); // 从证书中检查SSL加密算法是否存在
curl_setopt($curl, CURLOPT_USERAGENT, $_SERVER['HTTP_USER_AGENT']); // 模拟用户使用的浏览器 curl_setopt($curl, CURLOPT_USERAGENT, $_SERVER['HTTP_USER_AGENT']); // 模拟用户使用的浏览器
curl_setopt($curl, CURLOPT_FOLLOWLOCATION, 1); // 使用自动跳转 curl_setopt($curl, CURLOPT_FOLLOWLOCATION, 1); // 使用自动跳转
curl_setopt($curl, CURLOPT_AUTOREFERER, 1); // 自动设置Referer curl_setopt($curl, CURLOPT_AUTOREFERER, 1); // 自动设置Referer
if ($method == 'POST' && !empty($data)) { if ($method == 'POST' && !empty($data)) {
curl_setopt($curl, CURLOPT_POST, 1); // 发送一个常规的Post请求 curl_setopt($curl, CURLOPT_POST, 1); // 发送一个常规的Post请求
curl_setopt($curl, CURLOPT_POSTFIELDS, $data); // Post提交的数据包 curl_setopt($curl, CURLOPT_POSTFIELDS, $data); // Post提交的数据包
} }
curl_setopt($curl, CURLOPT_TIMEOUT, 45); // 设置超时限制防止死循环 curl_setopt($curl, CURLOPT_TIMEOUT, 45); // 设置超时限制防止死循环
curl_setopt($curl, CURLOPT_HEADER, 0); // 显示返回的Header区域内容 curl_setopt($curl, CURLOPT_HEADER, 0); // 显示返回的Header区域内容
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1); // 获取的信息以文件流的形式返回 curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1); // 获取的信息以文件流的形式返回
$tmpInfo = curl_exec($curl); // 执行操作 $tmpInfo = curl_exec($curl); // 执行操作
$errno = curl_errno($curl); $errno = curl_errno($curl);
if ($errno !== 0) { if ($errno !== 0) {
return false; return false;
$error_message = $errno . ' ' . curl_error($curl); //记录错误日志 $error_message = $errno . ' ' . curl_error($curl); //记录错误日志
log_message('error', "third_party/train_app/index/get_http curl {$error_message}"); log_message('error', "third_party/train_app/index/get_http curl {$error_message}");
} }
curl_close($curl); //关闭CURL会话 curl_close($curl); //关闭CURL会话
return $tmpInfo; //返回数据 return $tmpInfo; //返回数据
} }
} }
?> ?>

@ -59,21 +59,7 @@ class BIZ_train_model extends CI_Model {
AND AND
tpc_to_station = '$tpc_to_station'"; tpc_to_station = '$tpc_to_station'";
$query = $this->INFO->query($sql); $query = $this->INFO->query($sql);
return $query->row();
if($query->row()){
$cache_time = strtotime($query->row()->tpc_datetime);
$now_time = time();
$differ_time = ($now_time - $cache_time) / 86400;
if($differ_time >= 7){
$this->delete_traincache($tpc_from_station,$tpc_to_station);
return null;
}else{
return $query->row();
}
}else{
return null;
}
} }
//删除缓存操作 //删除缓存操作

Loading…
Cancel
Save