Esempio n. 1
0
 /**
  *18查询门店车辆列表
  * @param $json_params
  * @return string
  */
 public static function SearchRQ($json_params)
 {
     $request_time = time();
     // 验证JSON串的正确性
     if (!empty($json_params) && IconvEncode::IsJson($json_params)) {
         // 解析Json
         $request_param = json_decode($json_params, true);
         // 验证Json串中每一组参数的正确性 [S]
         if (empty($request_param['DriverAge'])) {
             $request_param['DriverAge'] = 26;
         }
         // 验证PickUp、DropOff、DriverAge是否存在
         if (empty($request_param['PickUp']) || empty($request_param['DropOff'])) {
             $return_json = json_encode(array('status' => false, 'error_msg' => '0x180002_PickUp、DropOff、DriverAge不可为空'));
             return $return_json;
         }
         // DriverAge只能是大于0小于100的数字
         if (!is_numeric($request_param['DriverAge']) || $request_param['DriverAge'] <= 18 || $request_param['DriverAge'] >= 75) {
             $return_json = json_encode(array('status' => false, 'error_msg' => '0x180003_DriverAge只能是大于18小于75的数字'));
             return $return_json;
         }
         // 声明简短变量
         $PickUp_Location = empty($request_param['PickUp']['Location']) ? '' : $request_param['PickUp']['Location'];
         // PickUp.Location
         $DropOff_Location = empty($request_param['DropOff']['Location']) ? '' : $request_param['DropOff']['Location'];
         // DropOff.Location
         $PickUp_Date = empty($request_param['PickUp']['Date']) ? '' : $request_param['PickUp']['Date'];
         // PickUp.Date
         $DropOff_Date = empty($request_param['DropOff']['Date']) ? '' : $request_param['DropOff']['Date'];
         // DropOff.Date
         // 验证PickUp与DropOff下的 Location与Date是否存在
         if (empty($PickUp_Location) || empty($PickUp_Date) || empty($DropOff_Location) || empty($DropOff_Date)) {
             $return_json = json_encode(array('status' => false, 'error_msg' => '0x180004_PickUp与DropOff下的 Location与Date是否存在'));
             return $return_json;
         }
         // Location下正确的参数名
         $Location_Key = array('id', 'country', 'city');
         // 验证PickUp.Location 中的参数名是否正确
         foreach ($PickUp_Location as $key => $val) {
             if (!in_array($key, $Location_Key)) {
                 $return_json = json_encode(array('status' => false, 'error_msg' => '0x180005_PickUp. Location 下的参数名错误'));
                 return $return_json;
             }
         }
         // 验证DropOff.Location 中的参数名是否正确
         foreach ($DropOff_Location as $key => $val) {
             if (!in_array($key, $Location_Key)) {
                 $return_json = json_encode(array('status' => false, 'error_msg' => '0x180006_DropOff. Location 下的参数名错误'));
                 return $return_json;
             }
         }
         // 验证PickUp.Location 中是否为填写任何条件 [id / country / city]
         if (count($PickUp_Location) == 0) {
             $return_json = json_encode(array('status' => false, 'error_msg' => '0x180007_PickUp. Location 下缺少必填参数'));
             return $return_json;
         } else {
             // 如按国家+城市的方式查询
             if (empty($PickUp_Location['id'])) {
                 // country与city不能单独使用 如填写了country或city的其中一个 另一个也必须填写
                 if (empty($PickUp_Location['country']) && !empty($PickUp_Location['city']) || !empty($PickUp_Location['country']) && empty($PickUp_Location['city'])) {
                     $return_json = json_encode(array('status' => false, 'error_msg' => '0x180008_单独使用了PickUp.Location 下的country或city'));
                     return $return_json;
                 }
             }
         }
         // 验证DropOff.Location 中是否为填写任何条件 [id / country / city]
         if (count($DropOff_Location) == 0) {
             $return_json = json_encode(array('status' => false, 'error_msg' => '0x180009_DropOff. Location 下缺少必填参数'));
             return $return_json;
         } else {
             // 如按国家+城市的方式查询
             if (empty($DropOff_Location['id'])) {
                 // country与city不能单独使用 如填写了country或city的其中一个 另一个也必须填写
                 if (empty($DropOff_Location['country']) && !empty($DropOff_Location['city']) || !empty($DropOff_Location['country']) && empty($DropOff_Location['city'])) {
                     $return_json = json_encode(array('status' => false, 'error_msg' => '0x180010_单独使用了DropOff.Location 下的country或city'));
                     return $return_json;
                 }
             }
         }
         // PickUp.Date 中的参数均为必填项
         if (empty($PickUp_Date['year']) || empty($PickUp_Date['month']) || empty($PickUp_Date['day']) || empty($PickUp_Date['hour']) || empty($PickUp_Date['minute'])) {
             $return_json = json_encode(array('status' => false, 'error_msg' => '0x180011_PickUp.Date下缺少必填参数'));
             return $return_json;
         }
         // DropOff.Date 中的参数均为必填项
         if (empty($DropOff_Date['year']) || empty($DropOff_Date['month']) || empty($DropOff_Date['day']) || empty($DropOff_Date['hour']) || empty($DropOff_Date['minute'])) {
             $return_json = json_encode(array('status' => false, 'error_msg' => '0x180012_DropOff.Date 下缺少必填参数'));
             return $return_json;
         }
         $start_time = strtotime($PickUp_Date['year'] . '-' . $PickUp_Date['month'] . '-' . $PickUp_Date['day'] . ' ' . $PickUp_Date['hour'] . ':' . $DropOff_Date['minute']);
         $end_time = strtotime($DropOff_Date['year'] . '-' . $DropOff_Date['month'] . '-' . $DropOff_Date['day'] . ' ' . $DropOff_Date['hour'] . ':' . $DropOff_Date['minute']);
         // 验证时间范围是否正确 [例:2014-13-38 错误时间strtotime会返回false]
         if ($start_time && $end_time) {
             // 结束时间不能小于开始时间
             if ($end_time < $start_time) {
                 $return_json = json_encode(array('status' => false, 'error_msg' => '0x180014_DropOff.Date 小于了PickUp.Date'));
                 return $return_json;
             }
         } else {
             $return_json = json_encode(array('status' => false, 'error_msg' => '0x180013_PickUp.Date或DropOff.Date不是正确的时间'));
             return $return_json;
         }
         // 验证Json串中每一组参数的正确性 [E]
         // 判断根据ID查询还是根据国家地区查询
         $PickUp_Location = empty($request_param['PickUp']['Location']['id']) ? 'country="' . $request_param['PickUp']['Location']['country'] . '" city="' . $request_param['PickUp']['Location']['city'] . '"' : 'id="' . $request_param['PickUp']['Location']['id'] . '"';
         $DropOff_Location = empty($request_param['DropOff']['Location']['id']) ? 'country="' . $request_param['DropOff']['Location']['country'] . '" city="' . $request_param['DropOff']['Location']['city'] . '"' : 'id="' . $request_param['DropOff']['Location']['id'] . '"';
         //remoteIp 得到客户端ip
         $remoteIp = !empty($request_param['remoteIp']) ? $request_param['remoteIp'] : CARRENTALAPI_REMOTEIP;
         if (!filter_var($remoteIp, FILTER_VALIDATE_IP)) {
             $return_json = json_encode(array('status' => false, 'error_msg' => '0x180015_remoteIp不是正确ip地址'));
             return $return_json;
         }
         // 拼接XML <SearchRQ supplierInfo="true" showReviews="true" >
         $request_xml = '
                     <SearchRQ  supplierInfo="true" prefcurr="USD">
                         <Credentials username="******" password="******" remoteIp="' . $remoteIp . '" />
                         <PickUp>
                             <Location ' . $PickUp_Location . '/>
                             <Date year="' . $request_param['PickUp']['Date']['year'] . '" month="' . $request_param['PickUp']['Date']['month'] . '" day="' . $request_param['PickUp']['Date']['day'] . '" hour="' . $request_param['PickUp']['Date']['hour'] . '" minute="' . $request_param['PickUp']['Date']['minute'] . '"/>
                         </PickUp>
                         <DropOff>
                             <Location ' . $DropOff_Location . '/>
                             <Date year="' . $request_param['DropOff']['Date']['year'] . '" month="' . $request_param['DropOff']['Date']['month'] . '" day="' . $request_param['DropOff']['Date']['day'] . '" hour="' . $request_param['DropOff']['Date']['hour'] . '" minute="' . $request_param['DropOff']['Date']['minute'] . '"/>
                         </DropOff>
                         <DriverAge>' . $request_param['DriverAge'] . '</DriverAge>
                         <Tracking adcamp="example" adplat="example"/>
                     </SearchRQ>';
         // 调用接口获取数据
         $request_data = array('xml' => $request_xml);
         $searchRQ = GetUrlContent::fileGetContent($request_data, CARRENTALAPI_URL, 100, 'POST');
         // $searchRQ='<SearchRS> <MatchList> </MatchList></SearchRS>';
         // ApiLogManage::addRentalcars('SearchRQ_once',$request_xml,$searchRQ,'',$request_time,time(),1);//记录日志
         $simple_xml_obj = simplexml_load_string($searchRQ);
         if (!$simple_xml_obj) {
             //判断数据是否为空
             $return_json = json_encode(array('status' => false, 'error_msg' => '0x180099_返回数据为空或生成xml对象数据为false'));
             return $return_json;
         }
         $data_arr = SimpleXML::simplexml4array($simple_xml_obj);
         if (!empty($data_arr['SearchRS'][0]['MatchList']) && isset($data_arr['SearchRS'][0]['MatchList'])) {
             $result_arr = $data_arr['SearchRS'][0]['MatchList'];
             if (!is_array($result_arr[0]['Match'])) {
                 //判断是否有车辆
                 $return_json = json_encode(array('status' => false, 'error_msg' => '0x180099_返回数据为空或生成xml对象数据为false'));
                 return $return_json;
             }
         }
         //对数据进行处理[S]
         $result_arr = self::filterArray($result_arr);
         //过滤中间层
         //下载rentalcars图片到本地
         /* ini_set('display_errors', 'On');// 显示所有错误
            error_reporting(E_ALL);*/
         foreach ($result_arr as &$match) {
             if (isset($match['Match'])) {
                 //处理车辆图片[S]
                 $oldImageURL = $match['Match']['Vehicle']['ImageURL']['@text'];
                 $parse_oldImageURL = parse_url($oldImageURL);
                 $newImageFile = CARRENTAL_IMAGES_PATH . $parse_oldImageURL['path'];
                 if (!file_exists($newImageFile)) {
                     $match['Match']['Vehicle']['ImageURL']['@text'] = HTTP_URL . GetUrlContent::GrabImage($oldImageURL, $newImageFile);
                 } else {
                     $match['Match']['Vehicle']['ImageURL']['@text'] = HTTP_URL . $newImageFile;
                 }
                 $oldLargeImageURL = $match['Match']['Vehicle']['LargeImageURL']['@text'];
                 $parse_oldLargeImageURL = parse_url($oldLargeImageURL);
                 $newLargeImageFile = CARRENTAL_IMAGES_PATH . $parse_oldLargeImageURL['path'];
                 if (!file_exists($newLargeImageFile)) {
                     $match['Match']['Vehicle']['LargeImageURL']['@text'] = HTTP_URL . GetUrlContent::GrabImage($oldLargeImageURL, $newLargeImageFile);
                 } else {
                     $match['Match']['Vehicle']['LargeImageURL']['@text'] = HTTP_URL . $newLargeImageFile;
                 }
                 //处理车辆图片[E]
                 //处理车辆公司logo[S]
                 $oldSmall_logo = $match['Match']['Supplier']['@attributes']['small_logo'];
                 $parse_oldSmall_logo = parse_url($oldSmall_logo);
                 $newSmall_logo = CARRENTAL_IMAGES_PATH . $parse_oldSmall_logo['path'];
                 if (!file_exists($newSmall_logo)) {
                     $match['Match']['Supplier']['@attributes']['small_logo'] = HTTP_URL . GetUrlContent::GrabImage($oldSmall_logo, $newSmall_logo);
                 } else {
                     $match['Match']['Supplier']['@attributes']['small_logo'] = HTTP_URL . $newSmall_logo;
                 }
                 //处理车辆公司logo[E]
             }
         }
         //对数据进行处理[E]
         $result = json_encode($result_arr);
         if (!empty($result)) {
             $return_json = json_encode(array('status' => true, 'data' => $result_arr));
             ApiLogManage::addRentalcars('SearchRQ', $json_params, $searchRQ, $return_json, $request_time, time(), 1);
             //记录日志
             return $return_json;
         } else {
             $return_json = json_encode(array('status' => false, 'error_msg' => '0x180099_请求超时'));
             ApiLogManage::addRentalcars('SearchRQ', $json_params, $searchRQ, $return_json, $request_time, time(), 10);
             //记录日志
             return $return_json;
             //请求超时
         }
     } else {
         $return_json = json_encode(array('status' => false, 'error_msg' => '0x180001_JSON参数格式错误'));
         return $return_json;
     }
 }
Esempio n. 2
0
 public function actionGetImg()
 {
     $imgPath = 'http://xml.rentalcars.com:80/images/car_images/newsite/D/fiat_500l.jpg';
     $newFile = CARRENTAL_IMAGES_PATH . parse_url($imgPath)['path'];
     echo GetUrlContent::GrabImage($imgPath, $newFile);
 }