5 && strtolower(substr($remote_server, 0, 5)) == "https") { curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false); } curl_setopt($ch, CURLOPT_URL, $remote_server); curl_setopt($ch, CURLOPT_POSTFIELDS, $post_string); curl_setopt($ch, CURLOPT_TIMEOUT, $second); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); 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'); $data = curl_exec($ch); curl_close($ch); return $data; } //发送get参数(链接,参数数组) static function send_get($url, $get_data) { $url_param = http_build_query($get_data); $result = file_get_contents($url . "?{$url_param}"); return $result; } //将xml转换为数组 static function xml_to_array($xml) { $ob = simplexml_load_string($xml); $json = json_encode($ob); $array = json_decode($json, true); return $array; } //array转xml static function data_to_xml($data) { if (is_object($data)) { $data = get_object_vars($data); } $xml = ''; foreach ($data as $key => $val) { if (is_null($val)) { $xml .= "<$key/>\n"; } else { is_numeric($key) && $key = "item"; $xml .= "<$key>"; $xml .= (is_array($val) || is_object($val)) ? self::data_to_xml($val) : $val; list($key,) = explode(' ', $key); $xml .= ""; } } return $xml; } //获取数据(链接,参数数组) static function base_api($url, $get_data) { $get_data["tt"] = rand(100000, 999999); $return_result = self::send_get($url, $get_data); $return_result = self::xml_to_array($return_result); return $return_result; } //返回中文字符串长度 static function utf8_strlen($string = null) { // 将字符串分解为单元 preg_match_all("/./us", $string, $match); // 返回单元个数 return count($match[0]); } //打印日志函数 static function addLog($log) { file_put_contents("update_ticket_log.txt", $log . " 操作时间:" . date("Y-m-d h:i:s", time()) . PHP_EOL, FILE_APPEND); } //判断是几维数组 static function arrayLevel($arr) { $al = array(0); function aL($arr, &$al, $level = 0) { if (is_array($arr)) { $level++; $al[] = $level; foreach ($arr as $v) { aL($v, $al, $level); } } } aL($arr, $al); return max($al); } } class orderService { //票务系统线路列表查询,获取指定账号可销售的线路 function run_list($user) { $sign = zizaiArgs::$SIGN; $get_data = array("user" => $user, "sign" => $sign, "op" => "list"); return orderUtils::base_api(zizaiArgs::$BASE_URL, $get_data); } //获取线路运营日期数据(用户名,密码,操作参数,线路代码) function godate($user, $projcode) { $sign = zizaiArgs::$SIGN; $get_data = array("user" => $user, "sign" => $sign, "op" => "godate", "projcode" => $projcode); return orderUtils::base_api(zizaiArgs::$BASE_URL, $get_data); } //获取线路运营班次数据(用户名,密码,操作参数,线路代码,运营日期) function gorun($user, $projcode, $godate) { $sign = zizaiArgs::$SIGN; $get_data = array("user" => $user, "sign" => $sign, "op" => "gorun", "projcode" => $projcode, "godate" => $godate); return orderUtils::base_api(zizaiArgs::$BASE_URL, $get_data); } //获取班次票种数据(用户名,密码,操作参数,线路代码,去程班次id) function ticket($user, $projcode, $runid) { $sign = zizaiArgs::$SIGN; $get_data = array("user" => $user, "sign" => $sign, "op" => "ticket", "projcode" => $projcode, "runid" => $runid); return orderUtils::base_api(zizaiArgs::$BASE_URL, $get_data); } //获取某个线路代码某一天的票种信息 function get_ticket_array($user, $projcode, $godate, $gotime = "") { $return_result = self::gorun($user, $projcode, $godate); if ($return_result["code"] == 0) { $run_array = $return_result["go_run_list"]["run"]; if (isset($return_result["go_run_list"]["run"]["runid"])) { $run_id = $return_result["go_run_list"]["run"]["runid"]; } else { foreach ($run_array as $run_info) { if ($gotime == "" || $run_info["runtime"] == $gotime) { $run_id = $run_info["runid"]; break; } } } } else { return false; } $return_result = self::ticket($user, $projcode, $run_id); if ($return_result["code"] == 0) { $ticket_array = $return_result["ticket_list"]["ticket"]; } else { $ticket_array = false; } return $ticket_array; } //票务系统直接下单(无需订单确认) /** * @param $user 用户名 * @param $ticket 票种id及张数,中间用‘P’隔开 * @param $name 联系人姓名 * @param $phone 联系人电话 * @param $cardId 身份证号码 * @param $memo 订单备注 没有填空字符串 * @param $bt 订票类型(0:电子票,1:预订票) * @return mixed|string */ function createOrder($user,$ticket,$name,$phone,$cardId,$memo,$bt) { $sign = zizaiArgs::$SIGN; $get_data = array("user" => $user, "sign" => $sign, "op" => "newbook","ticket"=>$ticket,"name"=>$name,"phone"=>$phone,"id"=>$cardId,"memo"=>$memo,"bt"=>$bt); return orderUtils::base_api(zizaiArgs::$BASE_URL, $get_data); } //票务系统锁位(用户名,密码,操作参数,锁位时间,票种id及张数中间用‘P’隔开,订单客人信息,会员ID,优惠码,会员积分) function lock($user, $lock = 15, $ticket, $customer = "", $memid = "", $barcode = "", $score = "") { $sign = zizaiArgs::$SIGN; $get_data = array("user" => $user, "sign" => $sign, "op" => "lock", "lock" => $lock, "ticket" => $ticket, "customer" => $customer, "memid" => $memid, "barcode" => $barcode, "score" => $score); return orderUtils::base_api(zizaiArgs::$BASE_URL, $get_data); } //票务系统订单确认(用户名,密码,操作参数,票务系统订单号) function eticket($user, $tradeno) { $sign = zizaiArgs::$SIGN; $get_data = array("user" => $user, "sign" => $sign, "op" => "eticket", "tradeno" => $tradeno); return orderUtils::base_api(zizaiArgs::$BASE_URL, $get_data); } //票务系统更新补充客户数据(用户名,密码,操作参数,票务系统订单号,客户信息) function customer($user, $tradeno, $customerlist) { $sign = zizaiArgs::$SIGN; $get_data = array("user" => $user, "sign" => $sign, "op" => "customer", "tradeno" => $tradeno, "customerlist" => $customerlist); return orderUtils::base_api(zizaiArgs::$BASE_URL, $get_data); } //票务系统订单状态查询(用户名,密码,操作参数,票务系统订单号) function status($user, $tn) { $sign = zizaiArgs::$SIGN; $get_data = array("user" => $user, "sign" => $sign, "op" => "status", "tn" => $tn); return orderUtils::base_api(zizaiArgs::$BASE_URL, $get_data); } }