공부하는 소담아빠
안드로이드 PHP 푸시 서버 예제 본문
<?php
define("GOOGLE_API_KEY", "YOUR API KEY");
function sendNotificationAndroid ($tokens, $message, $bodys) {
$url = 'https://fcm.googleapis.com/fcm/send';
$fields = array(
'notification' => $bodys, // 푸시 알림 팝업을 띄우려면 이 항목을 주석처리
'registration_ids' => $tokens,
'priority' => 'high',
'data' => $message
);
$headers = array(
'Authorization:key =' . GOOGLE_API_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[] = 'mobile app push tokens';
$message = array("title" => "App Title", "body" => "App Contents");
$bodys = array("title" => "App Title", "body" => "App Contents", "icon" => "icon", "sound" => false);
$message_status = sendNotificationAndroid($tokens, $message, $bodys);
echo $message_status;
?>
'웹_서버_개발 > PHP' 카테고리의 다른 글
PHP configure 에러 (1) | 2017.08.23 |
---|