Исправить биткойн php api в плагине WordPress?Совет пожалуйста!Спасибо - PullRequest
0 голосов
/ 26 сентября 2019

Мне нужна помощь, чтобы это исправить!Пожалуйста, помогите мне исправить этот скрипт!

<?php

if ( !defined( 'ABSPATH' ) ) {
    exit();
}

function cryptoniq_get_currency_prices() {

    $url = 'https://bitpay.com/api/rates';
    $request = wp_remote_get( $url );

    if( is_wp_error( $request ) ) {
        return false; 
    }

    $body = wp_remote_retrieve_body( $request );
    $coinslist2 = json_decode( $body, true );
    $coinslist = $coinslist2[0]["code"]; 
    return $coinslist;
}

function cryptoniq_get_coin_prices() {

    $url = 'https://bitpay.com/api/rates';
    $request = wp_remote_get( $url );

    if( is_wp_error( $request ) ) {
        return false; 
    }

    $body = wp_remote_retrieve_body( $request );
    $pricelist2 = json_decode( $body, true );
    $pricelist = $pricelist2[0]["rate"];    
    return $pricelist;
}

function cryptoniq_get_price( $coin = 'BTC', $amount = '', $currency = '', $random = 'no' ) {
    if ( $amount == 0 ) {
        return '0.00000000';
    }

    $base_currency = get_woocommerce_currency();
    $currency_prices = get_option( 'cryptoniq_currency_prices' );
    $coin_prices = get_option( 'cryptoniq_coin_prices' );

    if ( $currency && array_key_exists( $currency, $currency_prices ) ) {
        $amount = $amount / $currency_prices[$currency];
    } elseif ( $base_currency && $base_currency != 'USD' && array_key_exists( $base_currency, $currency_prices ) ) {
        $amount = $amount / $currency_prices[$base_currency];
    }

    if ( !empty( $coin ) && ( $coin == 'BTC' || $coin == 'ETH' || $coin == 'DOGE' || $coin == 'LTC' || $coin == 'ZEC' || $coin == 'DASH' ) ) {

$price = $amount / $coin_prices[$coin];

    } else {
        return;
    }

    // Calc Formula     
    $extra_random_number = ( $random == 'yes' ) ? rand( 100, 999 ) / 100000000 : 0;
    $coins_num = $price + $extra_random_number;
    $coins_num = number_format( (float) $coins_num, 8, '.', '' );

    return $coins_num;
}

Мне нужна помощь, чтобы исправить старый скрипт!Пожалуйста, помогите мне исправить этот скрипт!Я не получаю никаких результатов после того, как я изменил ссылку на API с https://api.cryptoniq.io/currencies с более не надежно на https://bitpay.com/api/rates для плагина WordPress.Некоторая помощь будет по достоинству оценена.Thx.

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...