You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 

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