"); $locatorRequestXML = new SimpleXMLElement(""); $accessRequestXML->addChild("AccessLicenseNumber", $accessLicenseNumber); $accessRequestXML->addChild("UserId", $userId); $accessRequestXML->addChild("Password", $password); $request = $locatorRequestXML->addChild('Request'); $request->addChild("RequestAction", "Locator"); $request->addChild("RequestOption", $filter["RequestOption"] ?? self::MBE_UPS_OPTION_DROP_LOCATIONS_AND_WILL_CALL_LOCATIONS ); $translate = $locatorRequestXML->addChild('Translate'); $translate->addChild("LanguageCode", $filter["language"]??'EN'); // if(!empty($filter["LocationID"])) { // $locatorRequestXML->addChild ( "LocationID", $filter["LocationID"]); // } else { $originAddress = $locatorRequestXML->addChild( 'OriginAddress' ); $addressKeyFormat = $originAddress->addChild( 'AddressKeyFormat' ); $addressKeyFormat->addChild( "AddressLine", $filter["AddressLine1"]?:'' ); $addressKeyFormat->addChild( "PostcodePrimaryLow", $filter["PostcodePrimaryLow"]?:''); $addressKeyFormat->addChild( "PoliticalDivision2", $filter["PoliticalDivision2"]?:'' ); $addressKeyFormat->addChild( "PoliticalDivision1", $filter["PoliticalDivision1"]?:'' ); $addressKeyFormat->addChild( "CountryCode", $filter["CountryCode"]?:'' ); $unitOfMeasurement = $locatorRequestXML->addChild( 'UnitOfMeasurement' ); $unitOfMeasurement->addChild( "Code", isset($filter["UnitOfMeasurement"])?$filter["UnitOfMeasurement"]: self::MBE_UPS_UAP_UNIT_OF_MEASUREMENT_KM ); $LocationSearchCriteria = $locatorRequestXML->addChild( 'LocationSearchCriteria' ); $LocationSearchCriteria->addChild( "MaximumListSize", $filter["MaximumListSize"] ?: self::MBE_UPS_UAP_MAXIMUM_LIST_ITEM_10 ); $LocationSearchCriteria->addChild( "SearchRadius", $filter["SearchRadius"] ?: self::MBE_UPS_UAP_SEARCH_RADIUS_20 ); $SortCriteria = $locatorRequestXML->addChild( 'SortCriteria' ); $SortCriteria->addChild( 'SortType', "01" ); // } $requestXML = $accessRequestXML->asXML() . $locatorRequestXML->asXML(); $form = array( 'http' => array( 'method' => 'POST', 'header' => 'Content-type: application/x-www-form-urlencoded', 'content' => "$requestXML" ) ); $request = stream_context_create($form); $browser = fopen($endpointurl, 'rb', false, $request); if (!$browser) { throw new Exception("Connection failed."); } // get response $response = stream_get_contents($browser); fclose($browser); $upsUapList = []; if ( ! $response ) { throw new Exception("getUapList: Response Error."); } else { $xmlResponse = simplexml_load_string($response); unset($response); unset($xmlResponse->Response); $xmlResponse = json_decode(json_encode($xmlResponse), true); if ($simplyfied && !empty($xmlResponse)) { $dropLocation = $xmlResponse['SearchResults']['DropLocation']; if(isset($dropLocation['LocationID']) && isset($dropLocation['AccessPointInformation'])) { $upsUapList[] = self::getUapItem($dropLocation); } else { foreach ( $dropLocation as $item ) { if(isset($item['AccessPointInformation'])) { $upsUapList[] = self::getUapItem($item); } } } return $upsUapList; } return $xmlResponse; } // } catch (Exception $ex) { // return $ex; // } } private static function getUapItem( $item ) { return $item['AddressKeyFormat'] + [ 'LocationID' => $item['LocationID'] ] + [ 'PublicAccesPointID' => $item['AccessPointInformation']['PublicAccessPointID'] ] + [ 'Distance' => $item['Distance']['Value'] . ' ' . $item['Distance']['UnitOfMeasurement']['Code'] ] + [ 'StandardHoursOfOperation' => $item['StandardHoursOfOperation'] ]; } }