Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.

pirms 3 gadiem
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398
  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_USER", "zzcx02");
  9. //define( "API_PASSWORD", "12345678");
  10. //define( "API_SIGN", "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){
  73. $sign = API_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){
  79. $sign = API_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){
  85. $sign = API_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 = "" ) {
  91. $return_result = gorun($user, $pass, $projcode ,$godate);
  92. //var_dump($return_result);
  93. if( $return_result["code"] == 0 ) {
  94. if( !isset($return_result["go_run_list"]["run"]) ) {
  95. return false;
  96. }
  97. $run_array = $return_result["go_run_list"]["run"];
  98. if( isset($return_result["go_run_list"]["run"]["runid"]) ) {
  99. $run_id = $return_result["go_run_list"]["run"]["runid"];
  100. } else {
  101. foreach ($run_array as $run_info) {
  102. if ( $gotime == "" || $run_info["runtime"] == $gotime) {
  103. $run_id = $run_info["runid"];
  104. break;
  105. }
  106. }
  107. }
  108. } else {
  109. return false;
  110. }
  111. $return_result = ticket( $user, $pass, $projcode, $run_id);
  112. if( $return_result["code"] == 0 ) {
  113. $ticket_array = $return_result["ticket_list"]["ticket"];
  114. } else {
  115. $ticket_array = false;
  116. }
  117. return $ticket_array;
  118. }
  119. //获取迪士尼单日票信息
  120. function get_disney_info( $godate, $gotime = "" ) {
  121. $ticket_array = get_ticket_array( API_USER,API_PASSWORD, DISNEY_CODE1, $godate, $gotime );
  122. if( $ticket_array == false ) { return false; }
  123. $ticket_array2 = array();
  124. return $ticket_array;
  125. }
  126. //获取迪士尼两日票信息
  127. function get_disney_info2( $godate, $gotime = "" ) {
  128. $ticket_array = get_ticket_array( API_USER,API_PASSWORD, DISNEY_CODE2, $godate, $gotime );
  129. if( $ticket_array == false ) { return false; }
  130. $ticket_array2 = array();
  131. foreach ($ticket_array as $k=>$v) {
  132. $ticket_array2[$k+3]=$v;
  133. }
  134. return $ticket_array2;
  135. }
  136. //获取迪士尼一日两日票信息 顺序:单日成人 单日儿童 单日老人 双人成人 双日儿童 双日老人
  137. function get_disney_all_info( $godate ) {
  138. $_ary_disney_index = array(
  139. "0" => 0,
  140. "2" => 2,
  141. "1" => 1,
  142. "3" => 3,
  143. "5" => 5,
  144. "4" => 4
  145. );
  146. $return_array = array( 0,0,0,0,0,0 );
  147. $return_price = array( 499,375,375,950,710,710 );
  148. $disney_array = get_disney_info( $godate );
  149. $disney_array2 = get_disney_info2( $godate );
  150. //return $disney_array2;
  151. if( $disney_array != false ) {
  152. foreach( $disney_array as $key => $disney_info ) {
  153. $return_index = $_ary_disney_index[$key];
  154. $return_array[$return_index] = isset($disney_info["ticketcount"])?$disney_info["ticketcount"]:'0';
  155. $return_price[$return_index] = isset($disney_info["ticketprice"])?$disney_info["ticketprice"]:'0';
  156. }
  157. }
  158. if( $disney_array2 != false ) {
  159. foreach( $disney_array2 as $key => $disney_info ) {
  160. $return_index = $_ary_disney_index[$key];
  161. $return_array[$return_index] = isset($disney_info["ticketcount"])?$disney_info["ticketcount"]:'0';
  162. $return_price[$return_index] = isset($disney_info["ticketprice"])?$disney_info["ticketprice"]:'0';
  163. }
  164. }
  165. return array('tic_info'=>$return_array,'price'=>$return_price);
  166. }
  167. function get_lion_king_info( $godate, $gotime = "" ) {
  168. $_ary_lionking_index = array(
  169. "0" => 0,
  170. "1" => 1,
  171. "2" => 2,
  172. "3" => 3,
  173. "4" => 4,
  174. "5" => 5
  175. );
  176. $return_price = array( 1000,800,590,490,390,290 );
  177. $return_array = array( 0,0,0,0,0,0 );
  178. $lion_array = get_disney_info3( $godate, $gotime);
  179. if( $lion_array != false ) {
  180. foreach( $lion_array as $key => $lion_info ) {
  181. $return_index = $_ary_lionking_index[$key];
  182. $return_array[$return_index] = $lion_info["ticketcount"];
  183. $return_price[$return_index] = $lion_info["ticketprice"];
  184. }
  185. }
  186. return array('tic_info'=>$return_array,'price'=>$return_price);
  187. }
  188. //传入参数 buy_array 购买票数的数组 array(0,0,0,0,0,0)
  189. //返回值 -1 库存不足 0 出票失败 其他 成功且返回自在订单号
  190. function buy_disney_ticket( $cus_name, $cus_mobile, $cus_idno, $buy_array, $godate ) {
  191. $_ary_disney_index = array(
  192. "0" => 0,
  193. "2" => 2,
  194. "1" => 1,
  195. "3" => 3,
  196. "5" => 5,
  197. "4" => 4
  198. );
  199. $disney_array = get_disney_info( $godate );
  200. $disney_array2 = get_disney_info2( $godate );
  201. $disney_all_array = array();
  202. if( false != $disney_array ) {
  203. foreach( $disney_array as $key => $disney_info ) {
  204. $return_index = $_ary_disney_index[$key];
  205. $disney_all_array[$return_index] = $disney_info;
  206. }
  207. }
  208. if( false != $disney_array2 ) {
  209. foreach( $disney_array2 as $key => $disney_info ) {
  210. $return_index = $_ary_disney_index[$key];
  211. $disney_all_array[$return_index] = $disney_info;
  212. }
  213. }
  214. $buy_prod_txt = "";
  215. foreach( $buy_array as $key => $buy_num ) {
  216. $disney_info = isset($disney_all_array[$key]) ? $disney_all_array[$key] : array("ticketcount" => 0);
  217. if( $disney_info["ticketcount"] < $buy_num ) {
  218. return -1;
  219. }
  220. if( $buy_num > 0 ) {
  221. $buy_prod_txt .= $disney_info["ticketid"] . "P" . $buy_num . "|";
  222. }
  223. }
  224. $customer_txt = '{|' . $cus_name . '|' . $cus_mobile . '|' . $cus_idno . '||}';
  225. $result_info = lock(API_USER, API_PASSWORD, 15, $buy_prod_txt, $customer_txt, "", "", "");
  226. if ($result_info["code"] == 0) {
  227. $trade_no = $result_info["tradeno"];
  228. } else {
  229. return 0;
  230. }
  231. return $trade_no;
  232. $result_info2 = eticket(API_USER, API_PASSWORD, $trade_no);
  233. if ($result_info2["code"] == 0) {
  234. return $trade_no;
  235. } else {
  236. return 0;
  237. }
  238. }
  239. function true_buy_disney($trade_no){
  240. return $trade_no;
  241. $result_info2 = eticket(API_USER, API_PASSWORD, $trade_no);
  242. if ($result_info2["code"] == 0) {
  243. return $trade_no;
  244. } else {
  245. return 0;
  246. }
  247. }
  248. //传入参数 buy_array 购买票数的数组 array(0,0,0,0,0,0)
  249. //返回值 -1 库存不足 0 出票失败 其他 成功且返回自在订单号
  250. function buy_lionking_ticket( $cus_name, $cus_mobile, $cus_idno, $buy_array, $godate, $gotime = "" ) {
  251. $_ary_lionking_index = array(
  252. "0" => 0,
  253. "1" => 1,
  254. "2" => 2,
  255. "3" => 3,
  256. "4" => 4,
  257. "5" => 5
  258. );
  259. $lion_array = get_disney_info3( $godate, $gotime);
  260. $lion_all_array = array();
  261. if( $lion_array != false ) {
  262. foreach( $lion_array as $key => $lion_info ) {
  263. $return_index = $_ary_lionking_index[$key];
  264. $lion_all_array[$return_index] = $lion_info;
  265. }
  266. }
  267. // return $lion_all_array;
  268. $buy_prod_txt = "";
  269. foreach( $buy_array as $key => $buy_num ) {
  270. $lionking_info = isset($lion_all_array[$key]) ? $lion_all_array[$key]:array("ticketcount" => 0);
  271. if( $lionking_info["ticketcount"] < $buy_num ) {
  272. // $return_array = array();
  273. //$return_array = $lionking_info["ticketcount"];
  274. // $return_array[] = $buy_array;
  275. // $return_array[] = $key;
  276. // return $return_array;
  277. return -1;
  278. }
  279. if( $buy_num > 0 ) {
  280. $buy_prod_txt .= $lionking_info["ticketid"] . "P" . $buy_num . "|";
  281. }
  282. }
  283. $customer_txt = '{|' . $cus_name . '|' . $cus_mobile . '|' . $cus_idno . '||}';
  284. $result_info = lock(API_USER, API_PASSWORD, 15, $buy_prod_txt, $customer_txt, "", "", "");
  285. if ($result_info["code"] == 0) {
  286. $trade_no = $result_info["tradeno"];
  287. } else {
  288. return $result_info;
  289. }
  290. return $trade_no;
  291. $result_info2 = eticket(API_USER, API_PASSWORD, $trade_no);
  292. if ($result_info2["code"] == 0) {
  293. return $trade_no;
  294. } else {
  295. return 0;
  296. }
  297. }
  298. function true_buy_lionking($trade_no){
  299. return $trade_no;
  300. $result_info2 = eticket(API_USER, API_PASSWORD, $trade_no);
  301. if ($result_info2["code"] == 0) {
  302. return $trade_no;
  303. } else {
  304. return 0;
  305. }
  306. }
  307. //获取迪士尼演出信息
  308. function get_disney_info3( $godate, $gotime = "" ) {
  309. $ticket_array = get_ticket_array( API_USER,API_PASSWORD, DISNEY_CODE3, $godate, $gotime );
  310. if( $ticket_array == false ) { return false; }
  311. return $ticket_array;
  312. }
  313. //获取线路运营班次返程日期数据(用户名,密码,操作参数,线路代码,去程班次id)
  314. function backdate( $user, $pass, $projcode ,$runid){
  315. $sign = API_SIGN;
  316. $get_data = array("user" => $user,"sign" => $sign,"op" => "backdate","projcode" => $projcode,"runid" => $runid);
  317. return base_api( OPERATE_URL, $get_data);
  318. }
  319. //获取线路特定班次返程班次数据(用户名,密码,操作参数,线路代码,去程班次id,回程日期)
  320. function backrun( $user, $pass, $projcode ,$runid ,$backdate){
  321. $sign = API_SIGN;
  322. $get_data = array("user" => $user,"sign" => $sign,"op" => "backrun","projcode" => $projcode,"runid" => $runid,"backdate" => $backdate);
  323. return base_api( OPERATE_URL, $get_data);
  324. }
  325. //获取班次票种数据(用户名,密码,操作参数,线路代码,去程班次id)
  326. function ticket( $user, $pass, $projcode ,$runid){
  327. $sign = API_SIGN;
  328. $get_data = array("user" => $user,"sign" => $sign,"op" => "ticket","projcode" => $projcode,"runid" => $runid);
  329. return base_api( OPERATE_URL, $get_data);
  330. }
  331. //票务系统锁位(用户名,密码,操作参数,锁位时间,票种id及张数中间用‘P’隔开,订单客人信息,会员ID,优惠码,会员积分)
  332. function lock( $user, $pass, $lock = 15 ,$ticket ,$customer = "",$memid = "",$barcode = "",$score= ""){
  333. $sign = API_SIGN;
  334. $get_data = array("user" => $user,"sign" => $sign,"op" => "lock","lock" => $lock,"ticket" => $ticket,"customer" => $customer,"memid" => $memid,"barcode" => $barcode,"score" => $score);
  335. return base_api( OPERATE_URL, $get_data);
  336. }
  337. //票务系统订单确认(用户名,密码,操作参数,票务系统订单号)
  338. function eticket( $user, $pass, $tradeno){
  339. $sign = API_SIGN;
  340. $get_data = array("user" => $user,"sign" => $sign,"op" => "eticket","tradeno" => $tradeno);
  341. return base_api( OPERATE_URL, $get_data);
  342. }
  343. //票务系统更新补充客户数据(用户名,密码,操作参数,票务系统订单号,客户信息)
  344. function customer( $user, $pass, $tradeno ,$customerlist){
  345. $sign = API_SIGN;
  346. $get_data = array("user" => $user,"sign" => $sign,"op" => "customer","tradeno" => $tradeno,"customerlist" => $customerlist);
  347. return base_api( OPERATE_URL, $get_data);
  348. }
  349. //票务系统订单状态查询(用户名,密码,操作参数,票务系统订单号)
  350. function status( $user, $pass, $tn){
  351. $sign = API_SIGN;
  352. $get_data = array("user" => $user,"sign" => $sign,"op" => "status","tn" => $tn);
  353. return base_api( OPERATE_URL, $get_data);
  354. }
  355. //获取线路产品介绍信息(用户名,密码,操作参数,产品代码)
  356. function circuitry( $user, $pass, $op, $ccode){
  357. $sign = API_SIGN;
  358. $get_data = array("user" => $user,"sign" => $sign,"op" => "circuitry","ccode" => $ccode);
  359. return base_api( OPERATE_URL, $get_data);
  360. }