|
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359 |
- <?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);
- if( $return_result["code"] == 0 ) {
- $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();
- foreach( $ticket_array as $ticket_info ) {
- $index_name = mb_substr($ticket_info["ticketname"],4,3);
- $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);
- $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(
- "AA区" => 0,
- "AB区" => 1,
- "BA区" => 2,
- "BB区" => 3,
- "CA区" => 4,
- "CB区" => 5
- );
- $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 $return_array;
- }
-
- //传入参数 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["ticketcount"];
- }
- }
-
- $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);
- $ticket_array2[$index_name] = $ticket_info;
- }
- return $ticket_array2;
- }
-
- //获取线路运营班次返程日期数据(用户名,密码,操作参数,线路代码,去程班次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);
- }
|