首页 > 解决方案 > 尝试通过 Guzzle 和 Laravel 连接到 Binance API

问题描述

我真的很挣扎,我不明白为什么。

基于此文档: https ://binance-docs.github.io/apidocs/spot/en/#system-status-system

我做了我的第一个请求,没有任何问题:

$data = Http::get('https://api.binance.com/sapi/v1/system/status');
if ($data) {
    return response()->json($data);
}

现在当我尝试这个时:

$timeStamp = Carbon::now()->timestamp;
$query_string = 'timestamp=' . $timeStamp;
$secretKey = config('exchanges.binance.binance_secret_key');
$apiKey = config('exchanges.binance.binance_api_key');
$signature = hash_hmac('sha256', $query_string, $secretKey) . PHP_EOL;

$data = Http::withHeaders([
    'X-MBX-APIKEY' => $apiKey,
])->get('https://api.binance.com/sapi/v1/capital/config/getall', [
    'timestamp' => $timeStamp,
    'signature' => $signature
]);
if ($data) {
    return response()->json($data);
}

我不断得到这个:

cURL error 6: Could not resolve host: sapi (see https://curl.haxx.se/libcurl/c/libcurl-errors.html) for sapi/v1/capital/config/getall?xxxxxxxxxxx

知道为什么会发生这种情况,请问我真的用 Guzzle 正确地形成了我的请求吗?

谢谢你。

标签: phplaravelguzzlebinance

解决方案


推荐阅读