currency-exchange-rates - 谷歌货币转换器不再工作

标签 currency-exchange-rates

Google Finance Currency Converter 似乎已完全停止工作。一周前,我开始从我的 Magento 1.9.2 商店收到这些电子邮件通知:

货币更新警告:
警告:无法从 https://finance.google.com/finance/converter?a=1&from=GBP&to=EUR 检索费率.
警告:无法从 https://finance.google.com/finance/converter?a=1&from=GBP&to=USD 检索费率.

这些 URL 确实不再有效。有谁知道我们是否可以使用新的 URL,或者我们是否需要配置不同的服务?

最佳答案

此链接不再有效。

 protected $_url = 'https://finance.google.com/finance/converter?a=1&from={{CURRENCY_FROM}}&to={{CURRENCY_TO}}';

我研究并找到了这个代码。

找到这个文件:
app/code/local/Payserv/GoogleFinance/Model/Google.php

将代码替换为:
class Payserv_GoogleFinance_Model_Google extends Mage_Directory_Model_Currency_Import_Abstract {

protected $_url = 'http://free.currencyconverterapi.com/api/v3/convert?q={{CURRENCY_FROM}}_{{CURRENCY_TO}}';

protected $_messages = array();

protected function _convert($currencyFrom, $currencyTo, $retry=0) {
    $url = str_replace('{{CURRENCY_FROM}}', $currencyFrom, $this->_url);
    $url = str_replace('{{CURRENCY_TO}}', $currencyTo, $url);
    try {
         $resultKey = $currencyFrom.'_'.$currencyTo;
         $response = file_get_contents($url);
         $data = Mage::helper('core')->jsonDecode($response);
         $results = $data['results'][$resultKey];
         $queryCount = $data['query']['count'];
         if( !$queryCount &&  !isset($results)) {
            $this->_messages[] = Mage::helper('directory')->__('Cannot retrieve rate from %s.', $url);
            return null;
        }
       return (float)$results['val'];
    } catch (Exception $e) {
        if ($retry == 0) {
            $this->_convert($currencyFrom, $currencyTo, 1);
        } else {
            $this->_messages[] = Mage::helper('directory')->__('Cannot retrieve rate from %s', $url);
        }
    }
}
}

关于currency-exchange-rates - 谷歌货币转换器不再工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49389746/

相关文章:

javascript - Basic Angular - 如何将 json http 响应加载到另一个 json 对象中

java - 没有API ID可以调用外部API吗?

google-api - Google 财经 API 错误

mysql - SQL - 计算给定时期的平均汇率并在选择中使用

sql - 在货币汇率中使用的最大小数位数是多少?

javascript - 如何使用 jquery ajax 方法从响应中提取转换后的值?

excel - Google Sheets 中的 Google Finance 货币汇率问题