在这方面需要帮助....我需要从 URL 的 API 调用中获取 json 数据。它说调用需要..
- 内容类型:应用程序/x-www-form-urlencoded
- HTTP 标头:密钥 ---> APIKEY
- HTTP HEADERS : sig ---> 带有 SECRET KEY 的 POST 数据的 HMAC-SHA1 签名
- POST PARAMETER: timestamp ----> Current Unix Timestamp
这是我的代码...
$key = 'APIKEY';
$secret = 'APISECRET';
$timestamp = time();
$signature = hash_hmac('sha1', $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;
它给了我错误消息 {"error":"Invalid Signature!"}。有什么线索吗?