I try to used binance api in my php class to retreive my all deposit addresses, but when i execute my function he return me error code -1022 and error message is "Signature for this request is not valid".
<?php
public class Binance{
private $secret = null;
private $key = null;
private $path_url = 'https://api.binance.com';
public function __construct(){
$this->secret = "1LZ.....................................Z";
$this->key = "rQ...................................................F80";
}
private function getSign($timestamp){
return hash_hmac('SHA256', $timestamp, $this->secret);
}
public function all_coins_address(){
$key = $this->key;
$secret = $this->secret;
$timestamp = time()*1000;
$prehash = "timestamp=$timestamp";
$sign = hash_hmac('SHA256', $prehash, $this->secret);
$url = $this->path_url."/sapi/v1/capital/deposit/address?coin=USDT×tamp=".$timestamp.'&signature='.$sign;
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_HTTPHEADER, array('X-MBX-APIKEY:'.$key));
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($ch, CURLOPT_URL, $url);
$result = curl_exec($ch);
$result = json_decode($result, true);
return $result;
}
}
$binance = new Binance();
print(’
’);
try{
print_r($binance->all_coins_address());
}catch (Exception $e){
print_r($e->getMessage());
}
exit(); ?>