-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathexample11_balancealert.php
52 lines (40 loc) · 1.43 KB
/
example11_balancealert.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
<?
// Example of howto check status of account in the 46elks service
// Change $username, $password to yout account values.
function checkBalance() {
// Set your 46elks API username and API password here
// You can find them at https://dashboard.46elks.com/
$username = 'u5a95663949bf505c072160c398445d16';
$password = 'D01BE1F79FEA298773B66C942873DF74';
$context = stream_context_create(array(
'http' => array(
'method' => 'GET',
'header' => "Authorization: Basic ".
base64_encode($username.':'.$password). "\r\n".
"Content-type: application/x-www-form-urlencoded\r\n",
'timeout' => 10
)));
$response = file_get_contents(
'https://api.46elks.com/a1/Me', false, $context );
if (!strstr($http_response_header[0],"200 OK"))
return $http_response_header[0];
return json_decode($response);
}
// Settings
// Email to send notification to:
$to = "[email protected]";
// Limit for sendning alert message:
$limit = 1000;
// Check balance
$accountdata = checkBalance();
// Change to real numbers:
$balance = $accountdata->balance/10000;
// Check if below limit.
if ($balance < $limit){
// Send notification e-mail, you could also send a reminder SMS, see example4_sendsms.php.
print mail (
$to,
"46elks account Balance low" ,
"Your account has a balance of: ".$balance." ".$accountdata->currency." to add more credits visit https://dashboard.46elks.com/");
}
?>