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.
 
 
 
 

238 lines
8.4 KiB

  1. <?php
  2. /**
  3. * Created by PhpStorm.
  4. * User: Steven
  5. * Date: 2016/8/9
  6. * Time: 10:48
  7. */
  8. header('Content_Type: application/xml;charset=utf-8');
  9. date_default_timezone_set('Asia/Shanghai');
  10. class zizaiArgs
  11. {
  12. /*public static $USER = "zzcx01";
  13. public static $SIGN = "03EF41375E5149EFB5CCD6AE236555C7";*/
  14. public static $USER = "zzcx02";
  15. public static $SIGN = "4E84E1EEBAF00B352DEF2B8F3336B63C";
  16. public static $BASE_URL = "http://partner.zizaitrip.net/interface";
  17. }
  18. class orderUtils
  19. {
  20. //发送post参数(链接,参数数组)
  21. static function request_by_curl($remote_server, $post_string = null, $second = 60)
  22. {
  23. $ch = curl_init();
  24. if (strlen($remote_server) > 5 && strtolower(substr($remote_server, 0, 5)) == "https") {
  25. curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
  26. curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
  27. }
  28. curl_setopt($ch, CURLOPT_URL, $remote_server);
  29. curl_setopt($ch, CURLOPT_POSTFIELDS, $post_string);
  30. curl_setopt($ch, CURLOPT_TIMEOUT, $second);
  31. curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
  32. curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/5.0 (Windows; U; Windows NT 5.1; zh-CN; rv:1.9.1.2) Gecko/20090729 Firefox/3.5.2');
  33. $data = curl_exec($ch);
  34. curl_close($ch);
  35. return $data;
  36. }
  37. //发送get参数(链接,参数数组)
  38. static function send_get($url, $get_data)
  39. {
  40. $url_param = http_build_query($get_data);
  41. $result = file_get_contents($url . "?{$url_param}");
  42. return $result;
  43. }
  44. //将xml转换为数组
  45. static function xml_to_array($xml)
  46. {
  47. $ob = simplexml_load_string($xml);
  48. $json = json_encode($ob);
  49. $array = json_decode($json, true);
  50. return $array;
  51. }
  52. //array转xml
  53. static function data_to_xml($data)
  54. {
  55. if (is_object($data)) {
  56. $data = get_object_vars($data);
  57. }
  58. $xml = '';
  59. foreach ($data as $key => $val) {
  60. if (is_null($val)) {
  61. $xml .= "<$key/>\n";
  62. } else {
  63. is_numeric($key) && $key = "item";
  64. $xml .= "<$key>";
  65. $xml .= (is_array($val) || is_object($val)) ? self::data_to_xml($val) : $val;
  66. list($key,) = explode(' ', $key);
  67. $xml .= "</$key>";
  68. }
  69. }
  70. return $xml;
  71. }
  72. //获取数据(链接,参数数组)
  73. static function base_api($url, $get_data)
  74. {
  75. $get_data["tt"] = rand(100000, 999999);
  76. $return_result = self::send_get($url, $get_data);
  77. $return_result = self::xml_to_array($return_result);
  78. return $return_result;
  79. }
  80. //返回中文字符串长度
  81. static function utf8_strlen($string = null)
  82. {
  83. // 将字符串分解为单元
  84. preg_match_all("/./us", $string, $match);
  85. // 返回单元个数
  86. return count($match[0]);
  87. }
  88. //打印日志函数
  89. static function addLog($log)
  90. {
  91. file_put_contents("update_ticket_log.txt", $log . " 操作时间:" . date("Y-m-d h:i:s", time()) . PHP_EOL, FILE_APPEND);
  92. }
  93. //判断是几维数组
  94. static function arrayLevel($arr)
  95. {
  96. $al = array(0);
  97. function aL($arr, &$al, $level = 0)
  98. {
  99. if (is_array($arr)) {
  100. $level++;
  101. $al[] = $level;
  102. foreach ($arr as $v) {
  103. aL($v, $al, $level);
  104. }
  105. }
  106. }
  107. aL($arr, $al);
  108. return max($al);
  109. }
  110. }
  111. class orderService
  112. {
  113. //票务系统线路列表查询,获取指定账号可销售的线路
  114. function run_list($user)
  115. {
  116. $sign = zizaiArgs::$SIGN;
  117. $get_data = array("user" => $user, "sign" => $sign, "op" => "list");
  118. return orderUtils::base_api(zizaiArgs::$BASE_URL, $get_data);
  119. }
  120. //获取线路运营日期数据(用户名,密码,操作参数,线路代码)
  121. function godate($user, $projcode)
  122. {
  123. $sign = zizaiArgs::$SIGN;
  124. $get_data = array("user" => $user, "sign" => $sign, "op" => "godate", "projcode" => $projcode);
  125. return orderUtils::base_api(zizaiArgs::$BASE_URL, $get_data);
  126. }
  127. //获取线路运营班次数据(用户名,密码,操作参数,线路代码,运营日期)
  128. function gorun($user, $projcode, $godate)
  129. {
  130. $sign = zizaiArgs::$SIGN;
  131. $get_data = array("user" => $user, "sign" => $sign, "op" => "gorun", "projcode" => $projcode, "godate" => $godate);
  132. return orderUtils::base_api(zizaiArgs::$BASE_URL, $get_data);
  133. }
  134. //获取班次票种数据(用户名,密码,操作参数,线路代码,去程班次id)
  135. function ticket($user, $projcode, $runid)
  136. {
  137. $sign = zizaiArgs::$SIGN;
  138. $get_data = array("user" => $user, "sign" => $sign, "op" => "ticket", "projcode" => $projcode, "runid" => $runid);
  139. return orderUtils::base_api(zizaiArgs::$BASE_URL, $get_data);
  140. }
  141. //获取某个线路代码某一天的票种信息
  142. function get_ticket_array($user, $projcode, $godate, $gotime = "")
  143. {
  144. $return_result = self::gorun($user, $projcode, $godate);
  145. if ($return_result["code"] == 0) {
  146. $run_array = $return_result["go_run_list"]["run"];
  147. if (isset($return_result["go_run_list"]["run"]["runid"])) {
  148. $run_id = $return_result["go_run_list"]["run"]["runid"];
  149. } else {
  150. foreach ($run_array as $run_info) {
  151. if ($gotime == "" || $run_info["runtime"] == $gotime) {
  152. $run_id = $run_info["runid"];
  153. break;
  154. }
  155. }
  156. }
  157. } else {
  158. return false;
  159. }
  160. $return_result = self::ticket($user, $projcode, $run_id);
  161. if ($return_result["code"] == 0) {
  162. $ticket_array = $return_result["ticket_list"]["ticket"];
  163. } else {
  164. $ticket_array = false;
  165. }
  166. return $ticket_array;
  167. }
  168. //票务系统直接下单(无需订单确认)
  169. /**
  170. * @param $user 用户名
  171. * @param $ticket 票种id及张数,中间用‘P’隔开
  172. * @param $name 联系人姓名
  173. * @param $phone 联系人电话
  174. * @param $cardId 身份证号码
  175. * @param $memo 订单备注 没有填空字符串
  176. * @param $bt 订票类型(0:电子票,1:预订票)
  177. * @return mixed|string
  178. */
  179. function createOrder($user,$ticket,$name,$phone,$cardId,$memo,$bt)
  180. {
  181. $sign = zizaiArgs::$SIGN;
  182. $get_data = array("user" => $user, "sign" => $sign, "op" => "newbook","ticket"=>$ticket,"name"=>$name,"phone"=>$phone,"id"=>$cardId,"memo"=>$memo,"bt"=>$bt);
  183. return orderUtils::base_api(zizaiArgs::$BASE_URL, $get_data);
  184. }
  185. //票务系统锁位(用户名,密码,操作参数,锁位时间,票种id及张数中间用‘P’隔开,订单客人信息,会员ID,优惠码,会员积分)
  186. function lock($user, $lock = 15, $ticket, $customer = "", $memid = "", $barcode = "", $score = "")
  187. {
  188. $sign = zizaiArgs::$SIGN;
  189. $get_data = array("user" => $user, "sign" => $sign, "op" => "lock", "lock" => $lock, "ticket" => $ticket, "customer" => $customer, "memid" => $memid, "barcode" => $barcode, "score" => $score);
  190. return orderUtils::base_api(zizaiArgs::$BASE_URL, $get_data);
  191. }
  192. //票务系统订单确认(用户名,密码,操作参数,票务系统订单号)
  193. function eticket($user, $tradeno)
  194. {
  195. $sign = zizaiArgs::$SIGN;
  196. $get_data = array("user" => $user, "sign" => $sign, "op" => "eticket", "tradeno" => $tradeno);
  197. return orderUtils::base_api(zizaiArgs::$BASE_URL, $get_data);
  198. }
  199. //票务系统更新补充客户数据(用户名,密码,操作参数,票务系统订单号,客户信息)
  200. function customer($user, $tradeno, $customerlist)
  201. {
  202. $sign = zizaiArgs::$SIGN;
  203. $get_data = array("user" => $user, "sign" => $sign, "op" => "customer", "tradeno" => $tradeno, "customerlist" => $customerlist);
  204. return orderUtils::base_api(zizaiArgs::$BASE_URL, $get_data);
  205. }
  206. //票务系统订单状态查询(用户名,密码,操作参数,票务系统订单号)
  207. function status($user, $tn)
  208. {
  209. $sign = zizaiArgs::$SIGN;
  210. $get_data = array("user" => $user, "sign" => $sign, "op" => "status", "tn" => $tn);
  211. return orderUtils::base_api(zizaiArgs::$BASE_URL, $get_data);
  212. }
  213. }