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.
 
 
 
 

453 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. writeLog("zz-fx disney:".$url." | ".json_encode($get_data)." | ".$return_result);
  65. $return_result = xml_to_array($return_result);
  66. return $return_result;
  67. }
  68. //登录接口(用户名,密码)
  69. function login_api( $user, $pass ) {
  70. $get_data = array("user" => $user,"pass" => $pass);
  71. return base_api( LOGIN_URL, $get_data);
  72. }
  73. //票务系统线路列表查询(用户名,密码,操作参数)
  74. function run_list( $user, $pass){
  75. $sign = API_SIGN;
  76. $get_data = array("user" => $user,"sign" => $sign,"op" => "list");
  77. return base_api( OPERATE_URL, $get_data);
  78. }
  79. //获取线路运营日期数据(用户名,密码,操作参数,线路代码)
  80. function godate( $user, $pass, $projcode){
  81. $sign = API_SIGN;
  82. $get_data = array("user" => $user,"sign" => $sign,"op" => "godate","projcode" => $projcode);
  83. return base_api( OPERATE_URL, $get_data);
  84. }
  85. //获取线路运营班次数据(用户名,密码,操作参数,线路代码,运营日期)
  86. function gorun( $user, $pass, $projcode ,$godate){
  87. $sign = API_SIGN;
  88. $get_data = array("user" => $user,"sign" => $sign,"op" => "gorun","projcode" => $projcode,"godate" => $godate);
  89. return base_api( OPERATE_URL, $get_data);
  90. }
  91. //获取某个线路代码某一天的票种信息
  92. function get_ticket_array( $user, $pass, $projcode , $godate, $gotime = "" ) {
  93. $return_result = gorun($user, $pass, $projcode ,$godate);
  94. //var_dump($return_result);
  95. if( $return_result["code"] == 0 ) {
  96. if( !isset($return_result["go_run_list"]["run"]) ) {
  97. return false;
  98. }
  99. $run_array = $return_result["go_run_list"]["run"];
  100. if( isset($return_result["go_run_list"]["run"]["runid"]) ) {
  101. $run_id = $return_result["go_run_list"]["run"]["runid"];
  102. } else {
  103. foreach ($run_array as $run_info) {
  104. if ( $gotime == "" || $run_info["runtime"] == $gotime) {
  105. $run_id = $run_info["runid"];
  106. break;
  107. }
  108. }
  109. }
  110. } else {
  111. return false;
  112. }
  113. $return_result = ticket( $user, $pass, $projcode, $run_id);
  114. if( $return_result["code"] == 0 ) {
  115. $ticket_array = $return_result["ticket_list"]["ticket"];
  116. } else {
  117. $ticket_array = false;
  118. }
  119. return $ticket_array;
  120. }
  121. //获取迪士尼单日票信息
  122. function get_disney_info( $godate, $gotime = "" ) {
  123. $ticket_array = get_ticket_array( API_USER,API_PASSWORD, DISNEY_CODE1, $godate, $gotime );
  124. if( $ticket_array == false ) { return false; }
  125. $ticket_array2 = array();
  126. return $ticket_array;
  127. }
  128. //获取迪士尼两日票信息
  129. function get_disney_info2( $godate, $gotime = "" ) {
  130. $ticket_array = get_ticket_array( API_USER,API_PASSWORD, DISNEY_CODE2, $godate, $gotime );
  131. if( $ticket_array == false ) { return false; }
  132. $ticket_array2 = array();
  133. foreach ($ticket_array as $k=>$v) {
  134. $ticket_array2[$k+3]=$v;
  135. }
  136. return $ticket_array2;
  137. }
  138. //获取迪士尼一日两日票信息 顺序:单日成人 单日儿童 单日老人 双人成人 双日儿童 双日老人
  139. function get_disney_all_info( $godate ) {
  140. $_ary_disney_index = array(
  141. "0" => 0,
  142. "2" => 2,
  143. "1" => 1,
  144. "3" => 3,
  145. "5" => 5,
  146. "4" => 4
  147. );
  148. $return_array = array( 0,0,0,0,0,0 );
  149. $return_price = array( 0,0,0,0,0,0 );
  150. $disney_array = get_disney_info( $godate );
  151. $disney_array2 = get_disney_info2( $godate );
  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. }
  159. }
  160. if( $disney_array2 != false ) {
  161. foreach( $disney_array2 as $key => $disney_info ) {
  162. $return_index = $_ary_disney_index[$key];
  163. $return_array[$return_index] = isset($disney_info["ticketcount"])?$disney_info["ticketcount"]:'0';
  164. $return_price[$return_index] = isset($disney_info["ticketprice"])?$disney_info["ticketprice"]:'0';
  165. }
  166. }
  167. return array('tic_info'=>$return_array,'price'=>$return_price);
  168. }
  169. function get_lion_king_info( $godate, $gotime = "" ) {
  170. $_ary_lionking_index = array(
  171. "0" => 0,
  172. "1" => 1,
  173. "2" => 2,
  174. "3" => 3,
  175. "4" => 4,
  176. "5" => 5
  177. );
  178. $return_price = array( 0,0,0,0,0,0 );
  179. $return_array = array( 0,0,0,0,0,0 );
  180. $lion_array = get_disney_info3( $godate, $gotime);
  181. if( $lion_array != false ) {
  182. foreach( $lion_array as $key => $lion_info ) {
  183. if(substr_count($lion_info['ticketname'] ,'AA')){
  184. $return_array[0] = $lion_info["ticketcount"];
  185. $return_price[0] = $lion_info["ticketprice"];
  186. } elseif(substr_count($lion_info['ticketname'] ,'AB')) {
  187. $return_array[1] = $lion_info["ticketcount"];
  188. $return_price[1] = $lion_info["ticketprice"];
  189. } elseif(substr_count($lion_info['ticketname'] ,'BA')) {
  190. $return_array[2] = $lion_info["ticketcount"];
  191. $return_price[2] = $lion_info["ticketprice"];
  192. } elseif(substr_count($lion_info['ticketname'] ,'BB')) {
  193. $return_array[3] = $lion_info["ticketcount"];
  194. $return_price[3] = $lion_info["ticketprice"];
  195. } elseif(substr_count($lion_info['ticketname'] ,'CA')) {
  196. $return_array[4] = $lion_info["ticketcount"];
  197. $return_price[4] = $lion_info["ticketprice"];
  198. } elseif(substr_count($lion_info['ticketname'] ,'CB')) {
  199. $return_array[5] = $lion_info["ticketcount"];
  200. $return_price[5] = $lion_info["ticketprice"];
  201. }
  202. // $return_index = $_ary_lionking_index[$key];
  203. // $return_array[$return_index] = $lion_info["ticketcount"];
  204. // $return_price[$return_index] = $lion_info["ticketprice"];
  205. }
  206. }
  207. return array('tic_info'=>$return_array,'price'=>$return_price);
  208. }
  209. //传入参数 buy_array 购买票数的数组 array(0,0,0,0,0,0)
  210. //返回值 -1 库存不足 0 出票失败 其他 成功且返回自在订单号
  211. function buy_disney_ticket( $cus_name, $cus_mobile, $cus_idno, $buy_array, $godate, $tic_mem_info = false, &$return_info = false ) {
  212. $_ary_disney_index = array(
  213. "0" => 0,
  214. "2" => 2,
  215. "1" => 1,
  216. "3" => 3,
  217. "5" => 5,
  218. "4" => 4
  219. );
  220. if( $tic_mem_info == false ) {
  221. $return_info = array("message" => "请联系技术人员更新缓存");
  222. return -1;
  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 ($result_info["code"] == 0) {
  254. $trade_no = $result_info["tradeno"];
  255. } else {
  256. if( $return_info != false ) {
  257. $return_info = $result_info["info"];
  258. }
  259. return 0;
  260. }
  261. return $trade_no;
  262. $result_info2 = eticket(API_USER, API_PASSWORD, $trade_no);
  263. if ($result_info2["code"] == 0) {
  264. return $trade_no;
  265. } else {
  266. return 0;
  267. }
  268. }
  269. function true_buy_disney($trade_no){
  270. //return $trade_no;
  271. if( $trade_no <= 0 ) {
  272. return 0;
  273. }
  274. $result_info2 = eticket(API_USER, API_PASSWORD, $trade_no);
  275. if ( isset($result_info2["code"]) && $result_info2["code"] == 0) {
  276. return $trade_no;
  277. } else {
  278. return 0;
  279. }
  280. }
  281. //传入参数 buy_array 购买票数的数组 array(0,0,0,0,0,0)
  282. //返回值 -1 库存不足 0 出票失败 其他 成功且返回自在订单号
  283. function buy_lionking_ticket( $cus_name, $cus_mobile, $cus_idno, $buy_array, $godate, $gotime = "" , $tic_mem_info = false ) {
  284. $_ary_lionking_index = array(
  285. "0" => 0,
  286. "1" => 1,
  287. "2" => 2,
  288. "3" => 3,
  289. "4" => 4,
  290. "5" => 5
  291. );
  292. if( $tic_mem_info == false ) {
  293. return "0";
  294. $lion_array = get_disney_info3($godate, $gotime);
  295. $lion_all_array = array();
  296. if ($lion_array != false) {
  297. foreach ($lion_array as $key => $lion_info) {
  298. if (substr_count($lion_info['ticketname'], 'AA')) {
  299. $lion_all_array[0] = $lion_info;
  300. } elseif (substr_count($lion_info['ticketname'], 'AB')) {
  301. $lion_all_array[1] = $lion_info;
  302. } elseif (substr_count($lion_info['ticketname'], 'BA')) {
  303. $lion_all_array[2] = $lion_info;
  304. } elseif (substr_count($lion_info['ticketname'], 'BB')) {
  305. $lion_all_array[3] = $lion_info;
  306. } elseif (substr_count($lion_info['ticketname'], 'CA')) {
  307. $lion_all_array[4] = $lion_info;
  308. } elseif (substr_count($lion_info['ticketname'], 'CB')) {
  309. $lion_all_array[5] = $lion_info;
  310. }
  311. }
  312. }
  313. } else {
  314. $lion_all_array = $tic_mem_info;
  315. }
  316. // return $lion_all_array;
  317. $buy_prod_txt = "";
  318. foreach( $buy_array as $key => $buy_num ) {
  319. $lionking_info = isset($lion_all_array[$key]) ? $lion_all_array[$key]:array("ticketcount" => 0);
  320. if( $lionking_info["ticketcount"] < $buy_num ) {
  321. // $return_array = array();
  322. //$return_array = $lionking_info["ticketcount"];
  323. // $return_array[] = $buy_array;
  324. // $return_array[] = $key;
  325. // return $return_array;
  326. return -1;
  327. }
  328. if( $buy_num > 0 ) {
  329. $buy_prod_txt .= $lionking_info["ticketid"] . "P" . $buy_num . "|";
  330. }
  331. }
  332. $customer_txt = '{|' . $cus_name . '|' . $cus_mobile . '|' . $cus_idno . '||}';
  333. $result_info = lock(API_USER, API_PASSWORD, 15, $buy_prod_txt, $customer_txt, "", "", "");
  334. if ($result_info["code"] == 0) {
  335. $trade_no = $result_info["tradeno"];
  336. } else {
  337. return "-2";
  338. }
  339. return $trade_no;
  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. function true_buy_lionking($trade_no){
  348. //return $trade_no;
  349. if( $trade_no == -1 || $trade_no == 0 || $trade_no == "" ) {
  350. return false;
  351. }
  352. $result_info2 = eticket(API_USER, API_PASSWORD, $trade_no);
  353. if ($result_info2["code"] == 0) {
  354. return $trade_no;
  355. } else {
  356. return 0;
  357. }
  358. }
  359. //获取迪士尼演出信息
  360. function get_disney_info3( $godate, $gotime = "" ) {
  361. $ticket_array = get_ticket_array( API_USER,API_PASSWORD, DISNEY_CODE3, $godate, $gotime );
  362. if( $ticket_array == false ) { return false; }
  363. return $ticket_array;
  364. }
  365. //获取线路运营班次返程日期数据(用户名,密码,操作参数,线路代码,去程班次id)
  366. function backdate( $user, $pass, $projcode ,$runid){
  367. $sign = API_SIGN;
  368. $get_data = array("user" => $user,"sign" => $sign,"op" => "backdate","projcode" => $projcode,"runid" => $runid);
  369. return base_api( OPERATE_URL, $get_data);
  370. }
  371. //获取线路特定班次返程班次数据(用户名,密码,操作参数,线路代码,去程班次id,回程日期)
  372. function backrun( $user, $pass, $projcode ,$runid ,$backdate){
  373. $sign = API_SIGN;
  374. $get_data = array("user" => $user,"sign" => $sign,"op" => "backrun","projcode" => $projcode,"runid" => $runid,"backdate" => $backdate);
  375. return base_api( OPERATE_URL, $get_data);
  376. }
  377. //获取班次票种数据(用户名,密码,操作参数,线路代码,去程班次id)
  378. function ticket( $user, $pass, $projcode ,$runid){
  379. $sign = API_SIGN;
  380. $get_data = array("user" => $user,"sign" => $sign,"op" => "ticket","projcode" => $projcode,"runid" => $runid);
  381. return base_api( OPERATE_URL, $get_data);
  382. }
  383. //票务系统锁位(用户名,密码,操作参数,锁位时间,票种id及张数中间用‘P’隔开,订单客人信息,会员ID,优惠码,会员积分)
  384. function lock( $user, $pass, $lock = 15 ,$ticket ,$customer = "",$memid = "",$barcode = "",$score= ""){
  385. $sign = API_SIGN;
  386. $get_data = array("user" => $user,"sign" => $sign,"op" => "lock","lock" => $lock,"ticket" => $ticket,"customer" => $customer,"memid" => $memid,"barcode" => $barcode,"score" => $score);
  387. return base_api( OPERATE_URL, $get_data);
  388. }
  389. //票务系统订单确认(用户名,密码,操作参数,票务系统订单号)
  390. function eticket( $user, $pass, $tradeno){
  391. $sign = API_SIGN;
  392. $get_data = array("user" => $user,"sign" => $sign,"op" => "eticket","tradeno" => $tradeno);
  393. return base_api( OPERATE_URL, $get_data);
  394. }
  395. //票务系统更新补充客户数据(用户名,密码,操作参数,票务系统订单号,客户信息)
  396. function customer( $user, $pass, $tradeno ,$customerlist){
  397. $sign = API_SIGN;
  398. $get_data = array("user" => $user,"sign" => $sign,"op" => "customer","tradeno" => $tradeno,"customerlist" => $customerlist);
  399. return base_api( OPERATE_URL, $get_data);
  400. }
  401. //票务系统订单状态查询(用户名,密码,操作参数,票务系统订单号)
  402. function status( $user, $pass, $tn){
  403. $sign = API_SIGN;
  404. $get_data = array("user" => $user,"sign" => $sign,"op" => "status","tn" => $tn);
  405. return base_api( OPERATE_URL, $get_data);
  406. }
  407. //获取线路产品介绍信息(用户名,密码,操作参数,产品代码)
  408. function circuitry( $user, $pass, $op, $ccode){
  409. $sign = API_SIGN;
  410. $get_data = array("user" => $user,"sign" => $sign,"op" => "circuitry","ccode" => $ccode);
  411. return base_api( OPERATE_URL, $get_data);
  412. }