gpt4 book ai didi

PHP 生成 HMAC-SHA1 签名

转载 作者:搜寻专家 更新时间:2023-10-31 21:03:22 25 4
gpt4 key购买 nike

这让我发疯。

我正在尝试按照此处的建议生成签名:https://www.reed.co.uk/developers/SignatureTest

这样:

function createSignature($queryUrl, $timestamp, $apiKey, $http = "GET", $agent = "Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 6.0)"){
$signature = $http . $agent . $queryUrl . "www.reed.co.uk" . $timestamp;
$signature = base64_encode(hash_hmac("sha1", $signature, $apiKey, true));
return $signature;
}


$clientId = 1;
$timestamp = "2016-05-13T09:22:50Z";

$apiKey = "bacd2d2d-8b69-43c8-94c5-4a24c0269b79";

$queryUrl = "https://www.reed.co.uk/recruiter/api/1.0/cvsearch";

$reedQuery = \Httpful\Request::get($queryUrl)
->addHeaders(array(
"X-ApiSignature" => createSignature($queryUrl, $timestamp, $apiKey),
"X-ApiClientId" => $clientId,
"X-TimeStamp" => $timestamp
))
->expectsJson()
->send();


print_r($reedQuery);

现在由于某些原因它在我的服务器上返回了这个:WRTjqQKfyEQyLJEzWWuT3SWgGPk=虽然预期结果是:JUgvCh5oeFYe1HDmfiMObOu1+nQ=

我什么都试过了,甚至从小端换到大端。什么都没有。

怎么了??? :(

最佳答案

我遇到了同样的问题;解决方案是 posted here在不同的问题下。

问题是字符串键 (GUID) 需要在前 3 个段 ( http://msdn.microsoft.com/en-us/library/system.guid.tobytearray.aspx ) 中颠倒 2 个字符的十六进制数的顺序。

创建哈希的示例(使用上面的 key ):

$apiToken = 'bacd2d2d-8b69-43c8-94c5-4a24c0269b79';
$stringToSign = 'POSTReedAgenthttps://www.reed.co.uk/recruiter/api/1.0/jobswww.reed.co.uk2017-11-11T13:50:06+00:00';
$hexStr = str_replace('-','',$apiToken);
$c = explode('-',chunk_split($hexStr,2,'-'));
$hexArr = array($c[3],$c[2],$c[1],$c[0],$c[5],$c[4],$c[7],$c[6],$c[8],$c[9],$c[10],$c[11],$c[12],$c[13],$c[14],$c[15]);
$keyStr = '';
for ($i = 0; $i < 16; ++$i) {
$num = hexdec($hexArr[$i]);
$keyStr .= chr($num);
}
$apiSignature = base64_encode(hash_hmac('sha1',$stringToSign,$keyStr,true));

这会生成一个与 Signature Test 中的哈希相匹配的哈希.

关于PHP 生成 HMAC-SHA1 签名,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37207221/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com