如何用PHP编写SOAP XML Web服务

时间:2016-05-22 03:57:43

标签: php xml web-services soap

我是PHP的SOAP API Web服务的新手,我必须接受XML输入并以XML格式返回。请提出一些代码示例。其实我正在为我的酒店做渠道经理。

输入XML ...

<ns3:OTA_HotelResNotifRQ ResStatus="Commit" EchoToken="dsh0a"
xmlns:ns2="http://www.example.com/hotels/channelmgr/"
xmlns:ns3="http://www.example.org/OTA/2003/05/beta">
 <ns3:POS>
 <ns3:Source>
 <ns3:BookingChannel>
 <ns3:CompanyName CompanyShortName="MMYT" Code="MMYT"
CountryCode="IN">Make My Trip</ns3:CompanyName>
 </ns3:BookingChannel>
 </ns3:Source>
 </ns3:POS>
 <ns3:HotelReservations>
 <ns3:HotelReservation ResStatus="Commit" CreateDateTime="2014-05-19">
 <ns3:UniqueID ID="AB123456789012"/>
 <ns3:RoomStays>
 <ns3:RoomStay>
 <ns3:RoomTypes>
 <ns3:RoomType NumberOfUnits="1" RoomTypeCode="Float"/>
 </ns3:RoomTypes>
 <ns3:RatePlans>
 <ns3:RatePlan>
Make My Trip CONFIDENTIAL 7
 <ns3:MealsIncluded MealPlanCodes="CP"/>
 </ns3:RatePlan>
 </ns3:RatePlans>
 <ns3:RoomRates>
 <ns3:RoomRate EffectiveDate="2014-05-20" ExpireDate="2014-05-21"
RatePlanCode="1234567891234"/>
 <ns3:RoomRate EffectiveDate="2014-05-21" ExpireDate="2014-05-22"
RatePlanCode="98765437291739"/>
 </ns3:RoomRates>
 </ns3:RoomStay>
 <ns3:RoomStay>
 <ns3:RoomTypes>
 <ns3:RoomType NumberOfUnits="1" RoomTypeCode="Float"/>
 </ns3:RoomTypes>
 <ns3:RatePlans>
 <ns3:RatePlan>
 <ns3:MealsIncluded MealPlanCodes="CP"/>
 </ns3:RatePlan>
 </ns3:RatePlans>
 <ns3:RoomRates>
 <ns3:RoomRate EffectiveDate="2014-05-20" ExpireDate="2014-05-21"
RatePlanCode="1234567891234"/>

Make My Trip CONFIDENTIAL 8
<ns3:RoomRate EffectiveDate="2014-05-21" ExpireDate="2014-05-22"
RatePlanCode="98765437291739"/>
 </ns3:RoomRates>
 </ns3:RoomStay>
 <ns3:RoomStay>
 <ns3:RoomTypes>
 <ns3:RoomType NumberOfUnits="1" RoomTypeCode="Float"/>
 </ns3:RoomTypes>
 <ns3:RatePlans>
 <ns3:RatePlan>
 <ns3:MealsIncluded MealPlanCodes="CP"/>
 </ns3:RatePlan>
 </ns3:RatePlans>
 <ns3:RoomRates>
 <ns3:RoomRate EffectiveDate="2014-05-20" ExpireDate="2014-05-21"
RatePlanCode="1234567891234"/>
 <ns3:RoomRate EffectiveDate="2014-05-21" ExpireDate="2014-05-22"
RatePlanCode="98765437291739"/>
 </ns3:RoomRates>
 </ns3:RoomStay>
 </ns3:RoomStays>
 <ns3:Services>
 <ns3:Service>
 <ns3:Price>
Make My Trip CONFIDENTIAL 9
 <ns3:AdditionalGuestAmounts AmountBeforeTax="362.00"
CurrencyCode="INR" DecimalPlaces="2"/>
<ns3:Total AmountAfterTax="4249.98" CurrencyCode="INR"
DecimalPlaces="2">
 <ns3:Taxes>
 <ns3:Tax Amount="947.98" CurrencyCode="INR" DecimalPlaces="2">
 <ns3:TaxDescription Name="Hotelier Tax"/>
 </ns3:Tax>
 <ns3:Tax Amount="126.00" CurrencyCode="INR" DecimalPlaces="2">
 <ns3:TaxDescription Name="TDS"/>
 </ns3:Tax>
 </ns3:Taxes>
 </ns3:Total>
 </ns3:Price>
 <ns3:ServiceDetails>
 <ns3:GuestCounts>
 <ns3:GuestCount AgeQualifyingCode="10" Count="6"/>
 <ns3:GuestCount AgeQualifyingCode="8" Count="2"/>
 </ns3:GuestCounts>
 </ns3:ServiceDetails>
 </ns3:Service>
 </ns3:Services>
 <ns3:ResGuests>
 <ns3:ResGuest PrimaryIndicator="true">
Make My Trip CONFIDENTIAL 10
 <ns3:Profiles>
 <ns3:ProfileInfo>
 <ns3:Profile>
 <ns3:Customer>
 <ns3:PersonName>
 <ns3:GivenName>Test</ns3:GivenName>
 </ns3:PersonName>
 </ns3:Customer>
 </ns3:Profile>
 </ns3:ProfileInfo>
 </ns3:Profiles>
 </ns3:ResGuest>
 </ns3:ResGuests>
 <ns3:ResGlobalInfo>
 <ns3:TimeSpan Start="2014-05-20" End="2014-05-22"/>
 <ns3:CancelPenalties>
 <ns3:CancelPenalty>
 <ns3:PenaltyDescription>
 <ns3:Text># More than 2 days before check-in date: FREE CANCELLATION; 2
days before check-in date: 1 night cost will be charged as
cancellation fee; In case of no show: no refund; An additional
MakeMyTrip service charge of INR 250 will apply
</ns3:Text>
 </ns3:PenaltyDescription>
Make My Trip CONFIDENTIAL 11
 </ns3:CancelPenalty>
 </ns3:CancelPenalties>
 <ns3:HotelReservationIDs>
 <ns3:HotelReservationID ResID_Type="14" ResID_Value="AB123456789012"
ResID_Date="2014-05-19"/>
 </ns3:HotelReservationIDs>
 <ns3:BasicPropertyInfo HotelCode="987654321987654321" HotelName="The
test test"/>
 </ns3:ResGlobalInfo>
 </ns3:HotelReservation>
 </ns3:HotelReservations>
 </ns3:OTA_HotelResNotifRQ>

输出XML ...

<OTA_HotelResNotifRS
xmlns="http://www.opentravel.org/OTA/2003/05/beta" Version="1.0"
TimeStamp="2012-04-27T10:56:34" EchoToken="UUicg">
<Success />
 <HotelReservations>
 <HotelReservation>
 <UniqueID Type="14" ID="AB123456789" />
 <ResGlobalInfo>
 <HotelReservationIDs>
 <HotelReservationID ResID_Type="14"
ResID_Value=" YourConfirmationNo " />
 </HotelReservationIDs>
 </ResGlobalInfo>
 </HotelReservation>
 </HotelReservations>
</OTA_HotelResNotifRS>

0 个答案:

没有答案