Example #1
0
 /**
  * 22得到热门地区的车辆信息
  * /index.php?r=CarrentalApi/rc/GetHotAreaMatchListRQ&json_params={"remoteIp":"106.2.184.106"}
  * 强制更热门地区数据的方式  /index.php?r=CarrentalApi/rc/GetHotAreaMatchListRQ&json_params={"remoteIp":"106.2.184.106"}&updateRedis=yes
  *
  * http://brs.test.baicheng.com/index.php?r=CarrentalApi/rc/GetHotAreaMatchListRQ\&update=crontabRedis //用于强制更新数据
  * http://brs.test.baicheng.com/index.php?r=CarrentalApi/rc/GetHotAreaMatchListRQ\&update=crontabShow //用于确认数据是否更新完,否则再次更新
  */
 public function actionGetHotAreaMatchListRQ()
 {
     /*  ini_set("display_errors", "On");
         error_reporting(E_ALL | E_STRICT);*/
     ini_set('max_execution_time', 1000);
     $Redis = YiiRedis::getInstance();
     $request_time = time();
     $json_params = Yii::app()->request->getParam('json_params');
     //客户端请求的json参数
     $update = Yii::app()->request->getParam('update');
     //是否强制更新redis中的查询数据
     $is_updateRedis = !empty($update) && $update == "crontabRedis" ? true : false;
     //用于强制更新数据 如:crontab
     $is_show = !empty($update) && $update == "crontabShow" ? true : false;
     //用于确认数据是否更新完,否则再次更新   用于 crontab
     // 验证JSON串的正确性
     if (!empty($json_params) && IconvEncode::IsJson($json_params) || $is_updateRedis || $is_show) {
         //remoteIp 得到客户端ip[S]
         $arr_params = json_decode($json_params, true);
         $arr_params['remoteIp'] = !empty($arr_params['remoteIp']) ? $arr_params['remoteIp'] : CARRENTALAPI_REMOTEIP;
         $remoteIp = $arr_params['remoteIp'];
         $json_params = json_encode($arr_params);
         if (!filter_var($remoteIp, FILTER_VALIDATE_IP)) {
             $return_json = json_encode(array('status' => false, 'error_msg' => '0x220002_remoteIp不是正确ip地址'));
             return $return_json;
         }
         //remoteIp 得到客户端ip[E]
         //得到搜索数据[S]
         //生成redis key
         $search_reasult_key = 'search_hor_area_' . md5($json_params);
         if ($Redis->get($search_reasult_key) && !$is_updateRedis && !$is_show) {
             $Rs = $Redis->get($search_reasult_key);
             exit($Rs);
         }
         //得到搜索数据[E]
         //得到热门地区
         $sql = "SELECT a.*,b.Name as ContinentName,b.Sort AS ContinentSort FROM rentalcars_hot_city AS a INNER JOIN rentalcars_hot_continent AS b ON  a.ContinentId=b.ID WHERE a.Status='1' AND b.Status='1' ORDER BY b.Sort  ASC ,a.Sort ASC";
         $HotArea_array = RentalcarsHotCity::model()->dbConnection->createCommand($sql)->queryAll();
         $request_params = array();
         $area_list_arr = array();
         $key = 0;
         foreach ($HotArea_array as $area) {
             $continentSort = $area['ContinentSort'];
             //大洲权重
             $request_date_unix = time() + 60 * 60 * 24 * 21;
             //21天后的车辆查询时间
             //得到城市下的所有门店[S]
             $pickUp_params_arr = array('country' => $area['RcCountry'], 'city' => $area['RcCity']);
             $pickUp_params_json = json_encode($pickUp_params_arr);
             $pickUp_location_json = RcManager::PickUpLocationListFilter($pickUp_params_json);
             $pickUp_location_arr = json_decode($pickUp_location_json, true);
             //得到城市下的所有门店[S]
             $pickUp_location_id_same = false;
             //判断某个门店下是否找到符合条件的车型
             if ($pickUp_location_arr['status'] && is_array($pickUp_location_arr['data'])) {
                 foreach ($pickUp_location_arr['data'] as $pickUp_location_val) {
                     //设置热门城市的条件[S]
                     $request_params['PickUp']['Location']['country'] = $area['RcCountry'];
                     $request_params['PickUp']['Location']['city'] = $area['RcCity'];
                     $request_params['PickUp']['Location']['id'] = $pickUp_location_val['id'];
                     $request_params['PickUp']['Date']['year'] = date('Y', $request_date_unix);
                     $request_params['PickUp']['Date']['month'] = date('m', $request_date_unix);
                     $request_params['PickUp']['Date']['day'] = date('d', $request_date_unix);
                     $request_params['PickUp']['Date']['hour'] = "10";
                     $request_params['PickUp']['Date']['minute'] = "30";
                     $request_params['DropOff']['Location'] = $request_params['PickUp']['Location'];
                     // $request_params['DropOff']['Date']=$request_params['PickUp']['Date'];
                     $request_params['DropOff']['Date']['year'] = date('Y', $request_date_unix + 60 * 60 * 24 * 7);
                     $request_params['DropOff']['Date']['month'] = date('m', $request_date_unix + 60 * 60 * 24 * 7);
                     $request_params['DropOff']['Date']['day'] = date('d', $request_date_unix + 60 * 60 * 24 * 7);
                     $request_params['DropOff']['Date']['hour'] = "10";
                     $request_params['DropOff']['Date']['minute'] = "30";
                     $request_params['DriverAge'] = 26;
                     $request_params['remoteIp'] = $remoteIp;
                     $request_json = json_encode($request_params);
                     //设置热门城市的条件[E]
                     //得到搜索数据[S]
                     //生成redis key
                     $search_reasult_key = 'search_hor_area_' . md5($request_json);
                     if ($Redis->get($search_reasult_key) && !$is_updateRedis) {
                         $Rs = $Redis->get($search_reasult_key);
                         $Rs_array = json_decode($Rs, true);
                     } else {
                         $Rs = RcManager::SearchRQ($request_json);
                         $Rs_array = json_decode($Rs, true);
                         if ($Rs_array['status']) {
                             $Redis->set($search_reasult_key, $Rs, 60 * 60 * 24);
                         }
                     }
                     //得到搜索数据[E]
                     //处理返回数据[S]
                     $RS_boss_carRentalTapeCompany_json = RcManager::CarRentalTapeCompany('');
                     //要过滤的租车公司名称
                     if (!empty($Rs_array['status']) && (bool) $Rs_array['status']) {
                         if (!empty($Rs_array['data']) && is_array($Rs_array['data'])) {
                             $Rs_data_array = $Rs_array['data'];
                             foreach ($Rs_data_array as $match) {
                                 if (!empty($match['Match']['Vehicle']['@attributes']['group'])) {
                                     $match_group = $match['Match']['Vehicle']['@attributes']['group'];
                                     //得到车辆类型编号
                                     //过滤租车公司[S]
                                     if ($RS_boss_carRentalTapeCompany_json) {
                                         $RS_boss__carRentalTapeCompany_arr = json_decode($RS_boss_carRentalTapeCompany_json, true);
                                         if (!empty($match['Match']['Supplier']['@text'])) {
                                             $supplier_name = $match['Match']['Supplier']['@text'];
                                             if (in_array($supplier_name, $RS_boss__carRentalTapeCompany_arr)) {
                                                 continue;
                                                 //过滤下线的租车公司
                                             }
                                         }
                                     }
                                     //过滤租车公司[E]
                                     if (RcManager::isVehicleType('C', $match_group)) {
                                         //过滤车辆
                                         $area_list_arr[$continentSort][$key]['Match'] = $match['Match'];
                                         $area_list_arr[$continentSort][$key]['CityNameCn'] = $area['CityNameCn'];
                                         $area_list_arr[$continentSort][$key]['CityNameEn'] = $area['CityNameEn'];
                                         $area_list_arr[$continentSort][$key]['Search'] = $request_params;
                                         $area_list_arr[$continentSort]['ContinentName'] = $area['ContinentName'];
                                         $pickUp_location_id_same = true;
                                         $key++;
                                         break;
                                     }
                                 }
                             }
                         }
                     }
                     //处理返回数据[S]
                     if (!$pickUp_location_id_same) {
                         continue;
                     } else {
                         break;
                     }
                 }
             }
         }
         unset($Rs, $Rs_array, $Rs_data_array, $match_group, $match, $HotArea_array);
         $return_array = array('status' => true, 'data' => $area_list_arr);
         $return_json = json_encode($return_array);
         ApiLogManage::addRentalcars('GetHotAreaMatchListRQ', '', '', $return_json, $request_time, time(), 1);
         //记录日志
         //设置搜索数据到redis[S]
         //生成redis key
         $search_reasult_key = 'search_hor_area_' . md5($json_params);
         $Redis->set($search_reasult_key, $return_json, 60 * 60 * 24);
         //得到搜索数据[E]
         exit($return_json);
     } else {
         $return_json = json_encode(array('status' => false, 'error_msg' => '0x220001_json数据格式不正确'));
         exit($return_json);
     }
 }
 /**
  * 18查询租车信息
  * @return String
  * 错误代码:[1.JSON参数格式错误 / 2.PickUp或DropOff或DriverAge 的参数名错误 / 3.DriverAge的参数错误 / 4.PickUp或DropOff下 缺少Location或Date参数 / 5.PickUp. Location 下的参数名错误
  *          6.DropOff. Location 下的参数名错误 / 7.PickUp. Location 下缺少必填参数 / 8.单独使用了PickUp.Location 下的country或city / 9.DropOff. Location 下缺少必填参数 /
  *          10.单独使用了DropOff.Location 下的country或city / 11.PickUp.Date下缺少必填参数 / 12.DropOff.Date 下缺少必填参数 / 13.PickUp.Date或DropOff.Date不是正确的时间 / 14.DropOff.Date 小于了 PickUp.Date]
  */
 public function actionSearchRQ()
 {
     $request_time = time();
     $json_params = Yii::app()->request->getParam('json_params');
     //客户端请求的json参数
     //        $json_params = '{"PickUp":{"Location":{"id":"1124991"},"Date":{"year":"2014","month":"12","day":"12","hour":"12","minute":"30"}},"DropOff":{"Location":{"id":"1124991"},"Date":{"year":"2014","month":"12","day":"30","hour":"12","minute":"30"}},"DriverAge":"32"}';
     // 验证JSON串的正确性
     if (!empty($json_params) && IconvEncode::IsJson($json_params)) {
         // 解析Json
         $request_param = json_decode($json_params, true);
         // 验证Json串中每一组参数的正确性 [S]
         // 验证PickUp、DropOff、DriverAge是否存在
         if (empty($request_param['PickUp']) || empty($request_param['DropOff']) || empty($request_param['DriverAge'])) {
             $return_json = json_encode(array('status' => false, 'error_msg' => '2_PickUp、DropOff、DriverAge不可为空'));
             exit($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' => '3_DriverAge只能是大于18小于75的数字'));
             exit($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' => '4_PickUp与DropOff下的 Location与Date是否存在'));
             exit($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' => '5_PickUp. Location 下的参数名错误'));
                 exit($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' => '6_DropOff. Location 下的参数名错误'));
                 exit($return_json);
             }
         }
         // 验证PickUp.Location 中是否为填写任何条件 [id / country / city]
         if (count($PickUp_Location) == 0) {
             $return_json = json_encode(array('status' => false, 'error_msg' => '7_PickUp. Location 下缺少必填参数'));
             exit($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' => '8_单独使用了PickUp.Location 下的country或city'));
                     exit($return_json);
                 }
             }
         }
         // 验证DropOff.Location 中是否为填写任何条件 [id / country / city]
         if (count($DropOff_Location) == 0) {
             $return_json = json_encode(array('status' => false, 'error_msg' => '9_DropOff. Location 下缺少必填参数'));
             exit($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' => '10_单独使用了DropOff.Location 下的country或city'));
                     exit($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' => '11_PickUp.Date下缺少必填参数'));
             exit($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' => '12_DropOff.Date 下缺少必填参数'));
             exit($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' => '14_DropOff.Date 小于了PickUp.Date'));
                 exit($return_json);
             }
         } else {
             $return_json = json_encode(array('status' => false, 'error_msg' => '13_PickUp.Date或DropOff.Date不是正确的时间'));
             exit($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'] . '"';
         // 拼接XML
         $request_xml = '
                     <SearchRQ>
                         <Credentials username="******" password="******" remoteIp="' . CARRENTALAPI_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, 30, 'POST');
         $simple_xml_obj = simplexml_load_string($searchRQ);
         $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'];
         }
         $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);
             //记录日志
             echo $return_json;
             exit;
         } else {
             $return_json = json_encode(array('status' => false, 'error_msg' => '5_请求超时'));
             ApiLogManage::addRentalcars('SearchRQ', $json_params, $searchRQ, $return_json, $request_time, time(), 10);
             //记录日志
             exit($return_json);
             //请求超时
         }
     } else {
         $return_json = json_encode(array('status' => false, 'error_msg' => '1_JSON参数格式错误'));
         exit($return_json);
     }
 }
Example #3
-1
 public static function CarRentalTapeCompany($updateRedis)
 {
     $request_time = time();
     $Redis = YiiRedis::getInstance();
     $is_updateRedis = true;
     if (!empty($updateRedis)) {
         if ($updateRedis == 'Yes') {
             $is_updateRedis = false;
         }
     }
     if ($Redis->get('CarRentalTapeCompany') && $is_updateRedis) {
         $RS_boss_json = $Redis->get('CarRentalTapeCompany');
     } else {
         $client = new SoapClient(CARRENTALAPI_BOS_URL);
         $bosArr = array();
         $bosArr['AppKey'] = CARRENTALAPI_BOS_APPKEY;
         $bosArr['AppSecrete'] = CARRENTALAPI_BOS_APPSECRETE;
         $bosArr['Request'] = '{}';
         $bos_result = $client->CarRentalTapeCompany(array('requestString' => json_encode($bosArr)));
         if (!empty($bos_result->CarRentalTapeCompanyResult)) {
             $rs_bos_arr = json_decode($bos_result->CarRentalTapeCompanyResult, true);
             if ($rs_bos_arr['ErrorCode'] === 0) {
                 $RS_boss_arr = json_decode($rs_bos_arr['Response']['Response'], true);
                 ApiLogManage::addRentalcars('CarRentalTapeCompany', json_encode($bosArr), '', json_encode($bos_result), $request_time, time(), 1);
                 //记录日志
             }
         }
         if (!empty($rs_bos_arr['ErrorMsg'])) {
             ApiLogManage::addRentalcars('CarRentalTapeCompany', json_encode($bosArr), '', json_encode($bos_result), $request_time, time(), 10);
             //记录日志
             $RS_boss_arr = array();
         }
         $RS_boss_json = json_encode($RS_boss_arr);
         $Redis->set('CarRentalTapeCompany', $RS_boss_json, 60 * 60 * 24 * 7);
     }
     return $RS_boss_json;
 }