PHP Curl HMAC-SHA1

后端 未结 1 1281
轮回少年
轮回少年 2021-01-07 12:12

Need help on this .... I need to get json data from API call from a URL. It said the called need..

  1. Content-Type : application/x-www-form-urlencoded
  2. HT
相关标签:
1条回答
  • 2021-01-07 12:32

    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;
    
    0 讨论(0)
提交回复
热议问题