dongxin2734 2016-11-14 17:34
浏览 103
已采纳

如何在PHP SoapClient()中重复对象0次或更多次?

I'm using something called Radixx ConnectPoint (SOAP) and I have run into a slight snag with how to go about requesting information correctly. Apologies if this is obvious; I am very new to SOAP.

For testing purposes I have this XML example that the API developer sent me to model my request after:

POST http://xxx.connectpoint.uat.radixx.com/ConnectPoint.Pricing.svc HTTP/1.0
Accept-Encoding: gzip,deflate
Content-Type: text/xml;charset=UTF-8
SOAPAction: "http://tempuri.org/IConnectPoint_Pricing/RetrieveFareQuote"
Content-Length: 4076
Host: xxx.connectpoint.uat.radixx.com
Connection: Keep-Alive
User-Agent: Apache-HttpClient/4.5.2 (Java/1.8.0_77)

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:tem="http://tempuri.org/" xmlns:rad="http://schemas.datacontract.org/2004/07/Radixx.ConnectPoint.Request" xmlns:rad1="http://schemas.datacontract.org/2004/07/Radixx.ConnectPoint.Pricing.Request.FareQuote">
   <soapenv:Header/>
   <soapenv:Body>
      <tem:RetrieveFareQuote>
         <!--Optional:-->
         <tem:RetrieveFareQuoteRequest>
            <rad:SecurityGUID>7fa327412a4a47hbu39fi87erfk0tan5ra580cd0a08e</rad:SecurityGUID>
            <rad:CarrierCodes>
               <!--Zero or more repetitions:-->
               <rad:CarrierCode><rad:AccessibleCarrierCode>xxx</rad:AccessibleCarrierCode></rad:CarrierCode>
            </rad:CarrierCodes>
            <!--Optional:-->
            <rad:ClientIPAddress>?</rad:ClientIPAddress>
            <!--Optional:-->
            <rad:HistoricUserName>?</rad:HistoricUserName>
            <rad1:CurrencyOfFareQuote>USD</rad1:CurrencyOfFareQuote>
            <rad1:PromotionalCode></rad1:PromotionalCode>
            <rad1:IataNumberOfRequestor></rad1:IataNumberOfRequestor>
            <rad1:CorporationID>-214</rad1:CorporationID>
            <rad1:FareFilterMethod>NoCombinabilityRoundtripLowestFarePerFareType</rad1:FareFilterMethod>
            <rad1:FareGroupMethod>WebFareTypes</rad1:FareGroupMethod>
            <rad1:InventoryFilterMethod>Available</rad1:InventoryFilterMethod>
            <rad1:FareQuoteDetails>
               <!--Zero or more repetitions:-->
               <rad1:FareQuoteDetail>
                  <rad1:Origin>BRL</rad1:Origin>
                  <rad1:Destination>ORD</rad1:Destination>
                  <rad1:UseAirportsNotMetroGroups>false</rad1:UseAirportsNotMetroGroups>
                  <!--Optional:-->
                  <rad1:UseAirportsNotMetroGroupsAsRule>false</rad1:UseAirportsNotMetroGroupsAsRule>
                  <!--Optional:-->
                  <rad1:UseAirportsNotMetroGroupsForFrom>false</rad1:UseAirportsNotMetroGroupsForFrom>
                  <!--Optional:-->
                  <rad1:UseAirportsNotMetroGroupsForTo>false</rad1:UseAirportsNotMetroGroupsForTo>
                  <rad1:DateOfDeparture>2016-11-20</rad1:DateOfDeparture>
                  <rad1:FareTypeCategory>1</rad1:FareTypeCategory>
                  <rad1:FareClass></rad1:FareClass>
                  <rad1:FareBasisCode></rad1:FareBasisCode>
                  <rad1:Cabin></rad1:Cabin>
                  <rad1:LFID>-214</rad1:LFID>
                  <rad1:OperatingCarrierCode></rad1:OperatingCarrierCode>
                  <rad1:MarketingCarrierCode></rad1:MarketingCarrierCode>
                  <rad1:NumberOfDaysBefore>0</rad1:NumberOfDaysBefore>
                  <rad1:NumberOfDaysAfter>0</rad1:NumberOfDaysAfter>
                  <rad1:LanguageCode>en</rad1:LanguageCode>
                  <rad1:TicketPackageID>1</rad1:TicketPackageID>
                  <rad1:FareQuoteRequestInfos>
                     <!--Zero or more repetitions:-->
                     <rad1:FareQuoteRequestInfo>
                        <rad1:PassengerTypeID>1</rad1:PassengerTypeID>
                        <rad1:TotalSeatsRequired>1</rad1:TotalSeatsRequired>
                     </rad1:FareQuoteRequestInfo>

                                          <rad1:FareQuoteRequestInfo>
                        <rad1:PassengerTypeID>5</rad1:PassengerTypeID>
                        <rad1:TotalSeatsRequired>1</rad1:TotalSeatsRequired>
                     </rad1:FareQuoteRequestInfo>

                                          <rad1:FareQuoteRequestInfo>
                        <rad1:PassengerTypeID>6</rad1:PassengerTypeID>
                        <rad1:TotalSeatsRequired>1</rad1:TotalSeatsRequired>
                     </rad1:FareQuoteRequestInfo>
                  </rad1:FareQuoteRequestInfos>
                  <!--Optional:-->

               </rad1:FareQuoteDetail>
            </rad1:FareQuoteDetails>
         </tem:RetrieveFareQuoteRequest>
      </tem:RetrieveFareQuote>
   </soapenv:Body>
