|
- <?php
- define( "API_USER", "zzcx01");
- define( "API_PASSWORD", "12345678");
- define( "API_SIGN", "03EF41375E5149EFB5CCD6AE236555C7");
- define( "DISNEY_CODE1", "SHDSN" );//单日票
- define( "DISNEY_CODE2", "SHDSN2" );//两日票
- define( "DISNEY_CODE3", "DSNSZW" );//演出票
-
- define( "API_USER2", "zzcx02");
- define( "API_PASSWORD2", "12345678");
- define( "API_SIGN2", "4E84E1EEBAF00B352DEF2B8F3336B63C");
- //define( "DISNEY_CODE1", "shz101" );//单日票
- //define( "DISNEY_CODE2", "shz101" );//两日票
- //define( "DISNEY_CODE3", "shz101" );//演出票
-
- define( "LOGIN_URL", "http://partner.zizaitrip.net/login" );
- define( "OPERATE_URL", "http://partner.zizaitrip.net/interface" );
-
- $_ary_goods_zizai_index = array(
- "成人票" => 0,
- "老人票" => 2,
- "儿童票" => 1,
- "成人票" => 3,
- "老人票" => 5,
- "儿童票" => 4,
- "AA区" => 0,
- "AB区" => 1,
- "BA区" => 2,
- "BB区" => 3,
- "CA区" => 4,
- "CB区" => 5
- );
-
- //向自在发送post参数(链接,参数数组)
- function send_post($url, $post_data) {
- $postdata = http_build_query($post_data);
- $options = array(
- 'http' => array(
- 'method' => 'POST',
- 'header' => 'Content-type:application/x-www-form-urlencoded',
- 'content' => $postdata,
- 'timeout' => 15 * 60 // 超时时间(单位:s)
- )
- );
- $context = stream_context_create($options);
- $result = file_get_contents($url, false, $context);
- return $result;
- }
-
- //向自在发送get参数(链接,参数数组)
- function send_get($url, $get_data) {
- $url_param = http_build_query($get_data);
- $result = file_get_contents($url."?{$url_param}");
- return $result;
- }
-
- //将xml转换为数组
- function xml_to_array($xml)
- {
- $ob = simplexml_load_string($xml);
- $json = json_encode($ob);
- $array = json_decode($json, true);
- return $array;
- }
-
- //获取数据(链接,参数数组)
- function base_api( $url, $get_data ) {
- $get_data["tt"] = rand(100000,999999);
- $return_result = send_get($url, $get_data);
- $return_result = xml_to_array($return_result);
- return $return_result;
- }
-
- //登录接口(用户名,密码)
- function login_api( $user, $pass ) {
- $get_data = array("user" => $user,"pass" => $pass);
- return base_api( LOGIN_URL, $get_data);
- }
-
- //票务系统线路列表查询(用户名,密码,操作参数)
- function run_list( $user, $pass, $sign = false ){
- $sign = $sign == false ? API_SIGN : $sign;
- $get_data = array("user" => $user,"sign" => $sign,"op" => "list");
- return base_api( OPERATE_URL, $get_data);
- }
-
- //获取线路运营日期数据(用户名,密码,操作参数,线路代码)
- function godate( $user, $pass, $projcode, $sign = false){
- $sign = $sign == false ? API_SIGN : $sign;
- $get_data = array("user" => $user,"sign" => $sign,"op" => "godate","projcode" => $projcode);
- return base_api( OPERATE_URL, $get_data);
- }
-
- //获取线路运营班次数据(用户名,密码,操作参数,线路代码,运营日期)
- function gorun( $user, $pass, $projcode ,$godate, $sign = false){
- $sign = $sign == false ? API_SIGN : $sign;
- $get_data = array("user" => $user,"sign" => $sign,"op" => "gorun","projcode" => $projcode,"godate" => $godate);
- return base_api( OPERATE_URL, $get_data);
- }
-
- //获取某个线路代码某一天的票种信息
- function get_ticket_array( $user, $pass, $projcode , $godate, $gotime = "" , $sign = false) {
- $sign = $sign == false ? API_SIGN : $sign;
- $return_result = gorun($user, $pass, $projcode ,$godate, $sign);
- $run_time = "";
- if( $return_result["code"] == 0 ) {
- if( !isset($return_result["go_run_list"]["run"]) ) {
- return false;
- }
- $run_array = $return_result["go_run_list"]["run"];
- if( isset($return_result["go_run_list"]["run"]["runid"]) ) {
- $run_id = $return_result["go_run_list"]["run"]["runid"];
- $run_time = $run_array["runtime"];
- } else {
- foreach ($run_array as $run_info) {
- if ( $gotime == "" || $run_info["runtime"] == $gotime) {
- $run_time = $run_info["runtime"];
- $run_id = $run_info["runid"];
- break;
- }
- }
- }
- } else {
- return false;
- }
- $return_result = ticket( $user, $pass, $projcode, $run_id, $sign);
- if( $return_result["code"] == 0 ) {
- $ticket_array = isset($return_result["ticket_list"]["ticket"]) ? $return_result["ticket_list"]["ticket"] : $return_result["ticket_list"];
- $ticket_array2 = array();
- foreach( $ticket_array as $key => $ticket_info ) {
- $ticket_info["godate"] = $godate;
- $ticket_info["gotime"] = $run_time;
- $ticket_array2[$key] = $ticket_info;
- }
- $ticket_array = $ticket_array2;
- } else {
- $ticket_array = false;
- }
- return $ticket_array;
- }
-
- //获取某个线路代码某一天的票种信息
- function get_ticket_array2( $user, $pass, $projcode , $godate ) {
- $return_result = gorun($user, $pass, $projcode ,$godate);
-
- $run_info_array = array();
- //var_dump($return_result);
- if( $return_result["code"] == 0 ) {
-
- if( !isset($return_result["go_run_list"]["run"]) ) {
- return false;
- }
- $run_array = $return_result["go_run_list"]["run"];
- if( isset($return_result["go_run_list"]["run"]["runid"]) ) {
- $run_info = array();
- $run_info["id"] = $return_result["go_run_list"]["run"]["runid"];
- $run_info["runtime"] = $return_result["go_run_list"]["run"]["runtime"];
- $run_info_array[] = $run_info;
- } else {
- foreach ($run_array as $run_info) {
- $run_info["id"] = $run_info["runid"];
- $run_info["runtime"] = $run_info["runtime"];
- $run_info_array[] = $run_info;
- }
- }
- } else {
- return false;
- }
- $return_array = array();
- foreach( $run_info_array as $run_info ) {
- $run_id = $run_info["id"];
- $return_result = ticket($user, $pass, $projcode, $run_id);
- if ($return_result["code"] == 0) {
- $ticket_array = $return_result["ticket_list"]["ticket"];
- $return_array[$run_info["runtime"]] = $ticket_array;
- }
- }
- return $return_array;
- }
-
- //获取迪士尼单日票信息
- function get_disney_info( $godate, $gotime = "" ) {
- $ticket_array = get_ticket_array( API_USER,API_PASSWORD, DISNEY_CODE1, $godate, $gotime );
- if( $ticket_array == false ) { return false; }
- $ticket_array2 = array();
- foreach( $ticket_array as $ticket_info ) {
- $index_name = mb_substr($ticket_info["ticketname"],4,3,'utf-8');
- $ticket_array2[$index_name] = $ticket_info;
- }
- return $ticket_array2;
- }
-
- //获取迪士尼两日票信息
- function get_disney_info2( $godate, $gotime = "" ) {
- $ticket_array = get_ticket_array( API_USER,API_PASSWORD, DISNEY_CODE2, $godate, $gotime );
- if( $ticket_array == false ) { return false; }
- $ticket_array2 = array();
- foreach( $ticket_array as $ticket_info ) {
- $index_name = mb_substr($ticket_info["ticketname"],0,5,'utf-8');
- $ticket_array2[$index_name] = $ticket_info;
- }
- return $ticket_array2;
- }
-
- //获取迪士尼一日两日票信息 顺序:单日成人 单日儿童 单日老人 双人成人 双日儿童 双日老人
- function get_disney_all_info( $godate ) {
- $_ary_disney_index = array(
- "成人票" => 0,
- "老人票" => 2,
- "儿童票" => 1,
- "二日成人票" => 3,
- "二日老人票" => 5,
- "二日儿童票" => 4
- );
- $return_array = array( 0,0,0,0,0,0 );
- $disney_array = get_disney_info( $godate );
- $disney_array2 = get_disney_info2( $godate );
- if( $disney_array != false ) {
- foreach( $disney_array as $key => $disney_info ) {
- $return_index = $_ary_disney_index[$key];
- $return_array[$return_index] = $disney_info["ticketcount"];
- }
- }
- if( $disney_array2 != false ) {
- foreach( $disney_array2 as $key => $disney_info ) {
- $return_index = $_ary_disney_index[$key];
- $return_array[$return_index] = $disney_info["ticketcount"];
- }
- }
- return $return_array;
- }
-
- function get_lion_king_info( $godate, $gotime = "" ) {
- $_ary_lionking_index = array(
- "0" => 0,
- "1" => 1,
- "2" => 2,
- "3" => 3,
- "4" => 4,
- "5" => 5
- );
- $return_price = array( 0,0,0,0,0,0 );
- $return_array = array( 0,0,0,0,0,0 );
- $return_tickets = array();
- $lion_array = get_disney_info3( $godate, $gotime);
- if( $lion_array != false ) {
- if( isset($lion_array["ticketid"]) ) {
- $lion_array2 = array();
- $lion_array2[] = $lion_array;
- $lion_array = $lion_array2;
- }
- foreach ($lion_array as $key => $lion_info) {
- if (substr_count($lion_info['ticketname'], 'AA')) {
- $return_array[0] = $lion_info["ticketcount"];
- $return_price[0] = $lion_info["ticketprice"];
- $return_tickets[0] = $lion_info;
- } elseif (substr_count($lion_info['ticketname'], 'AB')) {
- $return_array[1] = $lion_info["ticketcount"];
- $return_price[1] = $lion_info["ticketprice"];
- $return_tickets[1] = $lion_info;
- } elseif (substr_count($lion_info['ticketname'], 'BA')) {
- $return_array[2] = $lion_info["ticketcount"];
- $return_price[2] = $lion_info["ticketprice"];
- $return_tickets[2] = $lion_info;
- } elseif (substr_count($lion_info['ticketname'], 'BB')) {
- $return_array[3] = $lion_info["ticketcount"];
- $return_price[3] = $lion_info["ticketprice"];
- $return_tickets[3] = $lion_info;
- } elseif (substr_count($lion_info['ticketname'], 'CA')) {
- $return_array[4] = $lion_info["ticketcount"];
- $return_price[4] = $lion_info["ticketprice"];
- $return_tickets[4] = $lion_info;
- } elseif (substr_count($lion_info['ticketname'], 'CB')) {
- $return_array[5] = $lion_info["ticketcount"];
- $return_price[5] = $lion_info["ticketprice"];
- $return_tickets[5] = $lion_info;
- }
- }
- }
- return array('tic_info'=>$return_array,'price'=>$return_price,'ticket_array'=>$return_tickets);
- }
-
- //传入参数 buy_array 购买票数的数组 array(0,0,0,0,0,0)
- //返回值 -1 库存不足 0 出票失败 其他 成功且返回自在订单号
- function buy_disney_ticket( $cus_name, $cus_mobile, $cus_idno, $buy_array, $godate ) {
- $_ary_disney_index = array(
- "成人票" => 0,
- "老人票" => 2,
- "儿童票" => 1,
- "二日成人票" => 3,
- "二日老人票" => 5,
- "二日儿童票" => 4
- );
- $disney_array = get_disney_info( $godate );
- $disney_array2 = get_disney_info2( $godate );
- $disney_all_array = array();
- if( false != $disney_array ) {
- foreach( $disney_array as $key => $disney_info ) {
- $return_index = $_ary_disney_index[$key];
- $disney_all_array[$return_index] = $disney_info;
- }
- }
- if( false != $disney_array2 ) {
- foreach( $disney_array2 as $key => $disney_info ) {
- $return_index = $_ary_disney_index[$key];
- $disney_all_array[$return_index] = $disney_info;
- }
- }
- $buy_prod_txt = "";
- foreach( $buy_array as $key => $buy_num ) {
- $disney_info = $disney_all_array[$key];
- if( $disney_info["ticketcount"] < $buy_num ) {
- return -1;
- }
- $buy_prod_txt .= $disney_info["ticketid"] . "P" . $buy_num . "|";
- }
- $customer_txt = '{|' . $cus_name . '|' . $cus_mobile . '|' . $cus_idno . '||}';
- $result_info = lock(API_USER, API_PASSWORD, 15, $buy_prod_txt, $customer_txt, "", "", "");
- if ($result_info["code"] == 0) {
- $trade_no = $result_info["tradeno"];
- } else {
- return 0;
- }
- $result_info2 = eticket(API_USER, API_PASSWORD, $trade_no);
- if ($result_info2["code"] == 0) {
- return $trade_no;
- } else {
- return 0;
- }
- }
-
- //传入参数 buy_array 购买票数的数组 array(0,0,0,0,0,0)
- //返回值 -1 库存不足 0 出票失败 其他 成功且返回自在订单号
- function buy_lionking_ticket( $cus_name, $cus_mobile, $cus_idno, $buy_array, $godate, $gotime = "" ) {
- $_ary_lionking_index = array(
- "AA区" => 0,
- "AB区" => 1,
- "BA区" => 2,
- "BB区" => 3,
- "CA区" => 4,
- "CB区" => 5
- );
- $lion_array = get_disney_info3( $godate, $gotime);
- $lion_all_array = array();
- if( $lion_array != false ) {
- foreach( $lion_array as $key => $lion_info ) {
- $return_index = $_ary_lionking_index[$key];
- $lion_all_array[$return_index] = $lion_info;
- }
- }
-
- $buy_prod_txt = "";
- foreach( $buy_array as $key => $buy_num ) {
- $lionking_info = $lion_all_array[$key];
- if( $lionking_info["ticketcount"] < $buy_num ) {
- return -1;
- }
- $buy_prod_txt .= $lionking_info["ticketid"] . "P" . $buy_num . "|";
- }
- $customer_txt = '{|' . $cus_name . '|' . $cus_mobile . '|' . $cus_idno . '||}';
- $result_info = lock(API_USER, API_PASSWORD, 15, $buy_prod_txt, $customer_txt, "", "", "");
- if ($result_info["code"] == 0) {
- $trade_no = $result_info["tradeno"];
- } else {
- return 0;
- }
- $result_info2 = eticket(API_USER, API_PASSWORD, $trade_no);
- if ($result_info2["code"] == 0) {
- return $trade_no;
- } else {
- return 0;
- }
- }
-
-
- //获取迪士尼演出信息
- function get_disney_info3( $godate, $gotime = "" ) {
- $ticket_array = get_ticket_array( API_USER,API_PASSWORD, DISNEY_CODE3, $godate, $gotime );
- if( $ticket_array == false ) { return false; }
- $ticket_array2 = array();
- foreach( $ticket_array as $ticket_info ) {
- $index_name = mb_substr($ticket_info["ticketname"],2,3,'utf-8');
- $ticket_array2[$index_name] = $ticket_info;
- }
- return $ticket_array2;
- }
-
- //获取线路运营班次返程日期数据(用户名,密码,操作参数,线路代码,去程班次id)
- function backdate( $user, $pass, $projcode ,$runid, $sign = false){
- $sign = $sign == false ? API_SIGN : $sign;
- $get_data = array("user" => $user,"sign" => $sign,"op" => "backdate","projcode" => $projcode,"runid" => $runid);
- return base_api( OPERATE_URL, $get_data);
- }
-
- //获取线路特定班次返程班次数据(用户名,密码,操作参数,线路代码,去程班次id,回程日期)
- function backrun( $user, $pass, $projcode ,$runid ,$backdate, $sign = false){
- $sign = $sign == false ? API_SIGN : $sign;
- $get_data = array("user" => $user,"sign" => $sign,"op" => "backrun","projcode" => $projcode,"runid" => $runid,"backdate" => $backdate);
- return base_api( OPERATE_URL, $get_data);
- }
-
- //获取班次票种数据(用户名,密码,操作参数,线路代码,去程班次id)
- function ticket( $user, $pass, $projcode ,$runid, $sign = false){
- $sign = $sign == false ? API_SIGN : $sign;
- $get_data = array("user" => $user,"sign" => $sign,"op" => "ticket","projcode" => $projcode,"runid" => $runid);
- return base_api( OPERATE_URL, $get_data);
- }
-
- //票务系统锁位(用户名,密码,操作参数,锁位时间,票种id及张数中间用‘P’隔开,订单客人信息,会员ID,优惠码,会员积分)
- function lock( $user, $pass, $lock = 15 ,$ticket ,$customer = "",$memid = "",$barcode = "",$score= "", $sign = false){
- $sign = $sign == false ? API_SIGN : $sign;
- $get_data = array("user" => $user,"sign" => $sign,"op" => "lock","lock" => $lock,"ticket" => $ticket,"customer" => $customer,"memid" => $memid,"barcode" => $barcode,"score" => $score);
- return base_api( OPERATE_URL, $get_data);
- }
-
- //票务系统订单确认(用户名,密码,操作参数,票务系统订单号)
- function eticket( $user, $pass, $tradeno, $sign = false){
- $sign = $sign == false ? API_SIGN : $sign;
- $get_data = array("user" => $user,"sign" => $sign,"op" => "eticket","tradeno" => $tradeno);
- return base_api( OPERATE_URL, $get_data);
- }
-
- //票务系统更新补充客户数据(用户名,密码,操作参数,票务系统订单号,客户信息)
- function customer( $user, $pass, $tradeno ,$customerlist, $sign = false){
- $sign = $sign == false ? API_SIGN : $sign;
- $get_data = array("user" => $user,"sign" => $sign,"op" => "customer","tradeno" => $tradeno,"customerlist" => $customerlist);
- return base_api( OPERATE_URL, $get_data);
- }
-
- //票务系统订单状态查询(用户名,密码,操作参数,票务系统订单号)
- function status( $user, $pass, $tn, $sign = false){
- $sign = $sign == false ? API_SIGN : $sign;
- $get_data = array("user" => $user,"sign" => $sign,"op" => "status","tn" => $tn);
- return base_api( OPERATE_URL, $get_data);
- }
-
- //获取线路产品介绍信息(用户名,密码,操作参数,产品代码)
- function circuitry( $user, $pass, $op, $ccode, $sign = false){
- $sign = $sign == false ? API_SIGN : $sign;
- $get_data = array("user" => $user,"sign" => $sign,"op" => "circuitry","ccode" => $ccode);
- return base_api( OPERATE_URL, $get_data);
- }
-
|