PHP curl hash_hmac
在这方面需要帮助。。。。我需要从URL的API调用中获取json数据。它说,需要PHP curl hash_hmac,php,curl,hmacsha1,Php,Curl,Hmacsha1,在这方面需要帮助。。。。我需要从URL的API调用中获取json数据。它说,需要 内容类型:application/x-www-form-urlencoded HTTP头:键-->APIKEY HTTP头文件:sig-->HMAC-SHA1带有密钥的POST数据签名 POST参数:timestamp-->当前Unix时间戳 这是我的密码 $key = 'APIKEY'; $secret = 'APISECRET'; $timestamp = time(); $signature = hash
$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!”}。
有什么线索吗
$key = 'APIKEY';
$secret_key = 'APISECRET';
$timestamp = time();
$signature = hash_hmac('sha1', $timestamp, $secret);
应该是
$signature = hash_hmac('sha1', $timestamp, $secret_key);
您的$secret未定义。除非您只是没有粘贴它,否则将导致错误{“错误”:“无效签名!”}您可以更改
curl_setopt($ch,CURLOPT_POSTFIELDS,“timestamp=.time())
tocurl_setopt($ch,CURLOPT_POSTFIELDS,“timestamp=”.$timestamp)
以发布签名中使用的相同值。事实上,签名是错误的,您定义了$secret\u key
,但使用$secret
进行散列<代码>$signature=hash_hmac('sha1',$timestamp,$secret_key)我提出第一个问题,好像没人回答一样。所以我试了第二个。对此我很抱歉。我只是需要尽快修复这个代码。哎呀,我的错。实际上在我的代码中它是$secret。不是$secret\u密钥。我再次编辑了这个问题,以反映我在代码中所做的事情。你到底在使用哪个api?它来自fybsg.com。该文档位于公共API上,不是问题。私人的那个让我头疼。我想使用API函数getaccinfo。