-
Notifications
You must be signed in to change notification settings - Fork 1
/
Notification.php
105 lines (86 loc) · 3.59 KB
/
Notification.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
<?php
class Notification{
//*****************************************************************************************************
//************************************* class to send push notifications
//*****************************************************************************************************
function sendNotificationByTokens($title, $message, $tokens, $orderId, $status){
$path_to_firebase_cm = 'https://fcm.googleapis.com/fcm/send';
$fields = array(
'registration_ids' => $tokens,
'data' => array('title' => $title , 'body' => $message,
'icon'=> 'ic_stat_name',
'sound'=> 'default',
'color'=> '#F44336',
'tag'=>'nilo_notify_tag',
'image'=>'https://miro.medium.com/max/724/1*JbDo7U0l62vYMfm1WxnA1g.png',
'click_action'=> 'OPEN_ORDER',
'action_intent'=> '1',
'id'=> $orderId,
'status'=> $status),
'time_to_live' => 604800
);
$headers = array('Authorization:key=[your key of proyect in firebase/delete brackets]',
'Content-Type:application/json'
);
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $path_to_firebase_cm);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_IPRESOLVE, CURL_IPRESOLVE_V4 );
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($fields));
$result = curl_exec($ch);
if(!$result) {
$response["success"]=100;
$response["Error"]='Error: "' . curl_error($ch) . '" - Code: ' . curl_errno($ch);
} else {
$response["success"]=3;
$response["StatusCode"]= curl_getinfo($ch, CURLINFO_HTTP_CODE);
$response["message"]='Notificación enviada correctamente.';
$response["Response HTTP Body"]= " - " .$result ." -";
}
curl_close($ch);
return ($response);
}
function sendNotificationByTopics($title, $message, $topic, $photoUrl){
$path_to_firebase_cm = 'https://fcm.googleapis.com/fcm/send';
$fields = array(
'to' => "/topics/$topic",
'notification' => array(
'title' => $title ,
'body' => $message,
'icon'=> 'ic_stat_name',
'sound'=> 'default',
'color'=> '#F44336',
'tag'=>'nilo_notify_tag',
'image' => $photoUrl,
'click_action'=> 'OPEN_ORDER'),
'time_to_live' => 604800
);
$headers = array('Authorization:key=[your key of proyect in firebase/delete brackets]',
'Content-Type:application/json'
);
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $path_to_firebase_cm);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_IPRESOLVE, CURL_IPRESOLVE_V4 );
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($fields));
$result = curl_exec($ch);
if(!$result) {
$response["success"]=100;
$response["Error"]='Error: "' . curl_error($ch) . '" - Code: ' . curl_errno($ch);
} else {
$response["success"]=3;
$response["StatusCode"]= curl_getinfo($ch, CURLINFO_HTTP_CODE);
$response["message"]='Notificación enviada correctamente.';
$response["Response HTTP Body"]= " - " .$result ." -";
}
curl_close($ch);
return ($response);
}
}
?>