Вызов API FreightQuote с использованием PHP SoapClient - PullRequest
0 голосов
/ 22 января 2019

Я пытаюсь вызвать FreightQuote API, используя SoapClient для получения котировки.

Я получаю ответ, но это ошибка проверки.Тип ошибки: « Неизвестно » и сообщение « Произошла общая ошибка ».

Мой код:

$apiHostPath = "https://b2b.Freightquote.com/WebService/QuoteService.asmx?wsdl";
$AuthClient = new SoapClient($apiHostPath); 
$xmlString = file_get_contents("temp.xml");
$soapBody = new SoapVar($xmlString, XSD_ANYXML);
$result = $AuthClient->GetRatingEngineQuote(array($soapBody));
echo get_class($result);
print_r($result);

Мой файл XML:

<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:xsd="http://www.w3.org/2001/XMLSchema">
 <soap:Body>
 <GetRatingEngineQuote xmlns="http://tempuri.org/">
 <request>
 <CustomerId>customerid</CustomerId>
 <QuoteType>B2B</QuoteType>
 <ServiceType>LTL</ServiceType>
 <QuoteShipment>
 <IsBlind>false</IsBlind>
 <PickupDate>2019-02-17T00:00:00</PickupDate>
 <SortAndSegregate>false</SortAndSegregate>
 <UseStackableFlag>false</UseStackableFlag>
 <DeclaredValue>20</DeclaredValue>
 <MaxPickupDate />
 <TLDeliveryDate />
 <TLEquipmentType>Any</TLEquipmentType>
 <TLEquipmentSize>Any</TLEquipmentSize>
 <TLTarpSizeType>NoTarpRequired</TLTarpSizeType>
 <ShipmentLocations>
 <Location>
 <LocationType>Origin</LocationType>
 <HasLoadingDock>false</HasLoadingDock>
 <IsConstructionSite>false</IsConstructionSite> 
 <RequiresInsideDelivery>false</RequiresInsideDelivery>
 <IsTradeShow>false</IsTradeShow>
 <TradeShow>TradeShowDesc</TradeShow>
 <IsResidential>false</IsResidential>
 <RequiresLiftgate>false</RequiresLiftgate>
 <HasAppointment>false</HasAppointment>
 <IsLimitedAccess>false</IsLimitedAccess>
 <LocationAddress>
 <PostalCode>60632</PostalCode>
 <CountryCode>US</CountryCode>
 </LocationAddress>
 <AdditionalServices />
 </Location>
 <Location>
 <LocationType>Destination</LocationType>
 <HasLoadingDock>false</HasLoadingDock>
 <IsConstructionSite>false</IsConstructionSite>
 <RequiresInsideDelivery>false</RequiresInsideDelivery>
 <IsTradeShow>false</IsTradeShow>
 <TradeShow>TradeShowDesc</TradeShow>
 <IsResidential>false</IsResidential>
 <RequiresLiftgate>false</RequiresLiftgate>
 <HasAppointment>false</HasAppointment>
 <IsLimitedAccess>false</IsLimitedAccess>
 <LocationAddress>
 <PostalCode>44113</PostalCode>
 <CountryCode>US</CountryCode>
 </LocationAddress>
 <AdditionalServices />
 </Location>
 </ShipmentLocations>
 <ShipmentProducts>
 <Product>
 <Class>55</Class>
 <Weight>1200</Weight>
 <Length>0</Length>
 <Width>0</Width>
 <Height>0</Height>
 <ProductDescription>Books</ProductDescription>
 <PackageType>Pallets_48x48</PackageType>
 <IsStackable>false</IsStackable>
 <DeclaredValue>0</DeclaredValue>
 <CommodityType>GeneralMerchandise</CommodityType>
 <ContentType>NewCommercialGoods</ContentType>
 <IsHazardousMaterial>false</IsHazardousMaterial>
 <NMFC />
 <DimWeight>0</DimWeight>
 <EstimatedWeight>0</EstimatedWeight>
 <PieceCount>5</PieceCount>
 <ItemNumber>0</ItemNumber>
 <ProductDrops />
 </Product>
 </ShipmentProducts>
 <ShipmentContacts />
 </QuoteShipment>
 </request>
 <user>
 <Name>****</Name>
 <Password>****</Password> 
 <CredentialType>Default</CredentialType>
 </user>
 </GetRatingEngineQuote>
 </soap:Body>
</soap:Envelope> 

Ответы [ 2 ]

0 голосов
/ 31 января 2019

