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.
 
 
 
 

359 lines
13 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);
  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);
  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. if( $disney_array != false ) {
  151. foreach( $disney_array as $key => $disney_info ) {
  152. $return_index = $_ary_disney_index[$key];
  153. $return_array[$return_index] = $disney_info["ticketcount"];
  154. }
  155. }
  156. if( $disney_array2 != false ) {
  157. foreach( $disney_array2 as $key => $disney_info ) {
  158. $return_index = $_ary_disney_index[$key];
  159. $return_array[$return_index] = $disney_info["ticketcount"];
  160. }
  161. }
  162. return $return_array;
  163. }
  164. function get_lion_king_info( $godate, $gotime = "" ) {
  165. $_ary_lionking_index = array(
  166. "AA区" => 0,
  167. "AB区" => 1,
  168. "BA区" => 2,
  169. "BB区" => 3,
  170. "CA区" => 4,
  171. "CB区" => 5
  172. );
  173. $return_array = array( 0,0,0,0,0,0 );
  174. $lion_array = get_disney_info3( $godate, $gotime);
  175. if( $lion_array != false ) {
  176. foreach( $lion_array as $key => $lion_info ) {
  177. $return_index = $_ary_lionking_index[$key];
  178. $return_array[$return_index] = $lion_info["ticketcount"];
  179. }
  180. }
  181. return $return_array;
  182. }
  183. //传入参数 buy_array 购买票数的数组 array(0,0,0,0,0,0)
  184. //返回值 -1 库存不足 0 出票失败 其他 成功且返回自在订单号
  185. function buy_disney_ticket( $cus_name, $cus_mobile, $cus_idno, $buy_array, $godate ) {
  186. $_ary_disney_index = array(
  187. "成人票" => 0,
  188. "老人票" => 2,
  189. "儿童票" => 1,
  190. "二日成人票" => 3,
  191. "二日老人票" => 5,
  192. "二日儿童票" => 4
  193. );
  194. $disney_array = get_disney_info( $godate );
  195. $disney_array2 = get_disney_info2( $godate );
  196. $disney_all_array = array();
  197. if( false != $disney_array ) {
  198. foreach( $disney_array as $key => $disney_info ) {
  199. $return_index = $_ary_disney_index[$key];
  200. $disney_all_array[$return_index] = $disney_info;
  201. }
  202. }
  203. if( false != $disney_array2 ) {
  204. foreach( $disney_array2 as $key => $disney_info ) {
  205. $return_index = $_ary_disney_index[$key];
  206. $disney_all_array[$return_index] = $disney_info;
  207. }
  208. }
  209. $buy_prod_txt = "";
  210. foreach( $buy_array as $key => $buy_num ) {
  211. $disney_info = $disney_all_array[$key];
  212. if( $disney_info["ticketcount"] < $buy_num ) {
  213. return -1;
  214. }
  215. $buy_prod_txt .= $disney_info["ticketid"] . "P" . $buy_num . "|";
  216. }
  217. $customer_txt = '{|' . $cus_name . '|' . $cus_mobile . '|' . $cus_idno . '||}';
  218. $result_info = lock(API_USER, API_PASSWORD, 15, $buy_prod_txt, $customer_txt, "", "", "");
  219. if ($result_info["code"] == 0) {
  220. $trade_no = $result_info["tradeno"];
  221. } else {
  222. return 0;
  223. }
  224. $result_info2 = eticket(API_USER, API_PASSWORD, $trade_no);
  225. if ($result_info2["code"] == 0) {
  226. return $trade_no;
  227. } else {
  228. return 0;
  229. }
  230. }
  231. //传入参数 buy_array 购买票数的数组 array(0,0,0,0,0,0)
  232. //返回值 -1 库存不足 0 出票失败 其他 成功且返回自在订单号
  233. function buy_lionking_ticket( $cus_name, $cus_mobile, $cus_idno, $buy_array, $godate, $gotime = "" ) {
  234. $_ary_lionking_index = array(
  235. "AA区" => 0,
  236. "AB区" => 1,
  237. "BA区" => 2,
  238. "BB区" => 3,
  239. "CA区" => 4,
  240. "CB区" => 5
  241. );
  242. $lion_array = get_disney_info3( $godate, $gotime);
  243. $lion_all_array = array();
  244. if( $lion_array != false ) {
  245. foreach( $lion_array as $key => $lion_info ) {
  246. $return_index = $_ary_lionking_index[$key];
  247. $lion_all_array[$return_index] = $lion_info["ticketcount"];
  248. }
  249. }
  250. $buy_prod_txt = "";
  251. foreach( $buy_array as $key => $buy_num ) {
  252. $lionking_info = $lion_all_array[$key];
  253. if( $lionking_info["ticketcount"] < $buy_num ) {
  254. return -1;
  255. }
  256. $buy_prod_txt .= $lionking_info["ticketid"] . "P" . $buy_num . "|";
  257. }
  258. $customer_txt = '{|' . $cus_name . '|' . $cus_mobile . '|' . $cus_idno . '||}';
  259. $result_info = lock(API_USER, API_PASSWORD, 15, $buy_prod_txt, $customer_txt, "", "", "");
  260. if ($result_info["code"] == 0) {
  261. $trade_no = $result_info["tradeno"];
  262. } else {
  263. return 0;
  264. }
  265. $result_info2 = eticket(API_USER, API_PASSWORD, $trade_no);
  266. if ($result_info2["code"] == 0) {
  267. return $trade_no;
  268. } else {
  269. return 0;
  270. }
  271. }
  272. //获取迪士尼演出信息
  273. function get_disney_info3( $godate, $gotime = "" ) {
  274. $ticket_array = get_ticket_array( API_USER,API_PASSWORD, DISNEY_CODE3, $godate, $gotime );
  275. if( $ticket_array == false ) { return false; }
  276. $ticket_array2 = array();
  277. foreach( $ticket_array as $ticket_info ) {
  278. $index_name = mb_substr($ticket_info["ticketname"],2,3);
  279. $ticket_array2[$index_name] = $ticket_info;
  280. }
  281. return $ticket_array2;
  282. }
  283. //获取线路运营班次返程日期数据(用户名,密码,操作参数,线路代码,去程班次id)
  284. function backdate( $user, $pass, $projcode ,$runid){
  285. $sign = API_SIGN;
  286. $get_data = array("user" => $user,"sign" => $sign,"op" => "backdate","projcode" => $projcode,"runid" => $runid);
  287. return base_api( OPERATE_URL, $get_data);
  288. }
  289. //获取线路特定班次返程班次数据(用户名,密码,操作参数,线路代码,去程班次id,回程日期)
  290. function backrun( $user, $pass, $projcode ,$runid ,$backdate){
  291. $sign = API_SIGN;
  292. $get_data = array("user" => $user,"sign" => $sign,"op" => "backrun","projcode" => $projcode,"runid" => $runid,"backdate" => $backdate);
  293. return base_api( OPERATE_URL, $get_data);
  294. }
  295. //获取班次票种数据(用户名,密码,操作参数,线路代码,去程班次id)
  296. function ticket( $user, $pass, $projcode ,$runid){
  297. $sign = API_SIGN;
  298. $get_data = array("user" => $user,"sign" => $sign,"op" => "ticket","projcode" => $projcode,"runid" => $runid);
  299. return base_api( OPERATE_URL, $get_data);
  300. }
  301. //票务系统锁位(用户名,密码,操作参数,锁位时间,票种id及张数中间用‘P’隔开,订单客人信息,会员ID,优惠码,会员积分)
  302. function lock( $user, $pass, $lock = 15 ,$ticket ,$customer = "",$memid = "",$barcode = "",$score= ""){
  303. $sign = API_SIGN;
  304. $get_data = array("user" => $user,"sign" => $sign,"op" => "lock","lock" => $lock,"ticket" => $ticket,"customer" => $customer,"memid" => $memid,"barcode" => $barcode,"score" => $score);
  305. return base_api( OPERATE_URL, $get_data);
  306. }
  307. //票务系统订单确认(用户名,密码,操作参数,票务系统订单号)
  308. function eticket( $user, $pass, $tradeno){
  309. $sign = API_SIGN;
  310. $get_data = array("user" => $user,"sign" => $sign,"op" => "eticket","tradeno" => $tradeno);
  311. return base_api( OPERATE_URL, $get_data);
  312. }
  313. //票务系统更新补充客户数据(用户名,密码,操作参数,票务系统订单号,客户信息)
  314. function customer( $user, $pass, $tradeno ,$customerlist){
  315. $sign = API_SIGN;
  316. $get_data = array("user" => $user,"sign" => $sign,"op" => "customer","tradeno" => $tradeno,"customerlist" => $customerlist);
  317. return base_api( OPERATE_URL, $get_data);
  318. }
  319. //票务系统订单状态查询(用户名,密码,操作参数,票务系统订单号)
  320. function status( $user, $pass, $tn){
  321. $sign = API_SIGN;
  322. $get_data = array("user" => $user,"sign" => $sign,"op" => "status","tn" => $tn);
  323. return base_api( OPERATE_URL, $get_data);
  324. }
  325. //获取线路产品介绍信息(用户名,密码,操作参数,产品代码)
  326. function circuitry( $user, $pass, $op, $ccode){
  327. $sign = API_SIGN;
  328. $get_data = array("user" => $user,"sign" => $sign,"op" => "circuitry","ccode" => $ccode);
  329. return base_api( OPERATE_URL, $get_data);
  330. }