-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathphp_api_script.php
81 lines (72 loc) · 2.87 KB
/
php_api_script.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
80
81
<?php
/**
* ZaifへのリクエストをプリキシするAPI
* @author masaharuKomuro
*/
class Controller_Api_Zaif extends Controller
{
public function get_index ( $api = null, $currency_pair = 'all' ) {
try {
$result = file_get_contents('https://api.zaif.jp/api/1/' . $api . '/' . $currency_pair);
}
catch ( \Exception $e) {
$response = new Response( 'error', 500 );
$response->set_header('Access-Control-Allow-Origin', '*');
$response->set_header('Content-Type', 'application/json; charset=utf-8');
return $response;
}
$response = new Response( $result );
$response->set_header('Access-Control-Allow-Origin', '*');
$response->set_header('Content-Type', 'application/json; charset=utf-8');
return $response;
}
public function post_index ( $api = null ) {
$key = "{{ YOUR_API_KEY }}";
$secret = "{{ YOUR_SECRET_KEY }}";
$url = "https://api.zaif.jp/tapi";
$nonce = $result = \Db::insert('nonce')
->set(['dust' => 'a'])
->execute('coin_writer')[0];
// POSTデータ
$data = array(
'method' => $api,
'nonce' => $nonce
);
if ($_POST) {
$data = array_merge($_POST, $data);
}
$sign = hash_hmac('sha512', http_build_query($data), $secret); // パラメータをsha512で暗号化
$data = http_build_query($data, "", "&");
// header
$header = array(
"Content-Type: application/x-www-form-urlencoded",
"Content-Length: ".strlen($data),
"key: ".$key,
"sign: ".$sign
);
$context = array(
"http" => array(
"method" => "POST",
"header" => implode("\r\n", $header),
"content" => $data
)
);
try {
$response = file_get_contents($url, false, stream_context_create($context));
}
catch (\Exception $e) {
$response = new Response( 'error', 500 );
$response->set_header('Access-Control-Allow-Origin', '*');
$response->set_header('Content-Type', 'application/json; charset=utf-8');
return $response;
}
$response = new Response( $response );
$response->set_header('Access-Control-Allow-Origin', '*');
$response->set_header('Content-Type', 'application/json; charset=utf-8');
return $response;
}
public function action_test() {
phpinfo();
var_dump('a');exit;
}
}