PHP code example of wavpa / exchange-rate

1. Go to this page and download the library: Download wavpa/exchange-rate library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

wavpa / exchange-rate example snippets


use Wavpa\ExchangeRate\ExchangeRate;

$key = 'xxxxxxxxxxxxxxxx';

$exchangeRate = new ExchangeRate($key);

$response = $exchangeRate->convert('CNY', 'USD');

{
    "status":0,
    "msg":"ok",
    "result":{
        "from":"CNY",
        "to":"USD",
        "fromname":"人民币",
        "toname":"美元",
        "updatetime":"2020-08-24 16:04:42",
        "rate":"0.1447",
        "camount":0.1447
    }
}

string convert(string $from, string $to)

'exchange-rate' => [
    'key' => env('EXCHANGE_RATE_API_KEY'),
],

public function convert(Request $request, ExchangeRate $exchangeRate, $from, $to)
{
    return $exchangeRate->convert($from, $to);
}

public function convert(Request $request, $from, $to)
{
    return app('exchange-rate')->convert($from, $to);
}