Non puoi selezionare più di 25 argomenti Gli argomenti devono iniziare con una lettera o un numero, possono includere trattini ('-') e possono essere lunghi fino a 35 caratteri.
 
 
 
 

451 righe
17 KiB

  1. <?php
  2. define( "API_USER", "zzcx01");
  3. define( "API_PASSWORD", "12345678");
  4. define( "API_SIGN", "03EF41375E5149EFB5CCD6AE236555C7");
  5. define( "DISNEY_CODE1", "SHDSN" );//单日票
  6. //define( "DISNEY_CODE1", "DSNTB01" );//单日票
  7. define( "DISNEY_CODE2", "SHDSN2" );//两日票
  8. define( "DISNEY_CODE3", "DSNSZW" );//演出票
  9. //define( "API_USER", "zzcx02");
  10. //define( "API_PASSWORD", "12345678");
  11. //define( "API_SIGN", "4E84E1EEBAF00B352DEF2B8F3336B63C");
  12. //define( "DISNEY_CODE1", "shz101" );//单日票
  13. //define( "DISNEY_CODE2", "shz101" );//两日票
  14. //define( "DISNEY_CODE3", "shz101" );//演出票
  15. define( "LOGIN_URL", "http://partner.zizaitrip.net/login" );
  16. define( "OPERATE_URL", "http://partner.zizaitrip.net/interface" );
  17. $_ary_goods_zizai_index = array(
  18. "成人票" => 0,
  19. "老人票" => 2,
  20. "儿童票" => 1,
  21. "成人票" => 3,
  22. "老人票" => 5,
  23. "儿童票" => 4,
  24. "AA区" => 0,
  25. "AB区" => 1,
  26. "BA区" => 2,
  27. "BB区" => 3,
  28. "CA区" => 4,
  29. "CB区" => 5
  30. );
  31. //向自在发送post参数(链接,参数数组)
  32. function send_post($url, $post_data) {
  33. $postdata = http_build_query($post_data);
  34. $options = array(
  35. 'http' => array(
  36. 'method' => 'POST',
  37. 'header' => 'Content-type:application/x-www-form-urlencoded',
  38. 'content' => $postdata,
  39. 'timeout' => 15 * 60 // 超时时间(单位:s)
  40. )
  41. );
  42. $context = stream_context_create($options);
  43. $result = file_get_contents($url, false, $context);
  44. return $result;
  45. }
  46. //向自在发送get参数(链接,参数数组)
  47. function send_get($url, $get_data) {
  48. $url_param = http_build_query($get_data);
  49. $result = file_get_contents($url."?{$url_param}");
  50. return $result;
  51. }
  52. //将xml转换为数组
  53. function xml_to_array($xml)
  54. {
  55. $ob = simplexml_load_string($xml);
  56. $json = json_encode($ob);
  57. $array = json_decode($json, true);
  58. return $array;
  59. }
  60. //获取数据(链接,参数数组)
  61. function base_api( $url, $get_data ) {
  62. $get_data["tt"] = rand(100000,999999);
  63. $return_result = send_get($url, $get_data);
  64. $return_result = xml_to_array($return_result);
  65. return $return_result;
  66. }
  67. //登录接口(用户名,密码)
  68. function login_api( $user, $pass ) {
  69. $get_data = array("user" => $user,"pass" => $pass);
  70. return base_api( LOGIN_URL, $get_data);
  71. }
  72. //票务系统线路列表查询(用户名,密码,操作参数)
  73. function run_list( $user, $pass){
  74. $sign = API_SIGN;
  75. $get_data = array("user" => $user,"sign" => $sign,"op" => "list");
  76. return base_api( OPERATE_URL, $get_data);
  77. }
  78. //获取线路运营日期数据(用户名,密码,操作参数,线路代码)
  79. function godate( $user, $pass, $projcode){
  80. $sign = API_SIGN;
  81. $get_data = array("user" => $user,"sign" => $sign,"op" => "godate","projcode" => $projcode);
  82. return base_api( OPERATE_URL, $get_data);
  83. }
  84. //获取线路运营班次数据(用户名,密码,操作参数,线路代码,运营日期)
  85. function gorun( $user, $pass, $projcode ,$godate){
  86. $sign = API_SIGN;
  87. $get_data = array("user" => $user,"sign" => $sign,"op" => "gorun","projcode" => $projcode,"godate" => $godate);
  88. return base_api( OPERATE_URL, $get_data);
  89. }
  90. //获取某个线路代码某一天的票种信息
  91. function get_ticket_array( $user, $pass, $projcode , $godate, $gotime = "" ) {
  92. $return_result = gorun($user, $pass, $projcode ,$godate);
  93. //var_dump($return_result);
  94. if( $return_result["code"] == 0 ) {
  95. if( !isset($return_result["go_run_list"]["run"]) ) {
  96. return false;
  97. }
  98. $run_array = $return_result["go_run_list"]["run"];
  99. if( isset($return_result["go_run_list"]["run"]["runid"]) ) {
  100. $run_id = $return_result["go_run_list"]["run"]["runid"];
  101. } else {
  102. foreach ($run_array as $run_info) {
  103. if ( $gotime == "" || $run_info["runtime"] == $gotime) {
  104. $run_id = $run_info["runid"];
  105. break;
  106. }
  107. }
  108. }
  109. } else {
  110. return false;
  111. }
  112. $return_result = ticket( $user, $pass, $projcode, $run_id);
  113. if( $return_result["code"] == 0 ) {
  114. $ticket_array = isset($return_result["ticket_list"]["ticket"]) ? $return_result["ticket_list"]["ticket"] : $return_result["ticket_list"];
  115. } else {
  116. $ticket_array = false;
  117. }
  118. return $ticket_array;
  119. }
  120. //获取迪士尼单日票信息
  121. function get_disney_info( $godate, $gotime = "" ) {
  122. $ticket_array = get_ticket_array( API_USER,API_PASSWORD, DISNEY_CODE1, $godate, $gotime );
  123. if( $ticket_array == false ) { return false; }
  124. $ticket_array2 = array();
  125. return $ticket_array;
  126. }
  127. //获取迪士尼两日票信息
  128. function get_disney_info2( $godate, $gotime = "" ) {
  129. $ticket_array = get_ticket_array( API_USER,API_PASSWORD, DISNEY_CODE2, $godate, $gotime );
  130. if( $ticket_array == false ) { return false; }
  131. $ticket_array2 = array();
  132. foreach ($ticket_array as $k=>$v) {
  133. $ticket_array2[$k+3]=$v;
  134. }
  135. return $ticket_array2;
  136. }
  137. //获取迪士尼一日两日票信息 顺序:单日成人 单日儿童 单日老人 双人成人 双日儿童 双日老人
  138. function get_disney_all_info( $godate ) {
  139. $_ary_disney_index = array(
  140. "0" => 0,
  141. "2" => 2,
  142. "1" => 1,
  143. "3" => 3,
  144. "5" => 5,
  145. "4" => 4
  146. );
  147. $return_array = array( 0,0,0,0,0,0 );
  148. $return_price = array( 0,0,0,0,0,0 );
  149. $disney_array = get_disney_info( $godate );
  150. $disney_array2 = get_disney_info2( $godate );
  151. $disney_all_array = array();
  152. //return $disney_array2;
  153. if( $disney_array != false ) {
  154. foreach( $disney_array as $key => $disney_info ) {
  155. $return_index = $_ary_disney_index[$key];
  156. $return_array[$return_index] = isset($disney_info["ticketcount"])?$disney_info["ticketcount"]:'0';
  157. $return_price[$return_index] = isset($disney_info["ticketprice"])?$disney_info["ticketprice"]:'0';
  158. $disney_all_array[$return_index] = $disney_info;
  159. }
  160. }
  161. if( $disney_array2 != false ) {
  162. foreach( $disney_array2 as $key => $disney_info ) {
  163. $return_index = $_ary_disney_index[$key];
  164. $return_array[$return_index] = isset($disney_info["ticketcount"])?$disney_info["ticketcount"]:'0';
  165. $return_price[$return_index] = isset($disney_info["ticketprice"])?$disney_info["ticketprice"]:'0';
  166. $disney_all_array[$return_index] = $disney_info;
  167. }
  168. }
  169. return array('tic_info'=>$return_array,'price'=>$return_price,'ticket_array' => $disney_all_array );
  170. }
  171. function get_lion_king_info( $godate, $gotime = "" ) {
  172. $_ary_lionking_index = array(
  173. "0" => 0,
  174. "1" => 1,
  175. "2" => 2,
  176. "3" => 3,
  177. "4" => 4,
  178. "5" => 5
  179. );
  180. $return_price = array( 0,0,0,0,0,0 );
  181. $return_array = array( 0,0,0,0,0,0 );
  182. $lion_array = get_disney_info3( $godate, $gotime);
  183. if( $lion_array != false ) {
  184. foreach( $lion_array as $key => $lion_info ) {
  185. if(substr_count($lion_info['ticketname'] ,'AA')){
  186. $return_array[0] = $lion_info["ticketcount"];
  187. $return_price[0] = $lion_info["ticketprice"];
  188. } elseif(substr_count($lion_info['ticketname'] ,'AB')) {
  189. $return_array[1] = $lion_info["ticketcount"];
  190. $return_price[1] = $lion_info["ticketprice"];
  191. } elseif(substr_count($lion_info['ticketname'] ,'BA')) {
  192. $return_array[2] = $lion_info["ticketcount"];
  193. $return_price[2] = $lion_info["ticketprice"];
  194. } elseif(substr_count($lion_info['ticketname'] ,'BB')) {
  195. $return_array[3] = $lion_info["ticketcount"];
  196. $return_price[3] = $lion_info["ticketprice"];
  197. } elseif(substr_count($lion_info['ticketname'] ,'CA')) {
  198. $return_array[4] = $lion_info["ticketcount"];
  199. $return_price[4] = $lion_info["ticketprice"];
  200. } elseif(substr_count($lion_info['ticketname'] ,'CB')) {
  201. $return_array[5] = $lion_info["ticketcount"];
  202. $return_price[5] = $lion_info["ticketprice"];
  203. }
  204. // $return_index = $_ary_lionking_index[$key];
  205. // $return_array[$return_index] = $lion_info["ticketcount"];
  206. // $return_price[$return_index] = $lion_info["ticketprice"];
  207. }
  208. }
  209. return array('tic_info'=>$return_array,'price'=>$return_price);
  210. }
  211. //传入参数 buy_array 购买票数的数组 array(0,0,0,0,0,0)
  212. //返回值 -1 库存不足 0 出票失败 其他 成功且返回自在订单号
  213. function buy_disney_ticket( $cus_name, $cus_mobile, $cus_idno, $buy_array, $godate, $tic_mem_info = false ) {
  214. $_ary_disney_index = array(
  215. "0" => 0,
  216. "2" => 2,
  217. "1" => 1,
  218. "3" => 3,
  219. "5" => 5,
  220. "4" => 4
  221. );
  222. if( false == $tic_mem_info ) {
  223. $disney_array = get_disney_info($godate);
  224. $disney_array2 = get_disney_info2($godate);
  225. $disney_all_array = array();
  226. if (false != $disney_array) {
  227. foreach ($disney_array as $key => $disney_info) {
  228. $return_index = $_ary_disney_index[$key];
  229. $disney_all_array[$return_index] = $disney_info;
  230. }
  231. }
  232. if (false != $disney_array2) {
  233. foreach ($disney_array2 as $key => $disney_info) {
  234. $return_index = $_ary_disney_index[$key];
  235. $disney_all_array[$return_index] = $disney_info;
  236. }
  237. }
  238. } else {
  239. $disney_all_array = $tic_mem_info;
  240. }
  241. $buy_prod_txt = "";
  242. foreach( $buy_array as $key => $buy_num ) {
  243. $disney_info = isset($disney_all_array[$key]) ? $disney_all_array[$key] : array("ticketcount" => 0);
  244. if( $disney_info["ticketcount"] < $buy_num ) {
  245. return -1;
  246. }
  247. if( $buy_num > 0 ) {
  248. $buy_prod_txt .= $disney_info["ticketid"] . "P" . $buy_num . "|";
  249. }
  250. }
  251. $customer_txt = '{|' . $cus_name . '|' . $cus_mobile . '|' . $cus_idno . '||}';
  252. $result_info = lock(API_USER, API_PASSWORD, 15, $buy_prod_txt, $customer_txt, "", "", "");
  253. if ( isset($result_info["code"]) && $result_info["code"] == 0) {
  254. $trade_no = $result_info["tradeno"];
  255. } else {
  256. return false;
  257. }
  258. return $trade_no;
  259. /*
  260. $result_info2 = eticket(API_USER, API_PASSWORD, $trade_no);
  261. if ($result_info2["code"] == 0) {
  262. return $trade_no;
  263. } else {
  264. return 0;
  265. }
  266. */
  267. }
  268. function true_buy_disney($trade_no){
  269. //return $trade_no;
  270. if( $trade_no == -1 || $trade_no == 0 || $trade_no == "" ) {
  271. return false;
  272. }
  273. $result_info2 = eticket(API_USER, API_PASSWORD, $trade_no);
  274. if ( isset($result_info2["code"]) && $result_info2["code"] == 0) {
  275. return $trade_no;
  276. } else {
  277. return false;
  278. }
  279. }
  280. //传入参数 buy_array 购买票数的数组 array(0,0,0,0,0,0)
  281. //返回值 -1 库存不足 0 出票失败 其他 成功且返回自在订单号
  282. function buy_lionking_ticket( $cus_name, $cus_mobile, $cus_idno, $buy_array, $godate, $gotime = "", $tic_mem_info = false ) {
  283. $_ary_lionking_index = array(
  284. "0" => 0,
  285. "1" => 1,
  286. "2" => 2,
  287. "3" => 3,
  288. "4" => 4,
  289. "5" => 5
  290. );
  291. if( $tic_mem_info == false ) {
  292. return false;
  293. $lion_array = get_disney_info3($godate, $gotime);
  294. $lion_all_array = array();
  295. if ($lion_array != false) {
  296. foreach ($lion_array as $key => $lion_info) {
  297. if (substr_count($lion_info['ticketname'], 'AA')) {
  298. $lion_all_array[0] = $lion_info;
  299. } elseif (substr_count($lion_info['ticketname'], 'AB')) {
  300. $lion_all_array[1] = $lion_info;
  301. } elseif (substr_count($lion_info['ticketname'], 'BA')) {
  302. $lion_all_array[2] = $lion_info;
  303. } elseif (substr_count($lion_info['ticketname'], 'BB')) {
  304. $lion_all_array[3] = $lion_info;
  305. } elseif (substr_count($lion_info['ticketname'], 'CA')) {
  306. $lion_all_array[4] = $lion_info;
  307. } elseif (substr_count($lion_info['ticketname'], 'CB')) {
  308. $lion_all_array[5] = $lion_info;
  309. }
  310. }
  311. }
  312. } else {
  313. $lion_all_array = $tic_mem_info;
  314. }
  315. // return $lion_all_array;
  316. $buy_prod_txt = "";
  317. foreach( $buy_array as $key => $buy_num ) {
  318. $lionking_info = isset($lion_all_array[$key]) ? $lion_all_array[$key]:array("ticketcount" => 0);
  319. if( $lionking_info["ticketcount"] < $buy_num ) {
  320. // $return_array = array();
  321. //$return_array = $lionking_info["ticketcount"];
  322. // $return_array[] = $buy_array;
  323. // $return_array[] = $key;
  324. // return $return_array;
  325. return -1;
  326. }
  327. if( $buy_num > 0 ) {
  328. $buy_prod_txt .= $lionking_info["ticketid"] . "P" . $buy_num . "|";
  329. }
  330. }
  331. $customer_txt = '{|' . $cus_name . '|' . $cus_mobile . '|' . $cus_idno . '||}';
  332. $result_info = lock(API_USER, API_PASSWORD, 15, $buy_prod_txt, $customer_txt, "", "", "");
  333. if ($result_info["code"] == 0) {
  334. $trade_no = $result_info["tradeno"];
  335. } else {
  336. return $result_info;
  337. }
  338. return $trade_no;
  339. /*
  340. $result_info2 = eticket(API_USER, API_PASSWORD, $trade_no);
  341. if ($result_info2["code"] == 0) {
  342. return $trade_no;
  343. } else {
  344. return 0;
  345. }
  346. */
  347. }
  348. function true_buy_lionking($trade_no){
  349. //return $trade_no;
  350. if( $trade_no == -1 || $trade_no == 0 || $trade_no == "" ) {
  351. return false;
  352. }
  353. $result_info2 = eticket(API_USER, API_PASSWORD, $trade_no);
  354. if ($result_info2["code"] == 0) {
  355. return $trade_no;
  356. } else {
  357. return 0;
  358. }
  359. }
  360. //获取迪士尼演出信息
  361. function get_disney_info3( $godate, $gotime = "" ) {
  362. $ticket_array = get_ticket_array( API_USER,API_PASSWORD, DISNEY_CODE3, $godate, $gotime );
  363. if( $ticket_array == false ) { return false; }
  364. return $ticket_array;
  365. }
  366. //获取线路运营班次返程日期数据(用户名,密码,操作参数,线路代码,去程班次id)
  367. function backdate( $user, $pass, $projcode ,$runid){
  368. $sign = API_SIGN;
  369. $get_data = array("user" => $user,"sign" => $sign,"op" => "backdate","projcode" => $projcode,"runid" => $runid);
  370. return base_api( OPERATE_URL, $get_data);
  371. }
  372. //获取线路特定班次返程班次数据(用户名,密码,操作参数,线路代码,去程班次id,回程日期)
  373. function backrun( $user, $pass, $projcode ,$runid ,$backdate){
  374. $sign = API_SIGN;
  375. $get_data = array("user" => $user,"sign" => $sign,"op" => "backrun","projcode" => $projcode,"runid" => $runid,"backdate" => $backdate);
  376. return base_api( OPERATE_URL, $get_data);
  377. }
  378. //获取班次票种数据(用户名,密码,操作参数,线路代码,去程班次id)
  379. function ticket( $user, $pass, $projcode ,$runid){
  380. $sign = API_SIGN;
  381. $get_data = array("user" => $user,"sign" => $sign,"op" => "ticket","projcode" => $projcode,"runid" => $runid);
  382. return base_api( OPERATE_URL, $get_data);
  383. }
  384. //票务系统锁位(用户名,密码,操作参数,锁位时间,票种id及张数中间用‘P’隔开,订单客人信息,会员ID,优惠码,会员积分)
  385. function lock( $user, $pass, $lock = 15 ,$ticket ,$customer = "",$memid = "",$barcode = "",$score= ""){
  386. $sign = API_SIGN;
  387. $get_data = array("user" => $user,"sign" => $sign,"op" => "lock","lock" => $lock,"ticket" => $ticket,"customer" => $customer,"memid" => $memid,"barcode" => $barcode,"score" => $score);
  388. return base_api( OPERATE_URL, $get_data);
  389. }
  390. //票务系统订单确认(用户名,密码,操作参数,票务系统订单号)
  391. function eticket( $user, $pass, $tradeno){
  392. $sign = API_SIGN;
  393. $get_data = array("user" => $user,"sign" => $sign,"op" => "eticket","tradeno" => $tradeno);
  394. return base_api( OPERATE_URL, $get_data);
  395. }
  396. //票务系统更新补充客户数据(用户名,密码,操作参数,票务系统订单号,客户信息)
  397. function customer( $user, $pass, $tradeno ,$customerlist){
  398. $sign = API_SIGN;
  399. $get_data = array("user" => $user,"sign" => $sign,"op" => "customer","tradeno" => $tradeno,"customerlist" => $customerlist);
  400. return base_api( OPERATE_URL, $get_data);
  401. }
  402. //票务系统订单状态查询(用户名,密码,操作参数,票务系统订单号)
  403. function status( $user, $pass, $tn){
  404. $sign = API_SIGN;
  405. $get_data = array("user" => $user,"sign" => $sign,"op" => "status","tn" => $tn);
  406. return base_api( OPERATE_URL, $get_data);
  407. }
  408. //获取线路产品介绍信息(用户名,密码,操作参数,产品代码)
  409. function circuitry( $user, $pass, $op, $ccode){
  410. $sign = API_SIGN;
  411. $get_data = array("user" => $user,"sign" => $sign,"op" => "circuitry","ccode" => $ccode);
  412. return base_api( OPERATE_URL, $get_data);
  413. }