0

对于货币转换,我使用“florianv/laravel-swap”:“^1.1”库。Florianv/Laravel 交换

由于 Fixer.io 已更改其实现,因此有必要将 access_key 与请求一起传递,因此我收到此错误:“InvalidArgumentException: The "access_key" option must be provided to use fixer.io in /var/ www/project/project-files/vendor/florianv/exchanger/src/Service/Fixer.php:51 "。

我注册并获得了 access_key。我使用 composer 更新了库,现在我可以在vendor/florianv/exchanger/src/Service/Fixer.php中看到三个常量。

const ACCESS_KEY_OPTION = 'access_key';
const LATEST_URL = 'http://data.fixer.io/api/latest?base=%s&access_key=%s';
const HISTORICAL_URL = 'http://data.fixer.io/api/%s?base=%s&access_key=%s';

要传递访问密钥,我尝试了这个:

我在配置文件夹中有一个 swap.php,它看起来像这样:

return [
    'options' => [
        'cache_ttl' => 86400, // 24 hours.
        'cache_key_prefix' => 'currency_rate'
    ],
    'services' => [
        'fixer' => true,
    ],
    'currency_layer' => [
        'access_key' => 'asdfas7832mw3nsdfa776as8dfa', // Your app id
        'enterprise' => true, // True if your AppId is an enterprise one
    ],
    'cache' => env('CACHE_DRIVER', 'file'),
    'http_client' => null,
    'request_factory' => null,
    'cache_item_pool' => null,
];

这还有一个选项已被评论,我启用并在其中传递了 access_key,但它不起作用。我还在“fixer => true”下面的服务块中添加了它。

'currency_layer' => [
    'access_key' => 'asdfas7832mw3nsdfa776as8dfa'
]

同样在选项块中:

'options' => [
    'cache_ttl' => 86400, // 24 hours.
    'cache_key_prefix' => 'currency_rate',
    'access_key'=>'7ca208e9136c5e140d6a14427bf9ed21'
],

我尝试在 config/services.php 文件中添加 access_key,但它也没有用。

'fixer' => [
    'access_key'     => 'asdfas7832mw3nsdfa776as8dfa'
],

即使我尝试过,添加到 env 文件并从那里调用,但没有成功。我如何通过access_key,任何人都可以帮助我,应该是什么方法。

4

1 回答 1

0

vendor/florianv/exchanger/src/Service/Fixer.php ->不要触摸常量(这是我自己的错误)。

通过创建 Builder 传递选项数组:

    $options = ['access_key'    => 'YourGeneratedAPIKeyAtCurrencyLayer'];
    $this->exchangeSwap = (new Builder($options))
      ->add('fixer', $options )
      ->build();

我希望我能帮忙;-)

于 2018-04-19T12:19:14.150 回答