</soapenv:Envelope>

I have removed the identifying carrier codes and replaced them with xxx. The GUID security code is not valid anymore so I have left it in.

$data->CurrencyOfFareQuote = "USD";
$data->CorporationID = -214;
$data->FareFilterMethod = "NoCombinabilityRoundtripLowestFarePerFareType";
$data->FareGroupMethod = "WebFareTypes";
$data->InventoryFilterMethod = "Available";
$data->ClientIPAddress = "?"; // Optional
$data->HistoricUserName = "?"; // Optional
$data->PromotionalCode = null;
$data->IataNumberOfRequestor = null;
$data->FareQuoteDetails->FareQuoteDetail->Origin = "BRL";
$data->FareQuoteDetails->FareQuoteDetail->Destination = "ORD";
$data->FareQuoteDetails->FareQuoteDetail->UseAirportsNotMetroGroups = false;
$data->FareQuoteDetails->FareQuoteDetail->UseAirportsNotMetroGroupsAsRule = false;
$data->FareQuoteDetails->FareQuoteDetail->UseAirportsNotMetroGroupsForForm = false;
$data->FareQuoteDetails->FareQuoteDetail->UseAirportsNotMetroGroupsForTo = false;
$data->FareQuoteDetails->FareQuoteDetail->DateOfDeparture = "2016-11-20";
$data->FareQuoteDetails->FareQuoteDetail->FareTypeCategory = 1;
$data->FareQuoteDetails->FareQuoteDetail->FareClass = null;
$data->FareQuoteDetails->FareQuoteDetail->FareBasisCode = null;
$data->FareQuoteDetails->FareQuoteDetail->Cabin = null;
$data->FareQuoteDetails->FareQuoteDetail->LFID = -214;
$data->FareQuoteDetails->FareQuoteDetail->OperatingCarrierCode = null;
$data->FareQuoteDetails->FareQuoteDetail->MarketingCarrierCode = null;
$data->FareQuoteDetails->FareQuoteDetail->NumberOfDaysBefore = 0;
$data->FareQuoteDetails->FareQuoteDetail->NumberOfDaysAfter = 0;
$data->FareQuoteDetails->FareQuoteDetail->LanguageCode = "en";
$data->FareQuoteDetails->FareQuoteDetail->TicketPackageID = 1;

$quote = $pricing->RetrieveFareQuote(array("RetrieveFareQuoteRequest" => $data));
print_r($quote);

Once I ran a print_r I saw that I forgot to add the FareQuoteRequestInfos object, but after looking at the XML I am unsure how to add it in. From the XML, it looks like I also have to do the same thing to the FareQuoteDetail object, as it needs to be able to repeat.

How would I do such a thing? Do I add them as arrays?

For reference, here is the print_r result:

