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.
 
 
 
 
 

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