-
Notifications
You must be signed in to change notification settings - Fork 0
/
functions.php
114 lines (83 loc) · 2.73 KB
/
functions.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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
<?php
/* send request to API */
function info($config) {
$httpheader = http_headers($config);
$class = new APIREST($config['url']);
$result = $class -> call($httpheader, $config['method']);
return json_decode($result, TRUE);
}
/* send notification message to telegram bot */
function telegram($config) {
/*
show chat id (needs webhook disabled):
https://api.telegram.org/bot0000000000:xxx_API_KEY_xxx/getUpdates
Use $config['chatPath'] the HTTP API:
For a description of the Bot API, see this page: https://core.telegram.org/bots/api
for interactive bot
example: https://nordicapis.com/how-to-build-your-first-telegram-bot-using-php-in-under-30-minutes/
activate webhook:
https://api.telegram.org/bot0000000000:xxx_API_KEY_xxx/setwebhook?url=https://your.server.com/telegram.php
deactivate webhook:
https://api.telegram.org/bot0000000000:xxx_API_KEY_xxx/setwebhook?url=
*/
$httpheader = http_headers($config, TRUE);
$query =
$config['chatPath'] .
'/sendmessage?chat_id=' . $config['chatId'] .
'&parse_mode=html&text=' . $config['chatText']
;
$class = new APIREST($query);
$result = $class -> call($httpheader, $config['method']);
return json_decode($result, TRUE);
}
/* define http headers and parameters for exchange API */
function http_headers($config, $default = FALSE) {
if ($default) {
$httpheader = array(
'Accept: ' . $config['accept'],
'Content-Type: ' . $config['content_type']
);
} else {
switch ($config['exchange']) {
case 'bitmax':
$config['msg'] =
$config['timestamp'] .
'+' .
$config['api_request']
;
$config['signature'] = hmac($config['msg'], $config['secret']);
$httpheader = array(
'Accept: ' . $config['accept'],
'Content-Type: ' . $config['content_type'],
'x-auth-key: ' . $config['api_key'],
'x-auth-signature: ' . $config['signature'],
'x-auth-timestamp: ' . $config['timestamp']
);
break;
case 'okex':
#$timestamp = date('Y-m-d\TH:i:s.000', $config['timestamp'] / 1000) . 'Z'; # ISO 8601 standard format with Z
$config['msg'] =
(string) $config['timestamp'] .
$config['method'] .
$config['api_request']
;
$config['signature'] = hmac($config['msg'], $config['secret']);
$httpheader = array(
'Accept: ' . $config['accept'],
'Content-Type: ' . $config['content_type'],
'ok-access-key: ' . $config['api_key'],
'ok-access-sign: ' . $config['signature'],
'ok-access-timestamp: ' . $config['timestamp'] / 1000,
'ok-access-passphrase: ' . $config['pass']
#'OK-TEXT-TO-SIGN: ' . $config['msg']
);
break;
default:
$httpheader = array(
'Accept: ' . $config['accept'],
'Content-Type: ' . $config['content_type']
);
}
}
return $httpheader;
}