问题描述
我想让这个 HMAC 请求起作用。但是 api 的响应是:
Array
(
[ResultCode] => 401
[ResultMessage] => Unauthorized request
[ResultDetails] => Public Key required
)
api 的文档要求:
POST https://<endpoint>/<version>/course HTTPS/1.1
InstellingsNr: 999999,999998
Timestamp: 2014-10-01T00:00:00.000Z
Authentication: 411bd3009903c241cd2318c:d87fcd241d20478f2ff06dc32ccfda6d9 Accept: application/json
Content-Type: application/json Content-Length: 87
{
"schoolYear": "2014-15","startDate": "2014-10-01T00:00:00.000Z","endDate": ""
}
好像不行。这是我第一次处理 HMAC 请求,所以这对我来说是新的。 我的代码是(PHP):
<?PHP
function ifr_query($path,array $req = Array()) {
$key='MY_PUBLIC_KEY';
$secret='MY_SECRET_KEY';
$mt = explode(' ',microtime());
$nonce = $mt[1].substr($mt[0],2,6);
if ($req) {
$get=httpbuildquery($req);
$path=$path.'?'.$get;
}
$postdata=$nonce.$key.$path;
$sign = strtoupper(hash_hmac('sha256',$postdata,$secret));
$headers = array(
'Authentication:'.$sign,'Timestamp:'.$key,'InstellingsNr:'. '999999,999998','Accept:' . 'application/json','Content-Type:' . 'application/json','Apiauth-Nonce:'.$nonce
);
$ch = null;
$ch = curl_init('https://myendpointurl.be'.$path);
curl_setopt($ch,CURLOPT_RETURNTRANSFER,true);
curl_setopt($ch,CURLOPT_HTTPHEADER,$headers);
curl_setopt($ch,CURLOPT_SSL_VERIFYPEER,TRUE);
curl_setopt($ch,CURLOPT_CONNECTTIMEOUT,20);
$res = curl_exec($ch);
if ($res === false) throw new Exception('Curl error: '.curlerror($ch));
$dec = json_decode($res,true);
if (!$dec) throw new Exception('Invalid data: '.$res);
curl_close($ch);
return $dec;
}
$getinfo = array();
$devise = "EUR";
$url = "/course";
$getinfo = ifr_query($url);
echo "<pre>"; print_r($getinfo); echo "</pre>";
?>
有人可以帮我解决这个问题吗?
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)