LocalBitcoins.com Making requests to the API PHP example

$hmac_key = 'your hmac key';
$hmac_secret = 'your secret';
$search = array('.');
$replace= array('');
$mt = microtime(true);
$mt = str_replace($search,$replace,$mt);
$nonce = $mt;
$api_endpoint = '/api/myself/';
$url = 'https://localbitcoins.com'.$api_endpoint;
$get_or_post_params_urlencoded = '';
$message = $nonce . $hmac_key . $api_endpoint . $get_or_post_params_urlencoded;
$message_bytes = utf8_encode($message);
$signature = mb_strtoupper( hash_hmac( 'sha256', $message_bytes, $hmac_secret ) );
$ch = curl_init('https://localbitcoins.com'.$api_endpoint);
$options = array(
CURLOPT_RETURNTRANSFER => 1,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTPHEADER =>   array(
'Apiauth-Key:'.$hmac_key,
'Apiauth-Nonce:'.$nonce,
'Apiauth-Signature:'.$signature
),
);
curl_setopt_array($ch, $options);
$result = curl_exec($ch);
curl_close($ch);
echo $result;

Deja un comentario