在这方面需要帮助......
我需要从 URL 的 API 调用中获取 json 数据。
它说调用需要..
- 内容类型:application/x-www-form-urlencoded
- HTTP 标头:密钥 ---> APIKEY
- HTTP HEADERS : sig ---> 带 SECRET KEY 的 POST 数据的 HMAC-SHA1 签名
- POST 参数:时间戳 ----> 当前 Unix 时间戳
我这样做正确吗?但是如何实现上面的第3点???
$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;
一直在为这件事摸不着头脑。请帮助我这个 PHP 新手。
最后我得到了它....
请参阅 $signature 部分。
$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;
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)