duandu1049 2015-06-19 19:41
浏览 134

CURL将xml数据发送到soap服务,在php中返回wsdl XML

I am trying get response using curl request. soap service is running fine with soap-client. But using Curl I am not getting proper response.

Here is my Code sample:

$bookingRQ = '<?xml version="1.0" encoding="UTF-8"?>
<soap-env:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap-env="http://schemas.xmlsoap.org/soap/envelope/">
    <soap-env:Header>
        <Interface xmlns="http://api.hotels-vacation.com/Documentation/XML/OTA/4/2011B/" ChannelIdentifierId="HIS_VACATION_XML4H" Version="2011B" Interface="VACATION QUICK CONNECT XML 4 OTA">
            <ComponentInfo User="XMLHISJP" Pwd="5Kh86RSr" ComponentType="Hotel" />
        </Interface>
    </soap-env:Header>
    <soap-env:Body RequestId="201505101528000000001" Transaction="OTA_HotelResRQ">
        <OTA_HotelResRQ xmlns="http://www.opentravel.org/OTA/2003/05" TimeStamp="2012-05-03T15:47:24-04:00" EchoToken="2012-05-03T15:47:24-04:00" Target="Production" Version="1.000" PrimaryLangID="en">
            <HotelReservations>
                <HotelReservation RoomStayReservation="true" CreateDateTime="2012-05-03T15:47:24-04:00">
                    <UniqueID Type="14" ID="HZ10014035" />
                    <RoomStays>
                        <RoomStay>
                            <RoomTypes>
                                <RoomType RoomTypeCode="RR" />
                            </RoomTypes>
                            <RatePlans>
                                <RatePlan RatePlanCode="RPLN">
                                    <MealsIncluded MealPlanCodes="BRE" />
                                </RatePlan>
                            </RatePlans>
                            <RoomRates>
                                <RoomRate NumberOfUnits="1" EffectiveDate="2012-05-13" ExpireDate="2012-05-16" RoomTypeCode="RR" RatePlanCode="RPLN">
                                    <Rates>
                                        <Rate EffectiveDate="2012-05-13" ExpireDate="2012-05-14" RateTimeUnit="Day">
                                            <Base AmountBeforeTax="10000" AmountAfterTax="10980" DecimalPlaces="2" CurrencyCode="USD" />
                                            <Total AmountBeforeTax="10000" AmountAfterTax="10980" DecimalPlaces="2" CurrencyCode="USD" />
                                        </Rate>
                                        <Rate EffectiveDate="2012-05-14" ExpireDate="2012-05-16" RateTimeUnit="Day">
                                            <Base AmountBeforeTax="12000" AmountAfterTax="13050" DecimalPlaces="2" CurrencyCode="USD" />
                                            <Total AmountBeforeTax="24000" AmountAfterTax="26100" DecimalPlaces="2" CurrencyCode="USD" />
                                        </Rate>
                                    </Rates>
                                </RoomRate>
                            </RoomRates>
                            <GuestCounts>
                                <GuestCount AgeQualifyingCode="10" Count="1" />
                                <GuestCount AgeQualifyingCode="8" Count="1" />
                            </GuestCounts>
                            <TimeSpan Start="2012-05-13" End="2012-05-16" />
                            <DepositPayments>
                                <RequiredPayment>
                                    <AcceptedPayments>
                                        <AcceptedPayment RPH="1">
                                            <PaymentCard CardType="1" CardCode="VISA" CardNumber="4321432143214327" ExpireDate="1007" />
                                        </AcceptedPayment>
                                    </AcceptedPayments>
                                    <AmountPercent Amount="130.80" />
                                    <Deadline AbsoluteDeadline="2012-12-15" />
                                </RequiredPayment>
                            </DepositPayments>
                            <BasicPropertyInfo HotelCode="105487" />
                            <ResGuestRPHs>
                                <ResGuestRPH RPH="1" />
                                <ResGuestRPH RPH="2" />
                            </ResGuestRPHs>
                            <SpecialRequests>
                                <SpecialRequest Language="en" RequestCode="114">
                                    <Text Language="en">Honeymoon</Text>
                                </SpecialRequest>
                                <SpecialRequest Language="en" RequestCode="21">
                                    <Text Language="en">Non-Smoking</Text>
                                </SpecialRequest>
                            </SpecialRequests>
                        </RoomStay>
                    </RoomStays>
                    <ResGuests>
                        <ResGuest ResGuestRPH="1" AgeQualifyingCode="10" Age="21">
                            <Profiles>
                                <ProfileInfo>
                                    <Profile ProfileType="1">
                                        <Customer>
                                            <PersonName>
                                                <GivenName>John</GivenName>
                                                <Surname>Dow</Surname>
                                            </PersonName>
                                        </Customer>
                                    </Profile>
                                </ProfileInfo>
                            </Profiles>
                        </ResGuest>
                        <ResGuest ResGuestRPH="2" AgeQualifyingCode="8" age="10">
                            <Profiles>
                                <ProfileInfo>
                                    <Profile ProfileType="1">
                                        <Customer>
                                            <PersonName>
                                                <GivenName>Neil</GivenName>
                                                <Surname>Dow</Surname>
                                            </PersonName>
                                        </Customer>
                                    </Profile>
                                </ProfileInfo>
                            </Profiles>
                        </ResGuest>
                    </ResGuests>
                </HotelReservation>
            </HotelReservations>
        </OTA_HotelResRQ>
    </soap-env:Body>
