如何使用curl在支付网关网址中自定义变量?

时间:2015-09-15 10:05:21

标签: php magento curl

以下是我用于在支付网关网址中附加变量的代码。但我认为卷曲方法不正确。问题是什么?我想我必须使用curl的简单get请求吗?

public function getPaymentmethodPaymentgatewayurl()
{
$orderId = Mage::getSingleton('checkout/session')->getLastRealOrderId();
$order = Mage::getSingleton('sales/order')->loadByIncrementId($orderId);
$currency_code = Mage::app()->getStore()->getCurrentCurrencyCode();
$amt = $order->getGrandTotal();
$url = Mage::getStoreConfig("payment/paymentgateway/cgi_url");
$fields = array(
    'mid' => $mid,
    'ref' => time(),
    'cur' => $currency_code,
    'amt' => $amt,
);

$fields_string = "";
foreach ($fields as $key => $value)
{
  $fields_string .= $key . '=' . $value . '&';
}
$fields_string = substr($fields_string, 0, -1);
//open connection
$ch = curl_init($url);
//set the url, number of POST vars, POST data
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $fields_string);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($ch, CURLOPT_HEADER, 0); // DO NOT RETURN HTTP HEADERS
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); // RETURN THE CONTENTS OF THE CALL
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 120); // Timeout on connect (2 minutes)
//execute post
$result = curl_exec($ch);
curl_close($ch);
return $result; }

0 个答案:

没有答案