-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfcmmessaging.php
55 lines (44 loc) · 1.35 KB
/
fcmmessaging.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
<?php
include_once"./dbconn.php";
$userID = $_POST['userID'];
$sheetID = $_POST['sheetID'];
function send_noti($token, $sheet, $title, $content)
{
$url = "https://fcm.googleapis.com/fcm/send";
$serverKey = "AIzaSyBYNiZKos0MRRsu7x9DZTyJbrS_DyXTaaM";
$fields = array(
"to" => $token,
"data" => array(
"title" => $title,
"text" => $content,
"sheetID" => $sheet
)
);
$headers = array(
'Authorization:key ='.$serverKey,
'Content-Type: application/json'
);
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt ($ch, CURLOPT_SSL_VERIFYHOST, 0);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($fields));
$result = curl_exec($ch);
if ($result === FALSE) {
die('Curl failed: ' . curl_error($ch));
}
curl_close($ch);
return $result;
}
$result = mysqli_query($conn,
"SELECT token_fcm from users
WHERE userID='$userID'"
) or die(mysqli_error($conn));
$token = mysqli_fetch_array($result)[0];
$title = "게시한 악보에 댓글이 달렸습니다";
$content = "확인하려면 터치하세요";
echo send_noti($token, $sheetID, $title, $content);
?>