stdClass Object
(
    [RetrieveFareQuoteResult] => stdClass Object
        (
            [CommissionIncluded] => 
            [Exceptions] => stdClass Object
                (
                    [ExceptionInformation.Exception] => stdClass Object
                        (
                            [ExceptionCode] => 9989
                            [ExceptionDescription] => RetrieveFareQuote/FareQuoteDetails[0]/FareQuoteRequestInfos: cannot be NULL and collection count must be between 1 and 20
                            [ExceptionSource] => RetrieveFareQuote
                            [ExceptionLevel] => Critical
                        )

                )

            [FlightSegments] => stdClass Object
                (
                )

            [LegDetails] => stdClass Object
                (
                )

            [RequestedCorporationID] => 0
            [RequestedCurrencyOfFareQuote] => 
            [RequestedFareFilterMethod] => 0
            [RequestedGroupMethod] => 0
            [RequestedIataNumber] => 
            [RequestedInventoryFilterMethod] => 0
            [RequestedPromotionalCode] => 
            [RequestedReservationChannel] => 0
            [SegmentDetails] => stdClass Object
                (
                )

            [TaxDetails] => stdClass Object
                (
                )

        )

)

Any help or tips would be greatly appreciated! Thanks!

  • 写回答

1条回答 默认 最新

  • dougang5993 2016-11-14 18:53
    关注

    Figured this out myself and decided to share:

    $info = new StdClass;
    $info->Origin = "BRL";
    $info->Destination = "ORD";
    $info->UseAirportsNotMetroGroups = false;
    $info->UseAirportsNotMetroGroupsAsRule = false;
    $info->UseAirportsNotMetroGroupsForForm = false;
    $info->UseAirportsNotMetroGroupsForTo = false;
    $info->DateOfDeparture = "2016-11-20";
    $info->FareTypeCategory = 1;
    $info->FareClass = null;
    $info->FareBasisCode = null;
    $info->Cabin = null;
    $info->LFID = -214;
    $info->OperatingCarrierCode = null;
    $info->MarketingCarrierCode = null;
    $info->NumberOfDaysBefore = 0;
    $info->NumberOfDaysAfter = 0;
    $info->LanguageCode = "en";
    $info->TicketPackageID = 1;
    $info->FareQuoteRequestInfos->FareQuoteRequestInfo[] = array(
        'PassengerTypeID' => 1,
        'TotalSeatsRequired' => 1
    );
    $info->FareQuoteRequestInfos->FareQuoteRequestInfo[] = array(
        'PassengerTypeID' => 5,
        'TotalSeatsRequired' => 1
    );
    $info->FareQuoteRequestInfos->FareQuoteRequestInfo[] = array(
        'PassengerTypeID' => 6,
        'TotalSeatsRequired' => 1
    );
    
    $detail = new StdClass;
    $detail->FareQuoteDetail = $info;
    
    $data->CurrencyOfFareQuote = "USD";
    $data->CorporationID = -214;
    $data->FareFilterMethod = "NoCombinabilityRoundtripLowestFarePerFareType";
    $data->FareGroupMethod = "WebFareTypes";
    $data->InventoryFilterMethod = "Available";
    $data->ClientIPAddress = "?"; // Optional
    $data->HistoricUserName = "?"; // Optional
    $data->PromotionalCode = null;
    $data->IataNumberOfRequestor = null;
    $data->FareQuoteDetails = $detail;
    
    $quote = $pricing->RetrieveFareQuote(array("RetrieveFareQuoteRequest" => $data));
    
    print_r($quote);
    

    I moved the FareQuoteDetail into a separate class object and then added each FareQuoteRequestInfo as an array, which let me keep the same naming structure.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥20 机器学习能否像多层线性模型一样处理嵌套数据
  • ¥20 西门子S7-Graph,S7-300,梯形图
  • ¥50 用易语言http 访问不了网页
  • ¥50 safari浏览器fetch提交数据后数据丢失问题
  • ¥15 matlab不知道怎么改,求解答!!
  • ¥15 永磁直线电机的电流环pi调不出来
  • ¥15 用stata实现聚类的代码
  • ¥15 请问paddlehub能支持移动端开发吗?在Android studio上该如何部署?
  • ¥20 docker里部署springboot项目,访问不到扬声器
  • ¥15 netty整合springboot之后自动重连失效