Laravel Binance API调用在Lavavel控制器中不起作用
我正在编写一个调用Binance PHP API的laravel控制器 如果从命令行单独运行,则PHP API可以完美运行,例如。, php price.php +++++++price.php++++++++ $api=new\Binance\api($api\u key,$api\u secret) //获取所有位置,包括估计BTC值 $price=$api->price(“BNBBTC”);打印(价格) +++++++price.php+++++++++ 但是,如果我从laravel控制器调用api函数price(),则不会显示任何内容,也不会出现任何错误等。我可以添加($binance_api),它返回的结果是,使用所有正确的api密钥/密码成功创建了对象 类PriceController扩展控制器{Laravel Binance API调用在Lavavel控制器中不起作用,laravel,binance,Laravel,Binance,我正在编写一个调用Binance PHP API的laravel控制器 如果从命令行单独运行,则PHP API可以完美运行,例如。, php price.php +++++++price.php++++++++ $api=new\Binance\api($api\u key,$api\u secret) //获取所有位置,包括估计BTC值 $price=$api->price(“BNBBTC”);打印(价格) +++++++price.php+++++++++ 但是,如果我从laravel控制器
公共功能价格 (请求$请求){ $api_key=“xxxxxxx” $api_secret=“xxxxxxxx” } }
您需要返回一个值
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;
}
}
在API类定义中,公共函数price(){return$this->priceData($this->httpRequest(“v3/ticker/price”);}我发现根本原因是其他原因。但是谢谢你的评论。
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;
}
}