Php Can';t从SOAP响应中提取数据

Php Can';t从SOAP响应中提取数据,php,soap,Php,Soap,我一直在使用CURL和PHP处理SOAP请求/响应,但是我似乎无法为自己的一生解决如何提取数据的问题 用于SOAP请求的脚本 $soapUrl = "https://xml.proveid.experian.com/IDSearch.cfc?wdsl"; // xml post structure $xml_post_string = "<?xml version='1.0' encoding='utf-8'?>

我一直在使用CURL和PHP处理SOAP请求/响应,但是我似乎无法为自己的一生解决如何提取数据的问题

用于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);`
$soapUrl=”https://xml.proveid.experian.com/IDSearch.cfc?wdsl";     
//xml post结构
$xml\u post\u字符串=”
“$user。”
“$pw。”
GBR
“$firstName。”
“$secondName。”
“$dob。”
“$premise。”
“$streetName。”
“$postTown。”
“$邮政编码。”
GBR
“$电话。”
127.0.0.1
“$email。”
“$product。”
]]>
";
$headers=数组(
“内容类型:text/xml;字符集=\“utf-8\”,
“接受:文本/xml”,
“缓存控制:无缓存”,
“Pragma:无缓存”,
“行动:https://xml.proveid.experian.com/IDSearch.cfc",
“内容长度:”.strlen($xml\u post\u string),
);
$url=$soapUrl;
//用于https与auth连接的PHP cURL
$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_超时,100);
curl_setopt($ch,CURLOPT_POST,true);
curl_setopt($ch,CURLOPT_POSTFIELDS,$xml_post_string);//SOAP请求
curl_setopt($ch,CURLOPT_HTTPHEADER,$headers);
//转换
$response=curl\u exec($ch);
卷曲关闭($ch);
打印(回复)`
响应

<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>bakenjorure@www.com</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>

GBR
烘焙
乔鲁
1989-09-09
26
410
贝乌诺露台
贝诺
LL545BT
GBR
01154567892
127.0.0.1
bakenjorure@www.com
普罗维德
B3C369C0-F001-4FB1-80D3-801CB9D872FE
2015-10-09T23:46:54
信用参考
0
DOB未与现行CAI匹配的个人
ER或公民卡,因此申请已被批准
援引的
现在我真正需要的是结果标签上的数字。我试过很多方法,但似乎都不明白

任何帮助都将不胜感激


提前感谢。

为了更简单地使用SOAP,您可以使用PHP内置的SOAP客户端。

使用SoapClient类,您可以执行以下操作:

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


结果,您将获得本机PHP数据结构,而不是此处的纯文本XML。

为了更简单地使用SOAP,您可以使用PHP内置的SOAP客户端。

使用SoapClient类,您可以执行以下操作:

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


结果,您将获得本机PHP数据结构,而不是此处的纯文本XML。

Hi@Edvinas感谢您的回答,我确实研究过使用SOAP客户端编写请求,但我不断收到无效XML文档的错误响应。我似乎无法掌握如何使用多个元素,例如,如何将元素和元素包含在一个数组中及其子元素?如果不能使用SoapClient ant,只想解析纯XML,可以使用SimpleXMLElement。正如我从你的问题中看到的,你需要结果标签中的值,所以你可以在这个例子中这样做:Hi@Edvinas谢谢你的回答。我设法用一种稍微不同的方法提取数据,但你肯定让我走上了正确的道路。当我最终提取所需的数据时,我最终编码为JSON。我相信你的回答会帮助任何遇到这个问题的人!您好@Edvinas谢谢您的回答,我确实考虑过使用SOAP客户端编写请求,但是我一直收到无效XML文档的错误响应。我似乎无法掌握如何使用多个元素,例如,如何将元素和元素包含在一个数组中及其子元素?如果不能使用SoapClient ant,只想解析纯XML,可以使用SimpleXMLElement。正如我从你的问题中看到的,你需要结果标签中的值,所以你可以在这个例子中这样做:Hi@Edvinas谢谢你的回答。我设法用一种稍微不同的方法提取数据,但你肯定把我弄对了