2

致命错误:在第 83 行的 /home/gateway/public_html/index.php 中的非对象上调用成员函数 registerXPathNamespace()

所以我得到的错误在上面,在那一行是以下

$host = "services.incard.com.au/telechoicetransservice.asmx";

$timestamp = getGMTtimestamp();

$vars = 
"<?xml version=\"1.0\" encoding=\"UTF-8\"?>" .
"<soap:Envelope xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\" xmlns:soap=\"http://schemas.xmlsoap.org/soap/envelope/\">" .
    "<soap:Body>" .
        "<ProcessPayment xmlns=\"https://services.incard.com.au\">".
        "<auth>" .
            "<AccountCode>". urlencode($_POST['AccountCode'])."</AccountCode>".
            "<Username>". urlencode($_POST['AccountCode'])."</Username>".
            "<Password>". urlencode($_POST['AccountCode'])."</Password>".
        "</auth>" .
        "<MerchantNumber>".urlencode($_POST['MerchantNumber'])."</MerchantNumber>" .
        "<CustomerNumber>".urlencode($_POST['CustomerNumber'])."</CustomerNumber>".
        "<Amount>".urlencode($_POST['Amount'])."</Amount>".
        "<Description>".urlencode($_POST['Description'])."</Description>".
        "</ProcessPayment>".
"</soap:Body></soap:Envelope>";

$response = openSocket($host, $vars);

$xmlres = array();
$xmlres = makeXMLTree ($response);
$xml = simplexml_load_string($response); 
$xml->registerXPathNamespace('soap:Envelope', 'http://schemas.xmlsoap.org/soap/envelope/');
foreach ($xml->xpath('//soap:Envelope:ResponseCode') as $item) {
    echo (string) $item; 
}
foreach ($xml->xpath('//soap:Envelope:ResponseDescription') as $item) {
    echo (string) $item; 
}

我不知道为什么它不起作用。

我们从我们请求的服务器返回的响应如下

HTTP/1.1 200 OK
Content-Type: text/xml; charset=utf-8
Content-Length: length

<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
  <soap:Body>
    <ProcessPaymentResponse xmlns="https://services.incard.com.au">
      <ProcessPaymentResult>
        <ResponseCode>string</ResponseCode>
        <ResponseDescription>string</ResponseDescription>
      </ProcessPaymentResult>
    </ProcessPaymentResponse>
  </soap:Body>
</soap:Envelope>
4

1 回答 1

3

尝试更换

<?php
$xml->registerXPathNamespace('soap:Envelope', 
                                   'http://schemas.xmlsoap.org/soap/envelope/');
foreach ($xml->xpath('//soap:Envelope:ResponseCode') as $item) {
    echo (string) $item; 
}
foreach ($xml->xpath('//soap:Envelope:ResponseDescription') as $item) {
    echo (string) $item; 
}
?>

<?php
$xml->registerXPathNamespace( 'soap', 
                                'http://schemas.xmlsoap.org/soap/envelope/' );
$result = $xml->xpath('//soap:Body');

foreach ($result as $body) {
  echo $body->ProcessPaymentResponse->ProcessPaymentResult->ResponseCode . "<br />";
  echo $body->ProcessPaymentResponse->ProcessPaymentResult->ResponseDescription . "<br />";
}
?>

希望这可以帮助。

于 2012-05-11T10:22:13.527 回答