2

通知でアプリを作成しようとしています。通知はphpファイルからfirebaseに送信し、次にデバイスに送信する必要があります。最初はfirebase consoleで送信しようとしましたが、完璧に動作します。しかし、私はPHPを使用してnotificaionを送信しようとすると、私は問題があります。それは正常に送信されたが、私は通知を受け取っていないと言う。通知を送信するために私のPHPがあります:ios-firebaseで通知を送信する

<?php 
function send_notification ($tokens, $message) 
{ 

    $url = 'https://fcm.googleapis.com/fcm/send'; 
    $fields = array(
     'to' => $tokens, 
     'data' => $message 
     ); 
    $headers = array(
     'Authorization:key = my 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; 
} 

$data = array("alert" => "How it is going today"); 
$token = "fJVM7YrWGQg......"; 


$message = array("message" => " FCM PUSH NOTIFICATION TEST MESSAGE"); 
$message_status = send_notification($token, $message); 
echo $message_status; 

>

それを修正するために私が検索しました?。しかし何も助けなかった。

答えて

2

誰もが解決策を見つけました。誰か助けてくれると助かります:

// API access key from Google API's Console 
define('API_ACCESS_KEY', 'YOUR_FIREBASE_API_KEY'); 
$registrationIds = array("devices firebasetoken here."); 
// prep the bundle 
$msg = array(
     'body' => "message text", 
     'title'  => "message title", 
     'vibrate' => 1, 
     'sound'  => 1, 
    ); 
$fields = array(
      'registration_ids' => $registrationIds, 
      'notification'  => $msg 
     ); 

$headers = array(
      'Authorization: key=' . API_ACCESS_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)); 
$result = curl_exec($ch); 
curl_close($ch); 
echo $result; 
+0

こんにちは@MRustamzadeあなたは私があなたのアプリ内でそれをどう扱うか教えてください。ありがとう、私に知らせてください。 –

+0

@AvinashMishra私はここでそれをしました:https://firebase.google.com/docs/cloud-messaging/ios/client – MRustamzade

関連する問題