Binance API 调用在 Laravel Controller 中不起作用

Binance API call not working in Lavavel Controller

我正在写一个 laravel 控制器调用 Binance PHP APIs.

PHP API 如果 运行 单独从命令行运行,例如, phpprice.php

+++++++price.php++++++++

$api = new \Binance\API($api_key, $api_secret);

// Get all of your positions, including estimated BTC value $price =$api->price("BNBBTC"); print_r($price);

+++++++price.php+++++++++

但是,如果我从 laravel 控制器调用 api 函数 price(),没有任何显示,没有错误等。我可以 dd($binance_api) 并返回使用所有正确的 API key/secret.

成功创建对象

Class PriceController extends Controller{
public function price (Request $request){

$api_key = "xxxxxxx";

$api_secret = "xxxxxxxx";

$binance_api = new \Binance\API($api_key, $api_secret);

$price = $binance_api->price("BNBBTC");

}

}

您需要return一个值

Class PriceController extends Controller{
  public function price (Request $request){
    $api_key = "xxxxxxx";
    $api_secret = "xxxxxxxx";
    $binance_api = new \Binance\API($api_key, $api_secret);
    $price = $binance_api->price("BNBBTC");
    return $price;
  }
}