我正在研究支付解决方案,需要一些 PHP 帮助。我正在做一个 HTTPRequest,作为回应,我会得到一些 XML。XML 可能如下所示:
<?xml version="1.0" encoding="utf-8" ?>
<payer>
<purchase_list>
<freeform_purchase>
<line_number>1</line_number>
<description>description</description>
<price_including_vat>12</price_including_vat>
<vat_percentage>
15
</vat_percentage>
<quantity>10</quantity>
</freeform_purchase>
</purchase_list>
<payment_urls>
<auth_url>authurl</auth_url>
<settle_url>settleurl</settle_url>
</payment_urls>
</payer>
基本上我想做的是从标签中获取内容并将它们保存在字符串中。
我试过这个:
$order = '<?xml version="1.0" encoding="utf-8" ?>
<payer>
<purchase_list>
<freeform_purchase>
<line_number>1</line_number>
<description>description</description>
<price_including_vat>12</price_including_vat>
<vat_percentage>
15
</vat_percentage>
<quantity>10</quantity>
</freeform_purchase>
</purchase_list>
<payment_urls>
<auth_url>authurl</auth_url>
<settle_url>settleurl</settle_url>
</payment_urls>
</payer>';
$orderXML = new DOMDocument();
$orderXML->load($order);
$payerXML = $orderXML->getElementsByTagName( 'payer' );
$purchase_listXML = $orderXML->getElementsByTagName( 'purchase_list' );
$freeform_purchaseXML = $orderXML->getElementsByTagName( 'freeform_purchase' );
$linenumberXML = $orderXML->getElementsByTagName( 'line_number' );
$descriptionXML = $orderXML->getElementsByTagName( 'description' );
$price_inc_vatXML = $orderXML->getElementsByTagName( 'price_including_vat' );
$vat_percentageXML = $orderXML->getElementsByTagName( 'vat_percentage' );
$quantityXML = $orderXML->getElementsByTagName( 'quantity' );
$settle_urlXML = $orderXML->getElementsByTagName( 'settle_url' );
$auth_urlXML = $orderXML->getElementsByTagName( 'auth_url' );
$theLineNumber = $linenumberXML->item(0)->nodeValue;
$theValue = $descriptionXML->item(0)->nodeValue;
$freeform_price = $price_inc_vatXML->item(0)->nodeValue;
$freeform_vat = $vat_percentageXML->item(0)->nodeValue;
$freeform_quantity = $quantityXML->item(0)->nodeValue;
$Settle_url = $settle_urlXML->item(0)->nodeValue;
$Auth_url = $auth_urlXML->item(0)->nodeValue;
echo 'thLineNumber - ' . $theLineNumber;
echo $theValue;
echo $freeform_price;
echo $freeform_vat;
echo $freeform_quantity;
echo $Settle_url;
echo $Auth_url;
但显然有什么问题,因为它不会回应任何东西.. 建议?