FCM PHP함수로 푸시 보내기
페이지 정보
작성자 JMStudy 작성일19-11-21 17:57 조회4,008회 댓글0건본문
function send_notification($tokens, $message) {
$url = 'https://fcm.googleapis.com/fcm/send';
if ($message) {
$fields = array (
'notification' => array ('body' => $message['body'], 'title' => $message['title'])
);
}
if(is_array($tokens)) {
$fields['registration_ids'] = $tokens;
} else {
$fields['to'] = $tokens;
}
$fields['priority'] = "high";
$FCM_SERVER_KEY = "";
$headers = array(
'Authorization:key =' . $FCM_SERVER_KEY,
'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;
}
$tokens = "사용자토큰키";
$message = array(
"title" => "알림제목",
"body" => "알림내용",
);
send_notification($tokens, $message);
댓글목록
등록된 댓글이 없습니다.