本文整理汇总了PHP中xml::addChild方法的典型用法代码示例。如果您正苦于以下问题:PHP xml::addChild方法的具体用法?PHP xml::addChild怎么用?PHP xml::addChild使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类xml
的用法示例。
在下文中一共展示了xml::addChild方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: requestRealvaultReceiptIn
/**
* Return result of payment via RealVault
* @param xml $xm from RealexRedirectValidationModuleFrontController::postProcess()
* @param boolean $ask_dcc (optional)
* @param boolean $set_dcc (optional)
* @return xml
*/
public function requestRealvaultReceiptIn($xm, $ask_dcc = true, $set_dcc = false)
{
$url = 'https://epage.payandshop.com/epage-remote-plugins.cgi';
$tmp = $xm->attributes()->timestamp . '.' . $this->merchant_id . '.' . $xm->orderid . '.' . $xm->amount . '.' . $xm->currency . '.' . $xm->payerref;
$sha1hash = sha1($tmp);
$tmp = $sha1hash . '.' . $this->shared_secret;
$sha1hash = sha1($tmp);
$xm->addChild('sha1', $sha1hash);
if ($xm->dcc != '0' && $ask_dcc) {
$xm_dcc = $this->requestRealvaultDccrate($xm);
} else {
$xm_dcc = false;
}
if ($xm_dcc) {
exit;
}
$xml = "<request type='receipt-in' timestamp='" . $xm->attributes()->timestamp . "'>";
$xml .= '<merchantid>' . $this->merchant_id . '</merchantid>
<account>' . $xm->account . '</account>
<orderid>' . $xm->orderid . '</orderid>
<amount currency="' . $xm->currency . '">' . $xm->amount . '</amount>';
if (!empty($xm->cvn)) {
$xml .= '<paymentdata>
<cvn>
<number>' . $xm->cvn . '</number>
</cvn>
</paymentdata>';
}
if ($set_dcc) {
$xml .= '<autosettle flag="1" />';
} else {
$xml .= '<autosettle flag="' . $xm->autosettle . '" />';
}
if (isset($xm->eci) && !empty($xm->eci)) {
$xml .= '<mpi>';
if (isset($xm->cavv) && !empty($xm->cavv) && isset($xm->xid) && !empty($xm->xid)) {
$xml .= '<cavv>' . $xm->cavv . '</cavv>
<xid>' . $xm->xid . '</xid>';
}
if (isset($xm->eci) && !empty($xm->eci)) {
$xml .= '<eci>' . $xm->eci . '</eci></mpi>';
}
}
$xml .= '<payerref>' . $xm->payerref . '</payerref>
<paymentmethod>' . $xm->paymentmethod . '</paymentmethod>';
if ($set_dcc) {
$xml .= '
<dccinfo>
<ccp>' . $xm->dcc . '</ccp>
<type>1</type>
<rate>' . $xm->cardholderrate . '</rate>
<ratetype>S</ratetype>
<amount currency="' . $xm->cardholdercurrency . '">' . $xm->cardholderamount . '</amount>
</dccinfo>';
}
$xml .= '<md5hash />
<sha1hash>' . $sha1hash . '</sha1hash>
<comments>
<comment id="1" />
<comment id="2" />
</comments>
<tssinfo>
<address type="billing">
<code>' . $xm->billing_code . '</code>
<country>' . $xm->billing_country . '</country>
</address>
<address type="shipping">
<code>' . $xm->shipping_code . '</code>
<country>' . $xm->shipping_country . '</country>
</address>
<custnum></custnum>
<varref></varref>
<prodid></prodid>
</tssinfo>
</request>';
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_USERAGENT, 'payandshop.com php version 0.9');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $xml);
$response = curl_exec($ch);
curl_close($ch);
$xm_receipt = simplexml_load_string($response);
if (isset($xm->eci)) {
$xm_receipt->addChild('eci', $xm->eci);
}
if (isset($xm_receipt->dccinfo)) {
$xm_receipt->addChild('dcc', $xm->dcc);
$xm_receipt->addChild('dcc_choice', $xm->dcc_choice);
$xm_receipt->addChild('dcc_rate', $xm_receipt->dccinfo->cardholderrate);
$xm_receipt->addChild('dcc_cardholder_amount', $xm_receipt->dccinfo->cardholderamount);
$xm_receipt->addChild('dcc_cardholder_currency', $xm_receipt->dccinfo->cardholdercurrency);
//.........这里部分代码省略.........
示例2: _data2xml
/**
* 数据XML编码
* @param xml $xml XML对象
* @param mixed $data 数据
* @param string $item 数字索引时的节点名称
* @return string xml
*/
private static function _data2xml($xml, $data, $item = 'item')
{
foreach ($data as $key => $value) {
is_numeric($key) && ($key = $item);
if (is_array($value) || is_object($value)) {
$child = $xml->addChild($key);
self::_data2xml($child, $value, $item);
} else {
if (is_numeric($value)) {
$child = $xml->addChild($key, $value);
} else {
$child = $xml->addChild($key);
$node = dom_import_simplexml($child);
$node->appendChild($node->ownerDocument->createCDATASection($value));
}
}
}
}