You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
information-system/application/controllers/ht_flight.php

226 lines
11 KiB
PHP

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

<?php
if (!defined('BASEPATH'))
exit('No direct script access allowed');
class Ht_flight extends CI_Controller {
function __construct() {
parent::__construct();
//$this->output->enable_profiler(TRUE);
$this->load->model('Air_model');
}
//航班查询
public function index() {
$depart_city_code = $this->input->get('star');
$arrive_city_code = $this->input->get('dest');
$depart_date = $this->input->get('rDate');
echo $depart_city_code.$arrive_city_code.$depart_date;
if (empty($depart_city_code) || empty($arrive_city_code) || empty($depart_date)) {
echo '请输入正确的参数';
} else {
$depart_city_name = $this->Air_model->get_city_by_code($depart_city_code);
$arrive_city_name = $this->Air_model->get_city_by_code($arrive_city_code);
redirect("http://flight.elong.com/$depart_city_name-$arrive_city_name/?departdate=$depart_date");
}
}
//酒店详情页
public function hotel($cityname,$hotelname,$checkIn=false,$checkOut=false)
{
$cityname=trim($cityname);
if (empty($cityname) || empty($hotelname)) {
die('请输入正确的参数');
}
//格式化城市名和酒店名
$cityname=urldecode($cityname);
$hotelname=urldecode($hotelname);
$cityname=iconv("GBK", "UTF-8", $cityname);
$hotelname=iconv("GBK", "UTF-8", $hotelname);
$hotelname=str_replace('(', '', $hotelname);
$hotelname=str_replace(')', '', $hotelname);
//$hotelname=preg_replace("/\(.*\)/", '', $hotelname);
//格式化预订日期
($checkIn==false || strtotime($checkIn)<time()) && $checkIn=date('Y-m-d',time()+2*24*60*60);
($checkOut==false || strtotime($checkOut)<time()) && $checkOut=date('Y-m-d',time()+3*24*60*60);
$checkIn=date('Y-m-d',strtotime($checkIn));
$checkOut=date('Y-m-d',strtotime($checkOut));
//拼接酒店列表页链接
$this->lang->load('hotel_city_info');
$city_info=$this->lang->line('hotel_city_info');
$city_info=$city_info["$cityname"];
$city=strtolower($city_info['CityEName']);
$search_str=$city.$city_info['City'];
$search_str=str_replace(' ', '', $search_str);
//如果是XXX酒店原XXX酒店这类名称则把括号里的备注去掉
preg_match("/(.*)/", $hotelname, $backup);
$backup=isset($backup[1])? trim($backup[1]):'';
if (strpos($backup,'原')===0) {
$hotelname=str_replace(''.$backup.'', '', $hotelname);
}
$new_hotelname=preg_replace("/(.*)/", '', $hotelname);
$hotelname=urlencode($hotelname);
//获取酒店列表页内容
$data['url']='http://hotels.ctrip.com/hotel/'.$search_str.'/k1'.$hotelname;
$filecontents = $this->curl_data($data['url']);
//获取酒店详细页和价格列表页的链接
preg_match_all('/<h2 class=\"searchresult_name\"(.*)<\/h2>/i', $filecontents, $matches);
preg_match('/<a href=\"(.*)\" data-dopost=/i', $matches[1][0], $store);
//如果没有匹配的结果则提醒,并跳转到携程官网查询
$market=preg_replace("/\(.*\)/", '', ltrim(strip_tags($matches[0][0]),'1'));
if ($market!=$new_hotelname) {
//echo '<h1 style="margin: 100px auto;width: 600px;">暂无匹配的酒店数据(或者匹配出错)<br>请把酒店名提交给梁宇云<img align="absMiddle" src="http://www.mycht.cn/js/TQEditor/face/51.gif" emot="51" style="width: 35px;margin-top: -11px;"><br><p style="margin-top:50px;font-size:18px;"><a target="_blank" href="'.$data['url'].'">跳转到携程官方网站进行查看</a></p></h1>';
//die();
}
$detail_url='http://hotels.ctrip.com'.$store[1].'/?checkIn='.$checkIn.'&checkOut='.$checkOut;
$hotelid=trim(str_replace(array('/hotel/','.html'), '', $store[1]));
$price_url="http://hotels.ctrip.com/Domestic/tool/AjaxHotelPriceNew.aspx?type=new&city=".$city_info['City']."&hotel=$hotelid&startDate=$checkIn&depDate=$checkOut&RequestTravelMoney=F&promotion=F&prepay=F&IsCanReserve=F&IsJustConfirm=F&OrderType=desc";
preg_match('/<li class=\"searchresult_info_judge\">(.*)<\/li><li class=\"hotel_favorite_info\">/i', $filecontents, $score);
$data['hotel_score']=str_replace('<li class="hotel_favorite_info">', '', $score[0]);
$data['hotelid']=$hotelid;
$data['cityid']=$city_info['City'];
$detail=$this->curl_data($detail_url);
$preg = "/<script[\s\S]*?<\/script>/i";
$detail=preg_replace($preg,"",$detail);
if(mb_detect_encoding($detail,"UTF-8, ISO-8859-1, GBK")!="UTF-8" ) {
$detail=iconv("gbk","utf-8",$detail);
}
$length=stripos($detail, '<div id="hotelRoomBox"');
$data['part1']=substr($detail,0,$length);
$data['part2']=substr($detail,$length+24);
$data['part2']=substr(trim($data['part2']),6);
$this->load->view('ctrip_hotel',$data);
}
public function hotel_price_list($cityid,$hotelid,$checkIn=false,$checkOut=false)
{
//格式化预订日期
$checkIn==false && $checkIn=date('Y-m-d',time()+2*24*60*60);
$checkOut==false && $checkOut=date('Y-m-d',time()+3*24*60*60);
$checkIn=date('Y-m-d',strtotime($checkIn));
$checkOut=date('Y-m-d',strtotime($checkOut));
//获取价格列表
$price_url="http://hotels.ctrip.com/Domestic/tool/AjaxHotelPriceNew.aspx?type=new&city=$cityid&hotel=$hotelid&startDate=$checkIn&depDate=$checkOut&RequestTravelMoney=F&promotion=F&prepay=F&IsCanReserve=F&IsJustConfirm=F&OrderType=desc";
$price_list=$this->curl_data($price_url);
if(mb_detect_encoding($price_list,"UTF-8, ISO-8859-1, GBK")!="UTF-8" ) {
$price_list=iconv("gbk","utf-8",$price_list);
}
echo $price_list;
}
public function hotel_other_price($hotelid,$checkIn=false,$checkOut=false)
{
//格式化预订日期
$checkIn==false && $checkIn=date('Y-m-d',time()+2*24*60*60);
$checkOut==false && $checkOut=date('Y-m-d',time()+3*24*60*60);
$checkIn=date('Y-m-d',strtotime($checkIn));
$checkOut=date('Y-m-d',strtotime($checkOut));
//获取价格列表
$price_url="http://hotels.ctrip.com/domestic/comparepricepanel/loadlist/?hotelId=$hotelid&checkIn=$checkIn&checkOut=$checkOut&returnCash=1";
$html=$this->curl_data($price_url);
if(mb_detect_encoding($html,"UTF-8, ISO-8859-1, GBK")!="UTF-8" ) {
$html=iconv("gbk","utf-8",$html);
}
echo $html;
}
public function curl_data($url)
{
$ch2 = curl_init();
curl_setopt($ch2, CURLOPT_TIMEOUT, 30);
curl_setopt($ch2, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch2, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch2, CURLOPT_SSL_VERIFYHOST, false);
curl_setopt($ch2, CURLOPT_URL, $url);
$filecontents = curl_exec($ch2);
curl_close($ch2);
return $filecontents;
}
//携程酒店预订接口测试
public function test()
{
header("Content-type: text/html; charset=utf-8");
$this->load->library('Ctripapi');
//酒店详情
$city_code='33';
$area_id='';
$hotel_name='桂林漓江大瀑布饭店';
$result=$this->ctripapi->hotel_search($city_code,$area_id,$hotel_name);
//酒店价格计划列表
$hotel_code='437337';
$date_start='2015-10-12';
$date_end='2015-10-13';
//$result=$this->ctripapi->hotel_rate_plan($hotel_code,$date_start,$date_end);
//酒店价格缓存变化
$hotel_code='437337';
$city_code='33';
//$result=$this->ctripapi->hotel_cache_change($hotel_code,$city_code);
//酒店可订性检查
$hotel_code='437337';
$rateplan_code='6925134';
$start_stmp='2015-10-12';
$end_stmp='2015-10-13';
$arrival_stmp='2015-10-12 15:00:00';
$quantity=1;
$count=2;
//$result=$this->ctripapi->hotel_avail($hotel_code,$rateplan_code,$start_stmp,$end_stmp,$arrival_stmp,$quantity,$count);
//酒店订单生成
$data['hotel_code'] = '437337'; //酒店ID
$data['rateplan_code'] = '17661'; //价格计划ID
$data['unique_id'] = ''; //联盟用户在携程的uniqueid
$data['number_of_units'] = '1'; //预订房间数
$data['arrival_time'] = '10:00:00+08:00'; //入住人最早到店时间
$data['late_arrival_time'] = '19:00:00+08:00'; //入住人最早最晚时间
$data['surname'] = array('梁宇云'); //入住人姓名列表
$data['contact_type'] = 'tel'; //确认联系人方式:sms/email/fax/non 手机短消息/电邮/传真/无需确认
$data['contact_name'] = '梁宇云'; //联系人姓名
$data['phone_number'] = '15677370410'; //电话号码
$data['phone_tech_type'] = '1'; //电话类型
$data['contact_email'] = '2355711191@qq.com'; //联系邮箱
$data['start_stmp'] = '2015-10-12T00:00:00+08:00'; //入住开始时间
$data['end_stmp'] = '2015-10-13T00:00:00+08:00'; //入住结束时间
$data['count'] = '2'; //客人数量
$data['per_room'] = 'false'; //客人数量是否对应每间房false表示所有房间加起来一共住这么多客人
$data['special_text'] = '有窗'; //客人特殊要求
$data['amount_before_tax'] = '660'; //税前订单总价
$data['amount_currency'] = 'CNY'; //货币单位
$data['guarante_code'] = false; //担保标记:1:峰时担保2全额担保3超时担保4一律担保5手机担保
$data['guarantee_type'] = 'CC/DC/Voucher'; //信用卡担保类型(暂时只支持此类型)
$data['card_type'] = ''; //磁卡类型参考CodeList(CCT)
$data['card_number'] = ''; //信用卡号
$data['series_code'] = ''; //串号信用卡背后的3位数字
$data['effective_date'] = ''; //生效日期
$data['expire_date'] = ''; //失效日期
$data['card_holder_name'] = ''; //持卡人姓名
$data['card_holder_idcard'] = ''; //持卡人身份证
$data['guarante_amount'] = '0'; //接收到的担保金额
$data['guarante_currency'] = 'CNY'; //货币单位
$data['cancel_penalty_amount'] = ''; //取消罚金金额,取消罚金数量等于担保金数量
$data['cancel_penalty_currency']= 'CNY'; //取消罚金单位
$data['cancel_penalty_start'] = ''; //最迟的取消时间,在这个时间前取消不需要扣除罚金
$data['cancel_penalty_end'] = ''; //表示在这个时间段取消是需要扣除罚金
//$result=$this->ctripapi->hotel_res($data);
var_dump($result);
}
}