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

229 lines
6.7 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(){
exit('前方高能!!');
}
//帐号绑定
public function bindAccount(){
$timestamp = time();
$data = '{"account":"phoebe@hainatravel.com","defaultPay":0}';
$sign = md5(TUNIU_FLIGHT_KEY.$data.$timestamp);
$accountJson = '{
"purchaseId": '.TUNIU_FLIGHT_ID.',
"sign": "'.$sign .'",
"function": "paymentSign",
"timestamp": '.$timestamp.',
"data":'.$data.'
}';
$returnJson = post_tuniu(TUNIU_FLIGHT_API,$accountJson,'POST');
//print_r($returnData);
echo $returnJson;
}
//查询钱包接口
public function checkWallet(){
$timestamp = time();
$data = '{}';
$sign = md5(TUNIU_FLIGHT_KEY.$data.$timestamp);
$walletJson = '{
"purchaseId": '.TUNIU_FLIGHT_ID.',
"sign": "'.$sign .'",
"function": "tuNiuWalletInfo",
"timestamp": '.$timestamp.',
"data":'.$data.'
}';
$returnJson = post_tuniu(TUNIU_FLIGHT_API,$walletJson,'POST');
//print_r($returnData);
echo $returnJson;
}
//保险查询
public function getinsurance(){
$timestamp = time();
$data = '{}';
$sign = md5(TUNIU_FLIGHT_KEY.$data.$timestamp);
$insuranceJson = '{
"purchaseId": '.TUNIU_FLIGHT_ID.',
"sign": "'.$sign .'",
"function": "insurance",
"timestamp": '.$timestamp.',
"data":'.$data.'
}';
$returnJson = post_tuniu(TUNIU_FLIGHT_API,$insuranceJson,'POST');
//print_r($returnData);
echo $returnJson;
}
//查询接口
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-11-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":"'.$toCode.'","cabinClass":"Y","cabinCode":"H","departureCityCode":"'.$fromCode.'","departureDate":"'.$deparTime.'","flightNum":"'.$flightNumber.'"},"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;
//生成报文
}
//请求支付接口
public function payorders(){
$order = $this->input->get_post('order');
$order = '1226443588';
if(empty($order)){
exit('订单号为空');
}else{
//拼接支付报文
$timestamp = time();
$data = '{"account":"phoebe@hainatravel.com","orderId":"'.$order.'","payType":1}';
$sign = md5(TUNIU_FLIGHT_KEY.$data.$timestamp);
$payjson = '{
"purchaseId": '.TUNIU_FLIGHT_ID.',
"sign": "'.$sign .'",
"timestamp": '.$timestamp.',
"function": "paymentOrder",
"data":'.$data.'
}';
$returnJson = post_tuniu(TUNIU_FLIGHT_API,$payjson,'POST');
echo $returnJson;
}
}
//单个订单详情查询接口
public function getorderinfos(){
$order = $this->input->get_post('order');
if(empty($order)){
exit('订单号为空');
}else{
//拼接支付报文
$timestamp = time();
$data = '{"orderId":"'.$order.'"}';
$sign = md5(TUNIU_FLIGHT_KEY.$data.$timestamp);
$orderinfojson = '{
"purchaseId": '.TUNIU_FLIGHT_ID.',
"sign": "'.$sign .'",
"timestamp": '.$timestamp.',
"function": "orderDetail",
"data":'.$data.'
}';
$returnJson = post_tuniu(TUNIU_FLIGHT_API,$orderinfojson,'POST');
echo $returnJson;
}
}
//机票退票费查询接口
public function refundfee(){
$order = $this->input->get_post('order');
$ticketcode = $this->input->get_post('ticketcode');
$order = '1226443588';
$ticketcode = '822-2386171483';
if(empty($order)){
exit('订单号为空');
}else{
//拼接支付报文
$timestamp = time();
$data = '{"orderId":'.$order.',"ticketCodeList":["'.$ticketcode.'"]}';
$sign = md5(TUNIU_FLIGHT_KEY.$data.$timestamp);
$refundfeejson = '{
"purchaseId": '.TUNIU_FLIGHT_ID.',
"sign": "'.$sign .'",
"timestamp":'.$timestamp.',
"function":"refundFee",
"data":'.$data.'
}';
//echo $refundfeejson;die();
$returnJson = post_tuniu(TUNIU_FLIGHT_API,$refundfeejson,'POST');
echo $returnJson;
}
}
//机票退票接口
public function refundapply(){
$order = $this->input->get_post('order');
$ticketcode = $this->input->get_post('ticketcode');
$order = '1226443588';
$ticketcode = '822-2386171483';
if(empty($order)){
exit('订单号为空');
}else{
//拼接支付报文
$timestamp = time();
$data = '{"attachmentList":[],"orderId":"'.$order.'","refundReason":"行程调整","refundType":1,"ticketCodeList":["'.$ticketcode.'"]}';
$sign = md5(TUNIU_FLIGHT_KEY.$data.$timestamp);
$returnorderjson = '{
"purchaseId": '.TUNIU_FLIGHT_ID.',
"sign": "'.$sign .'",
"timestamp": '.$timestamp.',
"function": "refundApply",
"data":'.$data.'
}';
echo $returnorderjson;die();
$returnJson = post_tuniu(TUNIU_FLIGHT_API,$returnorderjson,'POST');
echo $returnJson;
}
}
}