0
votes

I need help.

I'm trying connect a website by API, but it requests authentication. They show me example by C# but I want to change into PHP.

I use file_get_contents for getting data. How I have to send them in the HTML Header of my request with their name. How I make signature.

There is explaining of website. in sum can you convert C# to PHP please :)


API Authentication:

All API calls related to a user account require authentication.

You need to provide 3 parameters to authenticate a request:

"X-PCK": API key
"X-Stamp": Nonce
"X-Signature": Signature
API key

You can create the API key from the Account > API Access page in your exchange account.

Nonce:

Nonce is a regular integer number. It must be increasing with every request you make.

A common practice is to use unix time for that parameter.

Signature:

Signature is a HMAC-SHA256 encoded message. The HMAC-SHA256 code must be generated using a private key that contains a timestamp and your API key

Example (C#):

string message = yourAPIKey + unixTimeStamp;
using (HMACSHA256 hmac = new HMACSHA256(Convert.FromBase64String( yourPrivateKey ))){

   byte[] signatureBytes = hmac.ComputeHash(Encoding.UTF8.GetBytes(message));

   string X-Signature = Convert.ToBase64String(signatureBytes));
}

After creating the parameters, you have to send them in the HTML Header of your request with their name

Example (C#):

client.DefaultRequestHeaders.Add("X-PCK", yourAPIKey);
client.DefaultRequestHeaders.Add("X-Stamp", stamp.ToString());
client.DefaultRequestHeaders.Add("X-Signature", signature);
2
What php do you have so far? - Aluan Haddad
I have just started. i'm novice - ahmedov

2 Answers

0
votes

Use curl. Take an example like this: http://php.net/manual/de/function.curl-init.php

For the headers use something like that

curl_setopt($ch, CURLOPT_HTTPHEADER, array(
    '"X-PCK": API key',
    '"X-Stamp": Nonce',
    '"X-Signature": Signature'
));
0
votes

I think that you must use curl instead of file_get_contents.

Exemple :

// API Url
$url = 'http://';
// Put the value of parameters
$yourAPIKey = "";
$stamp = "";
$signature = "";

$ch = curl_init($url);
curl_setopt_array($ch, array(
    CURLOPT_HTTPHEADER  => array('X-PCK: '. $yourAPIKey, 'X-Stamp: '. $stamp, 'X-Signature: '. $signature),
    CURLOPT_RETURNTRANSFER  =>true,
    CURLOPT_VERBOSE     => 1
));
$response = curl_exec($ch);
curl_close($ch);
// echo response output
echo $response;