-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsendNotification.php
100 lines (86 loc) · 3.29 KB
/
sendNotification.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
<?PHP
function sendMessage(){
$url = "http://nammabagalkot.in/cryptboard/callExchanges.php";
$responseData = file_get_contents($url);
$responseData = json_decode($responseData);
// $lastFetchData = getLastPrice();
$message = "";
foreach ($responseData as $key => $value) {
$name = $value->name;
if($name=="koinex"){
// $message.="Koinex\n";
$message.="BTC".": ".$value->btc->buy."\n";
$message.="BCH".": ".$value->bch->buy."\n";
$message.="ETH".": ".$value->eth->buy."\n";
$message.="XRP".": ".$value->xrp->buy."\n";
// $message.="LTC".":".$value->ltc->buy."\n";
}else{
// $message.=$name.": ".$value->buy."\n";
}
// if(array_key_exists($name, $lastFetchData)){
// $difference = $value->buy - $lastFetchData[$name];
// // echo $value->buy;
// // echo "-".$lastFetchData[$name]."<br/>";
// $value->lastPrice = $lastFetchData[$name];
// $value->difference = $difference;
// $message.=$name.":".$value->buy."";
// }
}
var_dump($message);
$content = array(
"en" => $message
);
$fields = array(
'app_id' => "7334a009-9ce6-491b-9e3b-223d839d6c65",
'included_segments' => array('All'),
'filters' => array(array("field" => "tag", "key" => "periodic", "relation" => "not_exists")),
'chrome_web_icon' =>"http://nammabagalkot.in/cryptboard/img/push_icob.png",
'contents' => $content,
'url' => "http://nammabagalkot.in/cryptboard"
);
$fields = json_encode($fields);
print("\nJSON sent:\n");
print($fields);
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "https://onesignal.com/api/v1/notifications");
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/json; charset=utf-8',
'Authorization: Basic YzE2NTRmYTktZGE3MC00NWY2LThiYjAtYTA1MzdkNTA3NTRh'));
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
curl_setopt($ch, CURLOPT_HEADER, FALSE);
curl_setopt($ch, CURLOPT_POST, TRUE);
curl_setopt($ch, CURLOPT_POSTFIELDS, $fields);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
$response = curl_exec($ch);
curl_close($ch);
return $response;
}
$response = sendMessage();
$return["allresponses"] = $response;
$return = json_encode( $return);
print("\n\nJSON received:\n");
print($return);
print("\n");
function getLastPrice(){
$properties = parse_ini_file("./php.ini", "true") or die("Could not find ini file");
$exhangesPropertyFile = $properties['exchanges'];
$exchanges = [];
foreach ($exhangesPropertyFile as $e) {
$exchanges[] = explode(",", $e)[0];
}
date_default_timezone_set('Asia/Kolkata');
$date = date('m_d_Y', time());
$time_stamp = date('m/d/Y H:i:s', time());
$lastFetchData = [];
foreach ($exchanges as $exchange) {
$fileToday = "data/" . $date ."_". $exchange."_price.txt";
if (file_exists($fileToday)) {
$fileData = file_get_contents($fileToday);
$fileDataLines = explode("\n", $fileData);
$lastLine = $fileDataLines[count($fileDataLines)-2];
$lastPrice = explode(",", $lastLine)[1];
$lastFetchData[$exchange] = $lastPrice;
}
}
return $lastFetchData;
}
?>