Я решил это и разместил здесь, чтобы он мог быть полезен другим с такой же проблемой.Я передаю этот вопрос, и выбранный ответ решил мою проблему.Код, написанный в вопросе, нуждается только в одной модификации, переменная $soapBody была ранее передана в массиве, который должен был быть передан непосредственно без массива.Правильная строка показана ниже:

$result = $AuthClient->GetRatingEngineQuote($soapBody);

XML-файл читается и передается в виде XML-строки, поэтому его нужно начинать с фактического тела, как показано ниже:

<GetRatingEngineQuote xmlns="http://tempuri.org/">
        <request>
                <CustomerId>customerid</CustomerId>
                <QuoteType>B2B</QuoteType>
                <ServiceType>LTL</ServiceType>
                <QuoteShipment>
                        <IsBlind>false</IsBlind>
                        <PickupDate>2019-02-13T14:12:48</PickupDate>
                        <SortAndSegregate>false</SortAndSegregate>
                        <ShipmentLocations>
                                <Location>
                                        <LocationName>Location</LocationName>
                                        <LocationType>Origin</LocationType>
                                        <HasLoadingDock>false</HasLoadingDock>
                                        <IsConstructionSite>false</IsConstructionSite>
                                        <IsResidential>false</IsResidential>
                                        <RequiresInsideDelivery>false</RequiresInsideDelivery>
                                        <IsTradeShow>false</IsTradeShow>
                                        <RequiresLiftgate>false</RequiresLiftgate>
                                        <HasAppointment>false</HasAppointment>
                                        <IsLimitedAccess>false</IsLimitedAccess>
                                        <ContactName>testuser</ContactName>
                                        <ContactPhone>5551237777</ContactPhone>
                                        <ContactEmail>XXXXX</ContactEmail>
                                        <LocationAddress>
                                                <AddressName>Address 1</AddressName>
                                                <StreetAddress>123 Main</StreetAddress>
                                                <City>Ohio</City>
                                                <StateCode>OH</StateCode>
                                                <PostalCode>30303</PostalCode>
                                                <CountryCode>US</CountryCode>
                                        </LocationAddress>
                                </Location>
                                <Location>
                                        <LocationName>Location name</LocationName>
                                        <LocationType>Destination</LocationType>
                                        <HasLoadingDock>false</HasLoadingDock>
                                        <IsConstructionSite>false</IsConstructionSite>
                                        <IsResidential>false</IsResidential>
                                        <RequiresInsideDelivery>false</RequiresInsideDelivery>
                                        <IsTradeShow>false</IsTradeShow>
                                        <RequiresLiftgate>false</RequiresLiftgate>
                                        <HasAppointment>false</HasAppointment>
                                        <IsLimitedAccess>false</IsLimitedAccess>
                                        <ContactName>Somename</ContactName>
                                        <ContactPhone>33333333</ContactPhone>
                                        <ContactEmail>abc@gmail.com</ContactEmail>
                                        <LocationAddress>
                                                <AddressName>Address 2</AddressName>
                                                <StreetAddress>123 Main</StreetAddress>
                                                <City>Atlanta</City>
                                                <StateCode>GA</StateCode>
                                                <PostalCode>60606</PostalCode>
                                                <CountryCode>US</CountryCode>
                                        </LocationAddress>
                                </Location>
                        </ShipmentLocations>
                        <ShipmentProducts>
                                <Product>
                                        <Class>400</Class>
                                        <Weight>200</Weight>
                                        <Length>50</Length>
                                        <Width>48</Width>
                                        <Height>36</Height>
                                        <ProductDescription>Books</ProductDescription>
                                        <PackageType>Pallets_48x48</PackageType>
                                        <IsStackable>false</IsStackable>
                                        <DeclaredValue>0</DeclaredValue>
                                        <CommodityType>Metals</CommodityType>
                                        <ContentType>NewCommercialGoods</ContentType>
                                        <IsHazardousMaterial>false</IsHazardousMaterial>
                                        <DimWeight>0</DimWeight>
                                        <EstimatedWeight>0</EstimatedWeight>
                                        <PieceCount>1</PieceCount>
                                        <ItemNumber>0</ItemNumber>
                                </Product>
                        </ShipmentProducts>
                </QuoteShipment>
        </request>
        <user>
                <Name>somename</Name>
                <Password>somepassword</Password>
                <CredentialType>Default</CredentialType>
        </user>
</GetRatingEngineQuote>
0 голосов
/ 29 января 2019

Может быть, вам не хватает требуемого <BillCollect>NONE or SITE or SHIPPER or RECEIVER</BillCollect> между </QuoteShipment> и </request>? Я посмотрел на WSDL, и кажется, что это требуется.

...