fix: cronjob exchange update would not work with apilayer (#381)
This commit is contained in:
parent
d410d4804a
commit
b0b4b7a65c
@ -11,7 +11,7 @@
|
|||||||
$userId = $userToUpdateExchange['id'];
|
$userId = $userToUpdateExchange['id'];
|
||||||
echo "For user: " . $userToUpdateExchange['username'] . "<br />";
|
echo "For user: " . $userToUpdateExchange['username'] . "<br />";
|
||||||
|
|
||||||
$query = "SELECT api_key FROM fixer WHERE user_id = :userId";
|
$query = "SELECT api_key, provider FROM fixer WHERE user_id = :userId";
|
||||||
$stmt = $db->prepare($query);
|
$stmt = $db->prepare($query);
|
||||||
$stmt->bindParam(':userId', $userId, SQLITE3_INTEGER);
|
$stmt->bindParam(':userId', $userId, SQLITE3_INTEGER);
|
||||||
$result = $stmt->execute();
|
$result = $stmt->execute();
|
||||||
@ -21,6 +21,7 @@
|
|||||||
|
|
||||||
if ($row) {
|
if ($row) {
|
||||||
$apiKey = $row['api_key'];
|
$apiKey = $row['api_key'];
|
||||||
|
$provider = $row['provider'];
|
||||||
|
|
||||||
$codes = "";
|
$codes = "";
|
||||||
$query = "SELECT id, name, symbol, code FROM currencies WHERE user_id = :userId";
|
$query = "SELECT id, name, symbol, code FROM currencies WHERE user_id = :userId";
|
||||||
@ -39,8 +40,20 @@
|
|||||||
$mainCurrencyCode = $row['code'];
|
$mainCurrencyCode = $row['code'];
|
||||||
$mainCurrencyId = $row['main_currency'];
|
$mainCurrencyId = $row['main_currency'];
|
||||||
|
|
||||||
$api_url = "http://data.fixer.io/api/latest?access_key=". $apiKey . "&base=EUR&symbols=" . $codes;
|
if ($provider === 1) {
|
||||||
$response = file_get_contents($api_url);
|
$api_url = "https://api.apilayer.com/fixer/latest?base=EUR&symbols=" . $codes;
|
||||||
|
$context = stream_context_create([
|
||||||
|
'http' => [
|
||||||
|
'method' => 'GET',
|
||||||
|
'header' => 'apikey: ' . $apiKey,
|
||||||
|
]
|
||||||
|
]);
|
||||||
|
$response = file_get_contents($api_url, false, $context);
|
||||||
|
} else {
|
||||||
|
$api_url = "http://data.fixer.io/api/latest?access_key=". $apiKey . "&base=EUR&symbols=" . $codes;
|
||||||
|
$response = file_get_contents($api_url);
|
||||||
|
}
|
||||||
|
|
||||||
$apiData = json_decode($response, true);
|
$apiData = json_decode($response, true);
|
||||||
|
|
||||||
$mainCurrencyToEUR = $apiData['rates'][$mainCurrencyCode];
|
$mainCurrencyToEUR = $apiData['rates'][$mainCurrencyCode];
|
||||||
|
|||||||
@ -1,3 +1,3 @@
|
|||||||
<?php
|
<?php
|
||||||
$version = "v2.4.0";
|
$version = "v2.4.1";
|
||||||
?>
|
?>
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user