使用PHP SoapClient调用FreightQuote API

时间:2019-01-22 11:34:29

标签: php web-services soap-client

我试图使用SoapClient调用FreightQuote API以获取报价。

我收到响应,但这是验证错误。错误类型为“ 未知”,消息为“ 发生一般错误”。

我的代码:

<?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> 

我的XML文件:

<script type="text/javascript">
hotelSelection = function()
{
var hotelName = document.getElementById("myInput").value;
    switch (hotelName) {
  case 'Mare Hotel':
    window.open("liveItMareHotel.html");
    break;
  case 'Hotel 2':
    window.open("liveItHotel2.html");
    break;
  case 'Hotel 3':
    window.open("liveitHotel3.html");
    break;
  case 'Hotel 4':
    window.open("liveItHotel4.html");
    break;
  case 'Hotel 5':
    window.open("liveItHotel5.html");
    break;
    default:
    window.open("liveItDefaultList.html");
}
}
</script>

2 个答案:

答案 0 :(得分:2)

我已解决该问题并将其发布在此处,因此它可以对遇到相同问题的其他人有所帮助。我提到了this个问题,因此选择的答案解决了我的问题。所讨论的代码只需要进行一次修改,$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>

答案 1 :(得分:0)

是不是您缺少<BillCollect>NONE or SITE or SHIPPER or RECEIVER</BillCollect></QuoteShipment>之间的必需</request>?我查看了WSDL,看来这是必需的。