【发布时间】:2018-05-28 03:09:11
【问题描述】:
我不知道其中发生了什么,但我正在尝试使用 API,他们还有另一个不同的身份验证标准,称为 HMAC,带有 Sha384 到 base64。
这是提供的示例:
class ICObenchAPI {
private $privateKey = 'private-key';
private $publicKey = 'public-key';
private $apiUrl = 'https://icobench.com/api/v1/';
public $result;
public function getICOs($type = 'all', $data = ''){
return $this->send('icos/' . $type, $data);
}
public function getICO($icoId, $data = ''){
return $this->send('ico/' . $icoId, $data);
}
public function getOther($type){
return $this->send('other/' . $type, '');
}
private function send($action, $data){
$dataJson = json_encode($data);
$sig = base64_encode(hash_hmac('sha384', $dataJson, $this->privateKey, true));
$ch = curl_init($this->apiUrl . $action);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
curl_setopt($ch, CURLOPT_POSTFIELDS, $dataJson);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
'Content-Type: application/json',
'Content-Length: ' . strlen($dataJson),
'X-ICObench-Key: ' . $this->publicKey,
'X-ICObench-Sig: ' . $sig)
);
$reply = curl_exec($ch);
$ff = $reply;
$reply = json_decode($reply,true);
if(isset($reply['error'])){
$this->result = $reply['error'];
return false;
}else if(isset($reply['message'])){
$this->result = $reply['message'];
return true;
}else if(isset($reply)){
$this->result = json_encode($reply);
return true;
}else{
$this->result = htmlspecialchars($ff);
return false;
}
}
public function result(){
return $this->result;
}
}
我正在寻找提供的 PHP 示例并将其转换为 nodeJS 脚本,只是真的不知道从哪里开始。我看过crypto-js和其他人,但只是不理解我什至在写的请求中具体发生了什么
【问题讨论】:
标签: php node.js base64 sha hmac