XML到PHP的SOAP请求

时间:2017-03-29 16:46:04

标签: php xml soap

SOAP请求XML如下所示:

<soapenv:Body>
<net:GetAvailability>
    <net:request>
        <inh:UserCredentials>
           <inh:AgentID>**</inh:AgentID><inh:Password>**</inh:Password>
           <inh:Username>**</inh:Username>
        </inh:UserCredentials>

        <net:AccessCircuit>
            <arr:string>All</arr:string>
        </net:AccessCircuit>

        <net:RequestDetails xsi:type="net:TelephoneNumberAvailabilityRequest" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
            <net:PerformMPFACCheck>No</net:PerformMPFACCheck>
            <net:ProxyCLI>true</net:ProxyCLI>
            <net:TelephoneNumber>0121****</net:TelephoneNumber>
        </net:RequestDetails>
        <net:UserConsent>Yes</net:UserConsent>
    </net:request>
</net:GetAvailability>
</soapenv:Body>

我需要做的是使用PHP SOAP发送此XML请求但是我无法使其工作。我目前的代码如下:

$APIParameters = array(
        'request' => array(
            'UserCredentials' => array(
                'Username' => $this->apiUsername,
                'Password' => $this->apiPassword,
                'AgentID' => $this->apiResellerID,
            ),
            'AccessCircuit' => array(
                'string' => 'All'
            ),
            'UserConsent' => 'Yes',

        )
    );

    $APIParameters['request']['RequestDetails'] = new SoapParam( array('PerformMPFACCheck' => 'Yes', 'Postcode' => "****", 'ProxyCLI' => "true", 'TelephoneNumber' => '****'), "TelephoneNumberAvailabilityRequest");

    print_r($APIParameters);                        
    $apiResult = $SOAPClient->GetAvailability($APIParameters);

print_r()返回以下内容:

Array
(
[request] => Array
    (
        [UserCredentials] => Array
            (
                [Username] => ****
                [Password] => ****
                [AgentID] => ****
            )

        [AccessCircuit] => Array
            (
                [string] => All
            )

        [UserConsent] => Yes
        [RequestDetails] => SoapParam Object
            (
                [param_name] => TelephoneNumberAvailabilityRequest
                [param_data] => Array
                    (
                        [PerformMPFACCheck] => Yes
                        [Postcode] => ****
                        [ProxyCLI] => true
                        [TelephoneNumber] => 0121****
                    )

            )

    )

然而SOAP请求失败并出现致命错误:未捕获的SoapFault异常:[a:InternalServiceFault]。我究竟做错了什么?!感谢任何帮助!

1 个答案:

答案 0 :(得分:0)

首先检查您使用此代码授予的wsld soap访问权限

 <?php
// enter your url
    $client = new SoapClient('enteryoururl');
    var_dump($client->__getFunctions());
?>

然后检查此网址中有哪个功能,如果您有访问权限,并且您的功能列表显示您的功能,请尝试此操作

Fatal error: Uncaught SoapFault exception: [ns1:Client.AUTH_1] Authentication Failed