答えて

0

コードのこの作品これは私が私の開発のために言及されているソースコードであるPHP

$server_key=""; // get this from Firebase project settings->Cloud Messaging 
$user_token=""; // Token generated from Android device after setting up firebase 
$title="New Message"; 
$n_msg="The is a message"; 

$ndata = array('title'=>$title,'body'=>$n_msg); 

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

$fields = array(); 
$fields['data'] = $ndata; 

$fields['to'] = $user_token; 
$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); 
1

を使用してFirebaseからAndroidデバイスに通知を送信します。あなたはphpfiddleで試すことができます。参照:Push notification (PHP)。ペイロードの通知はfirebase hereで確認できます。

<?php 

define('API_ACCESS_KEY', 'AIza......Xhdsnkf'); // get API access 
key from Google/Firebase API's Console 

$registrationIds = array('cyMSGTKBzwU:APA91...xMKgjgN32WfoJY6mI'); //Replace this with your device token 


// Modify custom payload here 
$msg = array 
(
     'mesgTitle'  => 'SMART TESTING', 
     'alert'   => 'This is sample notification' 

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

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

$ch = curl_init(); 
curl_setopt($ch,CURLOPT_URL, 'https://android.googleapis.com/gcm/send'); //For firebase, use 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

ありがとうございます。あなたは同じメッセージフィールドにアンドロイド通知バッジを設定する方法を言うことができますか? –

関連する問題