Skip to content

Instantly share code, notes, and snippets.

@alangrainger
Created May 8, 2019 09:58
Show Gist options
  • Save alangrainger/608cf45c21055488f6f4ec4e245ed549 to your computer and use it in GitHub Desktop.
Save alangrainger/608cf45c21055488f6f4ec4e245ed549 to your computer and use it in GitHub Desktop.
Signed OKEX requests with CURL and PHP
$time = round(microtime(true), 3);
$method = strtoupper($method);
$string = $time . $method . $endpoint;
$hash = hash_hmac('sha256', $string, $secret);
$hash = base64_encode(hex2bin($hash));
$curl = curl_init();
curl_setopt_array($curl, array(
CURLOPT_URL => 'https://www.okex.com' . $endpoint,
CURLOPT_RETURNTRANSFER => true,
CURLOPT_TIMEOUT => 10,
CURLOPT_CUSTOMREQUEST => $method,
CURLOPT_HTTPHEADER => array(
"OK-ACCESS-KEY: " . $apiKey,
"OK-ACCESS-SIGN: $hash",
"OK-ACCESS-TIMESTAMP: $time",
"OK-ACCESS-PASSPHRASE: " . $passphrase
)
));
$result = curl_exec($curl);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment