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/third_party/flightsystem/controllers/api.php

72 lines
2.5 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 api extends CI_Controller{
public function __construct(){
parent::__construct();
$this->load->helper('tuniu');
}
public function index(){
}
public function searchForHt(){
$departDate = $this->input->get_post('departDate');
$departCode = $this->input->get_post('departCode');
$arriveCode = $this->input->get_post('arriveCode');
if(empty($departDate) || empty($departCode) || empty($arriveCode)){
exit('请传入正确的参数,如有疑问请联系CYC');
}
$url = 'https://www.trainspread.com/guide.php/flight/search/?departDate='.$departDate.'&departCode='.$departCode.'&arriveCode='.$arriveCode;
$json = post_tuniu($url);
$data['data'] = json_decode($json);
$this->load->view('searchForHt',$data);
}
public function addorders(){
//接收参数
$departime = $this->input->get_post('departime');
$fromcode = $this->input->get_post('fromcode');
$tocode = $this->input->get_post('tocode');
$flightnumber = $this->input->get_post('flightnumber');
//测试数据
$deparTime = '2019-08-15';
$fromCode = 'BJS';
$toCode = 'SHA';
$flightNumber = 'KN5955';
//查询到sessionid
$searchJson = get_serach_json($deparTime,$fromCode,$toCode,$flightNumber);
$returnJson = post_tuniu(TUNIU_FLIGHT_API,$searchJson,'POST');
$returnData = json_decode($returnJson);
$sessionId = $returnData->data->queryResultList['0']->resourceList['0']->sessionId;
//$sessionId = 'eyJuYW1lIjoiZGlzdE5ldyIsImZrIjoiTkFZI1NIQSNLTjU5NTUjMjAxOS0wOC0xNSIsInNpIjo4LCJjYSI6IlkiLCJjbyI6IkgiLCJhcCI6IjUxOCIsImNwIjoiNzcyIn0';
echo $sessionId;
//获取航班信息,订单信息
//拼接下单报文
$data = '{"contactTel":"18877381547","flight":{"adtPrice":1111,"arriveCityCode":"SHA","cabinClass":"Y","cabinCode":"H","departureCityCode":"BJS","departureDate":"2019-08-15","flightNum":"KN5955"},"remark":"haina123456","sessionId":"'.$sessionId.'","touristList":[{"birthday":"1992-08-13","firstName":"chen","lastName":"yuchao","name":"陈宇超","personType":"ADT","psptId":"450302199208131039","psptType":1,"tel":"18877381547"}]}';
$timestamp = time();
$sign = md5(TUNIU_FLIGHT_KEY.$data.$timestamp);
$bookJson = '{
"purchaseId": '.TUNIU_FLIGHT_ID.',
"sign": "'.$sign .'",
"timestamp": '.$timestamp.',
"function": "createOrder",
"data":'.$data.'
}';
//echo $bookJson;die();
$returnJson = post_tuniu(TUNIU_FLIGHT_API,$bookJson,'POST');
//print_r($returnData);
echo $returnJson;
//生成报文
}
}