2017-04-24 3 views
0

firebase를 사용하여 웹에서 푸시 알림을 보내고 있지만 이름 만 얻는 동안 푸시 알림을 보낼 수 없습니다. firebase를 사용하여 웹에서 푸시 알림을 보내려면 어떻게해야합니까?firebase를 사용하여 웹에서 푸시 알림을 전송합니다.

이것은 내 PHP 코드입니다.

<?php 
$DEFAULT_URL = 'https://pushnotificatioexample.firebaseio.com/.json'; 

$mytoken = $_POST['token']; 
$mymessage = $_POST['message']; 
echo $mytoken; 
echo '<br>'.'</br>'; 
echo $mymessage; 

$registrationIds = array($mytoken); 

$message = array 
     (
     'message' => 'My awesome message', 
     'title'  => 'My awesome title', 
     'subtitle' => 'My awesome subtitle', 
     'tickerText' => 'My awesome Ticker text', 
     'vibrate' => 1, 
     'sound'  => 1, 
     'largeIcon' => 'large_icon', 
     'smallIcon' => 'small_icon' 
     ); 

     $fields = array(
     'registration_ids' => $registrationIds, 
     'data' => $message 
     ); 

     $headers = array(
     'Authorization:key = AIzaSyC9M4KFwqdy3vjcIBx9TNO8M7IysADbY_s', 
     'Content-Type: application/json' 
     ); 

     $ch = curl_init(); 
     curl_setopt($ch, CURLOPT_URL, $DEFAULT_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); 
     echo $result; 
?> 
+0

당신은 FCM의 엔드 포인트를 ('사용하지 않을해야 HTTPS : // fcm.googleapis.com/fcm/send') 대신 'https : // pushnotificatioexample.firebaseio.com/.json'을 사용할 수 있습니까? –

답변

0

서비스 쪽 스크립트에서 전송 한 것처럼 보입니다. Firebase (FCM) 공식 문서에 따르면 Realtime 데이터베이스와 모든 URL의 URL을 사용할 필요가 없습니다. 그래서 당신은

에서

$DEFAULT_URL = 'https://pushnotificatioexample.firebaseio.com/.json'; 

TO

$DEFAULT_URL = 'https://fcm.googleapis.com/fcm/send'; 

은 자세한 내용은 Firebase Cloud Messaging HTTP Protocolhere 참조하여 URL을 변경해야

+0

고마워요. – romil

+0

이걸 알면 다행입니다. 친절하게 대답을 표시하고 upvote. 그래서 다른 사람들에게 도움이 될 것입니다. –

관련 문제