2013-06-11 92 views
0

我想這個問題不是Sage Pay的具體問題,雖然它被提及與我的問題有關,所以希望你能幫助我解決這個棘手的問題。從xml文件中讀取(Sage Pay Reporting API)

這就是我想做的事:

  • 的主要任務是從聖人薪酬報告API獲取數據 - 就像一個魅力
  • 閱讀和收集從XML輸出文件中的變量 - 不工作

下面的代碼確實顯示重定向到Sage Pay網站後的交易列表,但我無法弄清楚如何獲得例如單個交易的金額並存儲它。

這裏是xml output的樣子:

任何答案/解決方案?我感謝您的幫助!

<? 

$command = 'getTransactionList'; 
$vendor = 'vendorname'; 
$user = 'username'; 
$password = 'pwd'; 
$startdate = '01/05/2013 00:00:01'; 
$enddate = '31/05/2013 23:59:59'; 

$string = '<command>'.$command.'</command><vendor>'.$vendor.'</vendor><user>'.$user.'</user><startdate>'.$startdate.'</startdate><enddate>'.$enddate.'</enddate>'; 


$crypt = MD5($string . '<password>' . $password . '</password>'); 

$curl = curl_init('https://test.sagepay.com/access/access.htm'); 
curl_setopt($curl, CURLOPT_FAILONERROR, true); 
curl_setopt($curl, CURLOPT_FOLLOWLOCATION, true); 
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true); 
curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, false); 
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false); 
$result = curl_exec($curl); 

$rxml = simplexml_load_string($result); 
echo $rxml->transactions->transaction[0]->amount; 

?> 

<HTML> 

<BODY> 


<form method="post" action="https://test.sagepay.com/access/access.htm"> 

<input type="hidden" name="XML" value="<vspaccess><?php echo $string; ?><signature><?php echo $crypt; ?></signature></vspaccess>"> 
<input type="submit" name="Button" value="Send"> 

</form> 
</BODY> 
</HTML> 
+0

顯示您在'$ result'中獲得的XML(刪除任何財務或個人數據)。 – MrCode

+0

如果你想分析XML,重要的不是你如何連接到外部計算機來下載數據,而是下載的XML數據如何(你不說)。 –

+0

謝謝MrCode和Álvaro。當我注意到我需要聲望爲10才能顯示它時,我已經在我的發帖中輸出了結果。將嘗試其他方式... – Kleni

回答

1

替換$ RXML = simplexml_load_string($結果);

$ RXML =新SimpleXMLElement($結果);