Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
293 views
in Technique[技术] by (71.8m points)

php - Send Header with HMacSha256 API Key

I am trying to send a header that is in this type of format:

 "method": "user.auth",
  "params": [
    "API",
    "806066b0-f02b-4d3e-b444-76ec718e1023",
    "8c939f7a6e6716ab7c4240384e07c81840dacd371cdcf5051bb6b7084897470e",
    1570091232
  ],
  "id": 1234
}

Where as the requirements are: type String Token type API

token String API Key

signature String Signature generated by a function as HMacSha256(API Key + expiry) with API Secret

expiry Integer A future time after which request will be rejected, in epoch second. Maximum expiry is request time plus 5 minutes

Currenrly the code I have is as such:

<?php
$url = "https://api.phemex.com/orders";
$curl = curl_init($url);
curl_setopt($curl, CURLOPT_URL, $url);
curl_setopt($curl, CURLOPT_POST, true);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
$headers = array(
   "accept: application/json",
   "X-API-Token: p0ACRCR1MIgg9GrPCkdBeSEE-nQGL4Lcm9s_Z5xtStAwMWM5OGRkYy0xMTVmLTQ3ZDgtOGNhZi05YjYzNWY3OWExODA",
   "Content-Type: application/json",
);
curl_setopt($curl, CURLOPT_HTTPHEADER, $headers);
$data = '{"clOrdId":"123456","ordType":"LIMIT","symbol":"BTC-USD","side":"BUY","orderQty":"0.1","price":"100"}';
curl_setopt($curl, CURLOPT_POSTFIELDS, $data);
//for debug only!
curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, false);
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
$resp = curl_exec($curl);
curl_close($curl);
var_dump($resp);
?>

This is as per the Phemex API https://github.com/phemex/phemex-api-docs/blob/master/Public-Contract-API-en.md#signatureexample3

question from:https://stackoverflow.com/questions/65874014/send-header-with-hmacsha256-api-key

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...