· 7 years ago · Mar 01, 2018, 06:46 PM
1<?php
2function btcid_query($method, array $req = array()) {
3 // API settings
4 $key = ''; // your API-key
5 $secret = ''; // your Secret-key
6 $req['method'] = $method;
7 $req['nonce'] = time();
8
9 // generate the POST data string
10 $post_data = http_build_query($req, '', '&');
11 $sign = hash_hmac('sha512', $post_data, $secret);
12 // generate the extra headers
13 $headers = array(
14'Sign: '.$sign,
15'Key: '.$key,
16 );
17 // our curl handle (initialize if required)
18 static $ch = null;
19 if (is_null($ch)) {
20 $ch = curl_init();
21 curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
22 curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/4.0 (compatible;
23BITCOINCOID PHP client; '.php_uname('s').'; PHP/'.phpversion().')');
24 }
25 curl_setopt($ch, CURLOPT_URL, 'https://vip.bitcoin.co.id/tapi/');
26 curl_setopt($ch, CURLOPT_POSTFIELDS, $post_data);
27 curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
28 curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
29
30 // run the query
31 $res = curl_exec($ch);
32 if ($res === false) throw new Exception('Could not get reply:
33'.curl_error($ch));
34 $dec = json_decode($res, true);
35 if (!$dec) throw new Exception('Invalid data received, please make sure
36connection is working and requested API exists: '.$res);
37
38 curl_close($ch);
39 $ch = null;
40 return $dec;
41}
42$result = btcid_query('getInfo');
43print_r($result);