2017-09-14 5 views
1

나는 PHP 웹 사이트를 만들고있다. Firebase Cloud Messaging을 사용하기 위해 클라이언트 (내 웹 사이트에 로그인 한 사용자)에게 알림을 보내려합니다.PHP로 Firebase 대상을 얻는 방법은 무엇입니까?

이미 중포 기지 응용 프로그램을 등록하고 메시지를

public function sendMessage($data, $target) 
{ 
    //FCM api URL 
    $url = 'https://fcm.googleapis.com/fcm/send'; 
    //api_key available in Firebase Console -> Project Settings -> CLOUD MESSAGING -> Server key 
    $server_key = 'MY SERVER KEY'; 

    $fields = array(); 
    $fields['data'] = $data; 
    if (is_array($target)) { 
     $fields['registration_ids'] = $target; 
    } else { 
     $fields['to'] = $target; 
    } 
    //header with content_type api key 
    $headers = array(
     'Content-Type:application/json', 
     'Authorization:key=' . $server_key 
    ); 

    $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('FCM Send Error: ' . curl_error($ch)); 
    } 
    curl_close($ch); 
    return $result; 
} 

를 보낼 함수를 작성하지만 중포 기지가 메시지를 보낼 수 있도록 $target을 얻을하는 방법을 모르겠어요. 사용자 등록/내 웹 사이트에 로그인, 나는 중포 기지에서 token를 요청하고 내 DB에 저장할 때

enter image description here

는 이제합니다.

해당 사용자에게 메시지를 보내려면 Firebase의 대상 (토큰)을 제공해야합니다. 누구든지 날 도와 줘?

답변

0

처음에는 클라이언트에 firebase 프로젝트를 사용하는 응용 프로그램이 있어야합니다. 그런 다음 당신은 응용 프로그램에 모래 메시지 수, 당신은 그것을 할 수있는 2 가지 방법이 있습니다 당신은이

  • 스마트 폰에 대한 그의 응용 프로그램이 일부 항목에 등록해야 전 토큰 자신의 등록을 취득합니다. "일반".
+0

나는 정확히 당신이 말하는지 모르겠다. 나는 사용자가 내 웹 사이트에 등록 할 때 firebase에서 사용자 토큰을 얻고 싶습니다. 물론 내 웹 사이트의 토큰과 firebase의 토큰은 differrent입니다. – Jusfunny