Не удается извлечь данные из ответа SOAP

1

Я работал над SOAP-запросом/ответом, используя CURL с PHP, однако я не могу понять, как извлечь данные для жизни меня.

Скрипт для запроса SOAP

$soapUrl        = "https://xml.proveid.experian.com/IDSearch.cfc?wdsl";     

// xml post structure

    $xml_post_string = "<?xml version='1.0' encoding='utf-8'?>
                        <soapenv:Envelope xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance' xmlns:xsd='http://www.w3.org/2001/XMLSchema' xmlns:soapenv='http://schemas.xmlsoap.org/soap/envelope/' xmlns:cor='http://corpwsdl.oneninetwo'>
                        <soapenv:Header/>
                          <soapenv:Body>
                          <cor:search soapenv:encodingStyle='http://schemas.xmlsoap.org/soap/encoding/'>
                             <xml xsi:type='xsd:string'><![CDATA[
                                <Search xmlns:xsd='https://xml.proveid.experian.com/xsd/Search.xsd'>
                                    <Authentication>
                                        <Username>".$user."</Username>
                                        <Password>".$pw."</Password>
                                    </Authentication>
                                    <CountryCode>GBR</CountryCode>
                                    <Person>
                                        <Name>
                                            <Forename>".$firstName."</Forename>
                                            <Surname>".$secondName."</Surname>
                                        </Name>
                                        <DateOfBirth>".$dob."</DateOfBirth>
                                    </Person>
                                    <Addresses>
                                        <Address Current='1'>
                                            <Premise>".$premise."</Premise>
                                            <Street>".$streetName."</Street>
                                            <PostTown>".$postTown."</PostTown>
                                            <Region/>
                                            <Postcode>".$postCode."</Postcode>
                                            <CountryCode>GBR</CountryCode>
                                        </Address>
                                    </Addresses>
                                    <Telephones>
                                        <Telephone>
                                            <Number>".$telephone."</Number>
                                        </Telephone>
                                    </Telephones>
                                    <IPAddress>127.0.0.1</IPAddress>
                                    <Emails>
                                        <Email>".$email."</Email>
                                    </Emails>
                                    <SearchOptions>
                                    <ProductCode>".$product."</ProductCode>
                                    </SearchOptions>
                                </Search>]]>
                            </xml>
                            </cor:search>
                          </soapenv:Body>
                        </soapenv:Envelope>";

       $headers = array(
                    "Content-type: text/xml;charset=\"utf-8\"",
                    "Accept: text/xml",
                    "Cache-Control: no-cache",
                    "Pragma: no-cache",
                    "SOAPAction: https://xml.proveid.experian.com/IDSearch.cfc",
                    "Content-length: ".strlen($xml_post_string),
                );


        $url = $soapUrl;

        // PHP cURL  for https connection with auth
        $ch = curl_init();
        curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
        curl_setopt($ch, CURLOPT_URL, $url);
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
        curl_setopt($ch, CURLOPT_TIMEOUT, 100);
        curl_setopt($ch, CURLOPT_POST, true);
        curl_setopt($ch, CURLOPT_POSTFIELDS, $xml_post_string); // the SOAP request
        curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);

        // converting
        $response = curl_exec($ch);
        curl_close($ch);

        print_r($response);'

отклик

<Search xmlns:xsd="https://xml.proveid.experian.com/xsd/Search.xsd">
<CountryCode>GBR</CountryCode>
<Person>
    <Name><Forename>Baken</Forename>
        <Surname>Jorure</Surname>
    </Name>
    <DateOfBirth>1989-09-09</DateOfBirth>
    <Age>26</Age>
</Person>
<Addresses>
    <Address Current="1">
        <Premise>410</Premise>
        <Street>Beuno Terrace</Street>
        <PostTown>Beuno</PostTown>
        <Region/>
        <Postcode>LL545BT</Postcode>
        <CountryCode>GBR</CountryCode>
    </Address>
</Addresses>
<Telephones>
    <Telephone>
        <Number>01154567892</Number>
    </Telephone>
</Telephones>
<IPAddress>127.0.0.1</IPAddress>
<Emails>
    <Email>[email protected]</Email>
</Emails>
<SearchOptions>
    <ProductCode>ProveID</ProductCode>
</SearchOptions>
<OurReference>B3C369C0-F001-4FB1-80D3-801CB9D872FE</OurReference>
<SearchDate>2015-10-09T23:46:54</SearchDate>
<Result>
    <Summary>
        <ReportSummary>
            <DatablocksSummary>
                <DatablockSummary>
                    <Name>CreditReference</Name>
                    <Decision/>
                </DatablockSummary>
            </DatablocksSummary>
        </ReportSummary>
       <DecisionMatrix Code="ECIGSUAT" Name="Electronic Cigarettes">
           <Decision>
               <Outcome Type="Primary">0</Outcome>
               <Reason>Individuals DOB has not matched to active CAIS 
               ER or Citizen Card therefore application has been 
               referred
               </Reason>
           </Decision>
        </DecisionMatrix>
    </Summary>
    </Result>
</Search>

Теперь все, что мне действительно нужно, это число в тегах "Результат". Я пробовал так много способов, но я просто не могу понять.

Любая помощь приветствуется.

Заранее спасибо.

Теги:
soap

1 ответ

0
Лучший ответ

Для более простого использования SOAP вы можете использовать встроенный SOAP-клиент PHP. http://php.net/manual/en/class.soapclient.php

С классом SoapClient вы можете сделать что-то вроде этого:

<?php
    $soapUrl = "https://xml.proveid.experian.com/IDSearch.cfc?wdsl"
    $soapClient = new SoapClient($soapUrl);
    $parameters = array();
    $result = $soapClient->Search($parameters);
?>

В результате вы получите собственную структуру данных PHP, а не обычный текст XML, как здесь.

  • 0
    Привет @Edvinas спасибо за ваш ответ, я изучал написание запроса с SOAP-клиентом, но получал сообщение об ошибке из-за недопустимого XML-документа. Я не мог понять, как использовать несколько элементов, например. как бы я имел элемент <Person> </ Person> и элементы <Address> </ Address> в одном массиве с их дочерними элементами?
  • 0
    Если вы не можете использовать SoapClient ant, просто хотите проанализировать простой XML, вы можете использовать SimpleXMLElement. Как видно из вашего вопроса, вам нужно значение в теге Outcome, чтобы вы могли сделать что-то вроде этого: 3v4l.org/dhmtW
Показать ещё 1 комментарий

Ещё вопросы

Сообщество Overcoder
Наверх
Меню