Need help on this .... I need to get json data from API call from a URL. It said the called need..
- Content-Type : application/x-www-form-urlencoded
- HTTP HEADERS : key ---> APIKEY
- HTTP HEADERS : sig ---> HMAC-SHA1 signature of POST Data with SECRET KEY
- POST PARAMETER: timestamp ----> Current Unix Timestamp
Do I do this correctly? But how to implement point 3 above???
$key = 'APIKEY';
$secret = 'APISECRET';
$signature = '';
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "https://www.domain.com/getticker");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
curl_setopt($ch, CURLOPT_HEADER, FALSE);
curl_setopt($ch, CURLOPT_POST, TRUE);
curl_setopt($ch, CURLOPT_POSTFIELDS, "timestamp=".time());
curl_setopt($ch, CURLOPT_HTTPHEADER, array("Content-Type: application/x-www-form-urlencoded","key: ".$key,"sig: ".$signature));
$response = curl_exec($ch);
curl_close($ch);
echo $response;
Been scratching my head over this. please help me this newbie on PHP.
Finally I got it.... see the $signature part.
$key = 'APIKEY';
$secret = 'APISECRET';
$timestamp = time();
$signature = hash_hmac('sha1', "timestamp=".$timestamp, $secret);
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "https://www.domain.com/getticker");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
curl_setopt($ch, CURLOPT_HEADER, FALSE);
curl_setopt($ch, CURLOPT_POST, TRUE);
curl_setopt($ch, CURLOPT_POSTFIELDS, "timestamp=".time());
curl_setopt($ch, CURLOPT_HTTPHEADER, array("Content-Type: application/x-www-form-urlencoded","key: ".$key,"sig: ".$signature));
$response = curl_exec($ch);
curl_close($ch);
echo $response;
来源:https://stackoverflow.com/questions/22326050/php-curl-hmac-sha1