I have a Laravel app in which I use some code to send FCM to send notification to IOS and Android, but now I need to include and image in the notification. the code I am using now is as below
$fcmUrl = 'https://fcm.googleapis.com/fcm/send';
$notification = [
'body' => 'Message',
'title'=>'title',
'sound' => true,
'priority' => "high",
'vibration'=>true,
'sound'=> "Enabled",
'badge'=>4,
'id'=>2
];
$extraNotificationData = ['one'=>1,'two'=>2];
$fcmNotification = [
//'registration_ids' => json_encode($token,JSON_FORCE_OBJECT), //multple token array
'to' => $this->token, //single token
'data' => $extraNotificationData,
'notification' => $notification
];
$headers = [
'Authorization: key=Server_key',
'Content-Type: application/json'
];
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $fcmUrl);
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($fcmNotification));
$result = curl_exec($ch);
curl_close($ch);
via Chebli Mohamed
Aucun commentaire:
Enregistrer un commentaire