$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; #### #!/usr/bin/perl -w BEGIN { print "Content-type: text/plain\n\n"; } use LWP::UserAgent; use Time::HiRes qw(gettimeofday); use Digest::SHA qw(sha256); use URI; use URI::QueryParam; use CGI::Carp qw(fatalsToBrowser); my $uri = URI->new(); my $nonce = int (gettimeofday * 1000); $url = "https://localbitcoins.com"; $api_endpoint = "/api/merchant/new_invoice/"; $hmac_key = "sfsdfdsfdsfsdf"; $hmac_secret = "fsdfdsfdsfd"; %params = ( currency => 'USD', amount => '500', description => 'HEY', internal => '0', ); $uri->query_param($_, $params{$_}) for keys %params; $post_params_urlencoded = $uri->query; $message = ($nonce.$hmac_key.$api_endpoint.$post_params_urlencoded); my $signature = unpack("H*", sha256($message, $hmac_secret)); my $ua = LWP::UserAgent->new; my $res = $ua->post( $url.$api_endpoint, "Apiauth-Key" => "$hmac_key", "Apiauth-Nonce" => "$nonce", "Apiauth-Signature" => "$signature", ); if ($res->is_success) { print $res->content; } else { print $res->status_line, "\n"; }