</soap-env:Envelope>';

$headers = array(
"Cache-Control: no-cache",
"Content-type: text/xml; charset=\"utf-8\"",
"Accept: text/xml",
"SOAPAction: \"OTA_HotelResRQ\"",
"Pragma: no-cache",
"Content-length: ".strlen($bookingRQ)
);


$url = 'http://chetu.volateam.com/chetu/push/soapserver/PullService.php?wsdl';
$ch = curl_init(); 
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_URL, $url); 
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); 
curl_setopt($ch, CURLOPT_TIMEOUT, 60); 
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);

curl_setopt($ch, CURLOPT_POST, true); 
curl_setopt($ch, CURLOPT_POSTFIELDS, $bookingRQ); 


$result = curl_exec($ch);

$xmlstring = str_replace('soap-env:', '', $result);
$xml = simplexml_load_string($xmlstring);
$json = json_encode($xml);
$array = json_decode($json,TRUE);

I am getting wsdl XML code as response. I google it but I did not find any solution. I am getting the response as below mentioned array.

Array ( [@attributes] => Array ( [name] => PullServiceHIS [targetNamespace] => http://chetu.volateam.com/chetu/push/soapserver/PullService.php )

[types] => Array
    (
    )

[portType] => Array
    (
        [@attributes] => Array
            (
                [name] => PullServiceHISPort
            )

        [operation] => Array
            (
                [@attributes] => Array
                    (
                        [name] => OTA_HotelResRQ
                    )

                [documentation] => This method takes XML request and return a string response
                [input] => Array
                    (
                        [@attributes] => Array
                            (
                                [message] => tns:OTA_HotelResRQIn
                            )

                    )

                [output] => Array
                    (
                        [@attributes] => Array
                            (
                                [message] => tns:OTA_HotelResRQOut
                            )

                    )

            )

    )

[binding] => Array
    (
        [@attributes] => Array
            (
                [name] => PullServiceHISBinding
                [type] => tns:PullServiceHISPort
            )

        [operation] => Array
            (
                [@attributes] => Array
                    (
                        [name] => OTA_HotelResRQ
                    )

                [input] => Array
                    (
                    )

                [output] => Array
                    (
                    )

            )

    )

[service] => Array
    (
        [@attributes] => Array
            (
                [name] => PullServiceHISService
            )

        [port] => Array
            (
                [@attributes] => Array
                    (
                        [name] => PullServiceHISPort
                        [binding] => tns:PullServiceHISBinding
                    )

            )

    )

[message] => Array
    (
        [0] => Array
            (
                [@attributes] => Array
                    (
                        [name] => OTA_HotelResRQIn
                    )

                [0] => Array
                    (
                        [@attributes] => Array
                            (
                                [name] => bookingRQ
                                [type] => xsd:string
                            )

                    )

            )

        [1] => Array
            (
                [@attributes] => Array
                    (
                        [name] => OTA_HotelResRQOut
                    )

                [part] => Array
                    (
                        [@attributes] => Array
                            (
                                [name] => return
                                [type] => xsd:string
                            )

                    )

            )

    )

)

  • 写回答

1条回答

  • dqfwcj0030 2015-06-23 21:51
    关注

    I would advise you to use the Native PHP SoapClient class. The easiest way then is to use a WSDL to php generator that will help you modelize the structures to be sent as the request.

    You must also know that OTA can be complex to call and requires a really good understanding of the rquest structure.

    Take a look at https://www.wsdltophp.com

    评论

报告相同问题?

悬赏问题

  • ¥15 YoloV5 第三方库的版本对照问题
  • ¥15 请完成下列相关问题!
  • ¥15 drone 推送镜像时候 purge: true 推送完毕后没有删除对应的镜像,手动拷贝到服务器执行结果正确在样才能让指令自动执行成功删除对应镜像,如何解决?
  • ¥15 求daily translation(DT)偏差订正方法的代码
  • ¥15 js调用html页面需要隐藏某个按钮
  • ¥15 ads仿真结果在圆图上是怎么读数的
  • ¥20 Cotex M3的调试和程序执行方式是什么样的?
  • ¥20 java项目连接sqlserver时报ssl相关错误
  • ¥15 一道python难题3
  • ¥15 牛顿斯科特系数表表示