致命错误:在第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>
答案 0 :(得分:1)
尝试替换
<?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 />";
}
?>
希望这有帮助。