forked from bednart/excoin-php-api-example
-
Notifications
You must be signed in to change notification settings - Fork 0
/
excoin.php
79 lines (61 loc) · 2.21 KB
/
excoin.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
<?php
class Excoin {
private $url;
private $apiKey;
private $apiSecret;
public function __construct($url, $apiKey, $apiSecret)
{
$this->url = $url;
$this->apiKey = $apiKey;
$this->apiSecret = $apiSecret;
}
/**
* Call Excoin API using nonce.
**/
public function getNonceResult()
{
// build message
$nonce = time();
$message = $nonce . $this->url;
// sign message
$sign = hash_hmac('sha256', $message, $this->apiSecret);
// open session
$session = curl_init($this->url);
// set options
curl_setopt($session, CURLOPT_HTTPHEADER, array('Api-Key: ' . $this->apiKey, 'Api-Signature: ' . $sign, 'Api-Nonce: ' . $nonce));
curl_setopt($session, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($session, CURLOPT_SSL_VERIFYHOST, false);
curl_setopt($session, CURLOPT_RETURNTRANSFER, true);
// get result
$result = curl_exec($session);
// close session
curl_close($session);
// return result as JSON object
return json_decode($result, true);
}
/**
* Call Excoin API using timestamp.
*/
public function getTimestampResult()
{
// build url - request will be valid for next 15 minutes (900 seconds)
$expire = time() + 900;
$url = $this->url . '?expire=' . $expire;
// sign url
$sign = hash_hmac('sha256', $url, $this->apiSecret);
// open session
$session = curl_init($url);
// set options
curl_setopt($session, CURLOPT_HTTPHEADER, array('Api-Key: ' . $this->apiKey, 'Api-Signature: ' . $sign));
curl_setopt($session, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($session, CURLOPT_SSL_VERIFYHOST, false);
curl_setopt($session, CURLOPT_RETURNTRANSFER, true);
// get result
$result = curl_exec($session);
// close session
curl_close($session);
// return result as JSON object
return json_decode($result, true);
}
}
?>