2017-02-11 1 views
0

Google에서 FCM은 무료라고합니다. 이게 무슨 뜻 이니? 아무도 그것을 설명 할 수 있습니까?firebase 클라우드 메시징 (앱 클라이언트 사용)

enter image description here

registration_ids :

이 파라미터는 멀티 캐스트 메시지를 수신하는 장치 목록 (등록 토큰, IDS 등)를 지정한다. 등록 토큰은 1 개 이상 1000 개 이하 여야합니다.

최대 1000? 2000 명의 사용자 (토큰)가 있으면 어떻게됩니까?

하나 더 문제가 있습니다. 내 PHP 스크립트에서 몇 가지 실수가있다, 난 단지 하나의 토큰 (찍은에서 최상위 행 토큰), plse 체크 내 send.php를 보낼 수 있습니다 :

테이블은 토큰의 목록과 간단한 하나의 열입니다.

<?php 
require "info.php"; 
$message = $_POST["message"]; 
$title = $_POST["title"]; 
$path_to_fcm = "https://fcm.googleapis.com/fcm/send"; 
$server_key = "*******************************"; 
$sql="select token from fcm"; 
$result = mysqli_query($con,$sql); 
$column = mysqli_fetch_row($result); 

$key=$column[0]; 

$headers=array('Authorization:key=' .$server_key, 
'content-Type:application/json'); 

$fields=array('registration_ids'=>$key, 
'notification'=>array('title'=>$title,'body'=>$message)); 

$payload = json_encode($fields); 
$curl_session = curl_init(); 
curl_setopt($curl_session, CURLOPT_URL, $path_to_fcm); 
curl_setopt($curl_session, CURLOPT_POST, true); 
curl_setopt($curl_session, CURLOPT_HTTPHEADER, $headers); 
curl_setopt($curl_session, CURLOPT_RETURNTRANSFER, TRUE); 
curl_setopt($curl_session, CURLOPT_SSL_VERIFYPEER, false); 
curl_setopt($curl_session, CURLOPT_IPRESOLVE, CURL_IPRESOLVE_V4); 
curl_setopt($curl_session, CURLOPT_POSTFIELDS, $payload); 
$result=curl_exec($curl_session); 
curl_close($curl_session); 
mysqli_close($con); 
?> 

제 프로젝트에 골머리를 앓습니다.

+1

게시물 당 하나의 질문으로 제한하십시오. –

답변

0

예 FCM 서비스에는 Firebase를 무료로 사용할 수 있습니다.

registration_ids는 귀하의 앱이 Firebase를 사용하는 경우 기기 (모바일)에서 생성되어 서버로 전송되는 ID입니다.

Firebase는 해당 ID를 사용하여 모든 유형의 알림을 장치 수에 보냅니다.

public class MyFirebaseInstanceIDService extends FirebaseInstanceIdService { 

    private static final String TAG = "MyFirebaseIIDService"; 

    /** 
    * Called if InstanceID token is updated. This may occur if the security of 
    * the previous token had been compromised. Note that this is called when the InstanceID token 
    * is initially generated so this is where you would retrieve the token. 
    */ 
    // [START refresh_token] 
    @Override 
    public void onTokenRefresh() { 
     // Get updated InstanceID token. 
     String refreshedToken = FirebaseInstanceId.getInstance().getToken(); 
     Log.d(TAG, "Refreshed token: " + refreshedToken); 

     // TODO: Implement this method to send any registration to your app's servers. 
     sendRegistrationToServer(refreshedToken); 
    } 
    // [END refresh_token] 

    /** 
    * Persist token to third-party servers. 
    * 
    * Modify this method to associate the user's FCM InstanceID token with any server-side account 
    * maintained by your application. 
    * 
    * @param token The new token. 
    */ 
    private void sendRegistrationToServer(String token) { 
     // Add custom implementation, as needed. 
    } 
} 
1

다음 예제를 검토하고 FCM 서버로 전송 된 매개 변수도주의하십시오. 'to', 'notification', 'data'와 같음

$registrationIds=array(); 

//select user RegistrationIDs/Token from DB 
$con=mysqli_connect("localhost","my_user","my_password","my_db"); 
$sql="SELECT `reg_id` from users;"; 
$result=mysqli_query($con,$sql); 
while($row = mysqli_fetch_assoc($result)) { 
    array_push($registrationIds,$row["reg_id"]); 
} 
mysqli_close($con); 


$msg = array(
    'body' => "My First Blog Description", 
    'title' => "My First Blog" 
); 

$noti_key='YOUR_FCM_REGISTRATION_KEY'; 

$registrationIds_chunk=array_chunk($registrationIds,1000); 
foreach($registrationIds_chunk as $single_chunk){ 
    if(count($single_chunk)==1){ 
     $fields = array 
     (
      'to'=>$single_chunk[0], 
      'notification'=> $msg 
     ); 
    }else{ 
     $fields = array 
     (
      'registration_ids'=>$single_chunk, 
      'notification'=> $msg 
     ); 
    } 

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

    $ch = curl_init(); 
    curl_setopt($ch,CURLOPT_URL, 'https://fcm.googleapis.com/fcm/send'); 
    curl_setopt($ch,CURLOPT_POST, true); 
    curl_setopt($ch,CURLOPT_HTTPHEADER, $headers); 
    curl_setopt($ch,CURLOPT_RETURNTRANSFER, true); 
    curl_setopt($ch,CURLOPT_SSL_VERIFYPEER, false); 
    curl_setopt($ch,CURLOPT_POSTFIELDS, json_encode($fields, true)); 
    $result = curl_exec($ch); 
    curl_close($ch); 
} 
+0

Plse는 주어진 매개 변수로 위의 코드를 다시 작성합니다. 개발자가 아니기 때문에 혼란 스럽습니다. $ 토큰 토큰 PLSE PLSE – wangz

+0

@wangz 검토하시기 바랍니다 편집을 얻기 위해 $ 제목 $ 메시지 (아무 통지와 함께 추가 데이터를 전달해야하는) 사용 데이터베이스 (PLSE 1 열 토큰 table_name 테이블의 FCM에서 추출). –

+0

plse는 $ data를 제외합니다 (데이터를 보내지 않습니다). 대신 $ title (알림 제목)을 포함합니다 .. – wangz

관련 문제