Сделать запрос на мыло через php SoapClient - PullRequest
0 голосов
/ 11 апреля 2019

Я должен сделать запрос SOAP, но у меня возникли некоторые проблемы, потому что с помощью SoapClient я не могу получить тот же XML, который предполагается.

Это правильный запрос xml

<soap-env:Envelope xmlns:soap-env="http://schemas.xmlsoap.org/soap/envelope/">
    <soap-env:Header>
        <wsse:Security
            xmlns:wsse="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd">
            <wsse:Username>10983</wsse:Username>
            <wsse:Password>test2019</wsse:Password>
            <Context>10000Hoteis</Context>
        </wsse:Security>
    </soap-env:Header>
    <soap-env:Body>
        <OTA_ReadRQ xmlns:ns="http://www.opentravel.org/OTA/2003/05/common"
            xmlns="http://www.opentravel.org/OTA/2003/05" TimeStamp="2015-07-16T06:38:10.60">
            <ReadRequests>
                <HotelReadRequest>
                    <TPA_Extensions>
                        <RequestType>GetCities</RequestType>
                        <CountryCode>PT</CountryCode>
                    </TPA_Extensions>
                </HotelReadRequest>
            </ReadRequests>
        </OTA_ReadRQ>
    </soap-env:Body>
</soap-env:Envelope>

А это мой текущий php код

 $xmlheader = <<<XML
        <wsse:Security
            xmlns:wsse="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd">
            <wsse:Username>myusername</wsse:Username>
            <wsse:Password>mypassword</wsse:Password>
            <Context>10000Hoteis</Context>
        </wsse:Security>
XML;
$xmlbody = <<<XML

        <OTA_ReadRQ xmlns:ns="http://www.opentravel.org/OTA/2003/05/common"
                xmlns="http://www.opentravel.org/OTA/2003/05" TimeStamp="2015-07-16T06:38:10.60">
                <ReadRequests>
                        <HotelReadRequest>
                                <TPA_Extensions>
                                        <RequestType>GetCities</RequestType>
                                        <CountryCode>PT</CountryCode>
                                </TPA_Extensions>
                        </HotelReadRequest>
                </ReadRequests>
        </OTA_ReadRQ>

XML;
$headerXML = new \SoapVar($xmlheader,XSD_ANYXML);
$body = new \SoapVar($xmlbody,XSD_ANYXML);
$client = new \SoapClient(null, ['location' => 'http://10000hoteis.com.pt/NewAvailabilityServlet/staticdata/OTA2014A', 'uri' =>'http://schemas.xmlsoap.org/soap/envelope/' ,'trace' => true]);

$header = new \SoapHeader('http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd', 'Security', $headerXML);
$client->__setSoapHeaders($header);  
$result = $client->OTA_ReadRQ($body); 

Но это не сработает, потому что поставить дополнительный

<SOAP-ENV:OTA_ReadRQ>

между тегом body и

<OTA_ReadRQ xmlns:ns="http://www.opentravel.org/OTA/2003/05/common"
                xmlns="http://www.opentravel.org/OTA/2003/05" TimeStamp="2015-07-16T06:38:10.60">

Как я могу правильно выполнить этот запрос?

...