Exchange-Rate
將 coinbase 與 uc_bitcoin drupal 模組一起使用
我需要一個簡單的技巧來更改 Drupal
uc_bitcoin
模組程式碼,以便它從 Coinbase 獲取匯率,它旨在使用 MtGox。我想避免使用整個 coinbase API,因為我只想要匯率,而不是廚房水槽。那裡有很多文件。我在
uc_bitcoin
從 MtGox 獲取資訊的 drupal 模組中找到了程式碼。它需要一些簡單的更改,以便從 Coinbase 獲取這些數據。由於兩者是如此不同,而且我對 PHP 並不流利,所以我認為有人可以幫助我解決這個問題。這是從 MtGox 獲取匯率的程式碼:
function uc_bitcoin_exchange_rate($order) { static $rate; if(isset($rate)) { return $rate; } if ($order->currency == 'BTC') { // BTC 1:1 return 1; } // Supported MtGox currencies, Dec 15 2012 $mtGox_currencies = array( 'USD', 'EUR', 'JPY', 'CAD', 'GBP', 'CHF', 'RUB', 'AUD', 'SEK', 'DKK', 'HKD', 'PLN', 'CNY', 'SGD', 'THB', 'NZD', 'NOK' ); // @todo add cache if (in_array($order->currency, $mtGox_currencies)) { if ($response = drupal_http_request('https://data.mtgox.com/api/1/BTC' . $order->currency . '/ticker')) { if ($response->code == 200) { $data = json_decode($response->data); if(!empty($data->return->avg->value)) { $rate = $data->return->avg->value; } } } } // @todo add cache if (in_array($order->currency, $mtGox_currencies)) { if ($response = drupal_http_request('https://data.mtgox.com/api/1/BTC' . $order->currency . '/ticker')) { if ($response->code == 200) { $data = json_decode($response->data); if(!empty($data->return->avg->value)) { $rate = $data->return->avg->value; } } } } if (!$rate || !is_numeric($rate)) { watchdog('uc_bitcoin', 'MtGox lookup - Unable to get current exchange rate', WATCHDOG_ERROR); $rate = FALSE; // just to be super sure. } return $rate; }
我對drupal不是很熟悉,而且我從來沒有使用過你所說的模組,但我會試一試:
function uc_bitcoin_exchange_rate($order) { static $data; $rate = FALSE; $currency = $order->currency; $currency_code = 'btc_to_' . strtolower($currency); if ($currency == 'BTC') { // BTC 1:1 return 1; } if (!isset($data) { if ($response = drupal_http_request('https://api.coinbase.com/v1/currencies/exchange_rates')) { if ($response->code == 200) { $data = json_decode($response->data); $rate = $data[$currency_code]; } } } if (!is_numeric($rate)) { watchdog('uc_bitcoin', 'CoinBase lookup - Unable to get current exchange rate', WATCHDOG_ERROR); $rate = FALSE; // just to be super sure. } return $rate; }
這對你有幫助嗎?
<https://dgtlmoon.com/how_configuring_drupals_ubercart_bitcoin_payment_module>
不幸的是,它需要通過 JSON/XMLRPC 與真正的“比特幣”實例通信,我不確定 blockchain.info 是否會提供這個?