Example #1
0
 /**
  *17查询预定订单信息
  * @param $json_params
  * @return string
  */
 public static function BookingInfoRQ($json_params)
 {
     $request_time = time();
     // 验证Jons串的正确性
     if (!empty($json_params) && IconvEncode::IsJson($json_params)) {
         $request_param = json_decode($json_params, true);
         // 验证Json串中每一组参数的正确性 [S]
         // 过滤空格与空值
         foreach ($request_param as $key => $val) {
             $request_param[$key] = trim($val);
         }
         $request_param = array_filter($request_param);
         // 验证ID和Email是否存在
         if (empty($request_param['id']) || empty($request_param['Email'])) {
             $return_json = json_encode(array('status' => false, 'error_msg' => '0x170002_ID和Email必须存在'));
             ApiLogManage::addRentalcars('BookingInfoRQ', $json_params, '', $return_json, $request_time, time(), 2);
             //记录日志
             return $return_json;
         }
         // 验证ID是否是数字
         if (!is_numeric($request_param['id'])) {
             $return_json = json_encode(array('status' => false, 'error_msg' => '0x170003_验证ID是否是数字'));
             ApiLogManage::addRentalcars('BookingInfoRQ', $json_params, '', $return_json, $request_time, time(), 2);
             //记录日志
             return $return_json;
         }
         // 验证Email格式是否正确
         if (!preg_match('/^(\\w)+(\\.\\w+)*@(\\w)+((\\.\\w{2,3}){1,3})$/', $request_param['Email'])) {
             $return_json = json_encode(array('status' => false, 'error_msg' => '0x170004_Email格式不正确'));
             ApiLogManage::addRentalcars('BookingInfoRQ', $json_params, '', $return_json, $request_time, time(), 2);
             //记录日志
             return $return_json;
         }
         // 验证Json串中每一组参数的正确性 [E]
         // 拼接XML
         $request_xml = '
                     <BookingInfoRQ>
                         <Credentials username="******" password="******" remoteIp="' . CARRENTALAPI_REMOTEIP . '" />
                         <Booking id="' . $request_param['id'] . '"></Booking>
                         <Email>' . $request_param['Email'] . '</Email>
                     </BookingInfoRQ>';
         // 调用接口获取数据
         $request_data = array('xml' => $request_xml);
         $bookingInfoRS = GetUrlContent::fileGetContent($request_data, CARRENTALAPI_URL, 30, 'POST');
         $return_object = simplexml_load_string($bookingInfoRS);
         $data_arr = SimpleXML::simplexml4array($return_object);
         $result_arr = RcManager::filterArray($data_arr);
         //过滤中间层
         //$result= json_encode($return_object);
         if (!empty($result_arr['BookingInfoRS']['Booking'])) {
             $return_json = json_encode(array('status' => true, 'data' => $result_arr['BookingInfoRS']));
             ApiLogManage::addRentalcars('BookingInfoRQ', $json_params, $bookingInfoRS, $return_json, $request_time, time(), 1);
             //记录日志
             return $return_json;
         } else {
             $return_json = json_encode(array('status' => false, 'error_msg' => '0x170005_请求超时'));
             ApiLogManage::addRentalcars('BookingInfoRQ', $json_params, $bookingInfoRS, $return_json, $request_time, time(), 10);
             //记录日志
             return $return_json;
         }
     } else {
         $return_json = json_encode(array('status' => false, 'error_msg' => '0x170001_JSON参数格式错误'));
         ApiLogManage::addRentalcars('BookingInfoRQ', $json_params, '', $return_json, $request_time, time(), 2);
         //记录日志
         return $return_json;
     }
 }