|
- <?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_USER", "zzcx02");
- //define( "API_PASSWORD", "12345678");
- //define( "API_SIGN", "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 = API_SIGN;
- $get_data = array("user" => $user,"sign" => $sign,"op" => "list");
- return base_api( OPERATE_URL, $get_data);
- }
-
- //获取线路运营日期数据(用户名,密码,操作参数,线路代码)
- function godate( $user, $pass, $projcode){
- $sign = API_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 = API_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 = "" ) {
- $return_result = gorun($user, $pass, $projcode ,$godate);
- //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_id = $return_result["go_run_list"]["run"]["runid"];
- } else {
- foreach ($run_array as $run_info) {
- if ( $gotime == "" || $run_info["runtime"] == $gotime) {
- $run_id = $run_info["runid"];
- break;
- }
- }
- }
- } else {
- return false;
- }
- $return_result = ticket( $user, $pass, $projcode, $run_id);
- if( $return_result["code"] == 0 ) {
- $ticket_array = $return_result["ticket_list"]["ticket"];
- } else {
- $ticket_array = false;
- }
- return $ticket_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();
-
- return $ticket_array;
- }
-
- //获取迪士尼两日票信息
- 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 $k=>$v) {
- $ticket_array2[$k+3]=$v;
- }
- return $ticket_array2;
- }
-
- //获取迪士尼一日两日票信息 顺序:单日成人 单日儿童 单日老人 双人成人 双日儿童 双日老人
- function get_disney_all_info( $godate ) {
- $_ary_disney_index = array(
- "0" => 0,
- "2" => 2,
- "1" => 1,
- "3" => 3,
- "5" => 5,
- "4" => 4
- );
- $return_array = array( 0,0,0,0,0,0 );
- $return_price = array( 499,375,375,950,710,710 );
- $disney_array = get_disney_info( $godate );
- $disney_array2 = get_disney_info2( $godate );
- //return $disney_array2;
- if( $disney_array != false ) {
- foreach( $disney_array as $key => $disney_info ) {
- $return_index = $_ary_disney_index[$key];
- $return_array[$return_index] = isset($disney_info["ticketcount"])?$disney_info["ticketcount"]:'0';
- $return_price[$return_index] = isset($disney_info["ticketprice"])?$disney_info["ticketprice"]:'0';
- }
- }
- if( $disney_array2 != false ) {
- foreach( $disney_array2 as $key => $disney_info ) {
- $return_index = $_ary_disney_index[$key];
- $return_array[$return_index] = isset($disney_info["ticketcount"])?$disney_info["ticketcount"]:'0';
- $return_price[$return_index] = isset($disney_info["ticketprice"])?$disney_info["ticketprice"]:'0';
- }
- }
- return array('tic_info'=>$return_array,'price'=>$return_price);
- }
-
- 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( 1000,800,590,490,390,290 );
- $return_array = array( 0,0,0,0,0,0 );
- $lion_array = get_disney_info3( $godate, $gotime);
- if( $lion_array != false ) {
- foreach( $lion_array as $key => $lion_info ) {
- $return_index = $_ary_lionking_index[$key];
- $return_array[$return_index] = $lion_info["ticketcount"];
- $return_price[$return_index] = $lion_info["ticketprice"];
- }
- }
- return array('tic_info'=>$return_array,'price'=>$return_price);
- }
-
- //传入参数 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" => 0,
- "2" => 2,
- "1" => 1,
- "3" => 3,
- "5" => 5,
- "4" => 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 = isset($disney_all_array[$key]) ? $disney_all_array[$key] : array("ticketcount" => 0);
- if( $disney_info["ticketcount"] < $buy_num ) {
- return -1;
- }
- if( $buy_num > 0 ) {
- $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;
- }
- return $trade_no;
- $result_info2 = eticket(API_USER, API_PASSWORD, $trade_no);
- if ($result_info2["code"] == 0) {
- return $trade_no;
- } else {
- return 0;
- }
- }
-
- function true_buy_disney($trade_no){
- return $trade_no;
- $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(
- "0" => 0,
- "1" => 1,
- "2" => 2,
- "3" => 3,
- "4" => 4,
- "5" => 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;
- }
- }
- // return $lion_all_array;
- $buy_prod_txt = "";
- foreach( $buy_array as $key => $buy_num ) {
- $lionking_info = isset($lion_all_array[$key]) ? $lion_all_array[$key]:array("ticketcount" => 0);
-
- if( $lionking_info["ticketcount"] < $buy_num ) {
- // $return_array = array();
- //$return_array = $lionking_info["ticketcount"];
- // $return_array[] = $buy_array;
- // $return_array[] = $key;
- // return $return_array;
- return -1;
- }
- if( $buy_num > 0 ) {
- $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 $result_info;
- }
- return $trade_no;
-
- $result_info2 = eticket(API_USER, API_PASSWORD, $trade_no);
- if ($result_info2["code"] == 0) {
- return $trade_no;
- } else {
- return 0;
- }
- }
- function true_buy_lionking($trade_no){
- return $trade_no;
- $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; }
-
- return $ticket_array;
- }
-
- //获取线路运营班次返程日期数据(用户名,密码,操作参数,线路代码,去程班次id)
- function backdate( $user, $pass, $projcode ,$runid){
- $sign = API_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 = API_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 = API_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 = API_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 = API_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 = API_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 = API_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 = API_SIGN;
- $get_data = array("user" => $user,"sign" => $sign,"op" => "circuitry","ccode" => $ccode);
- return base_api( OPERATE_URL, $get_data);
- }
|