Skip to content

Instantly share code, notes, and snippets.

@madi-madi
Created December 26, 2020 16:45
Show Gist options
  • Save madi-madi/c83b950db1d70e490cb15545f5d78e99 to your computer and use it in GitHub Desktop.
Save madi-madi/c83b950db1d70e490cb15545f5d78e99 to your computer and use it in GitHub Desktop.
send fcm all Topic
<?php
/*
curl -X POST --header "Authorization: key=<KeyValue>" \
--Header "Content-Type: application/json" \
https://fcm.googleapis.com/fcm/send \
-d "{\"condition\":\"!('anytopicyoudontwanttouse' in topics)\",\"notification\":{\"title\":\"Hello\",\"body\":\"Yellow\"}}"
*/
$notification = [
'title' => 'fffffffffffffffffffffffffffffffff',
'body' => 'bbbbbbbbbbbbbbbbbbbb',
'icon' => "icon",
];
$notification = array_filter($notification, function($value) {
return $value !== null;
});
$url = 'https://fcm.googleapis.com/fcm/send';
$fields = array (
// 'registration_ids' => $device_token,
'data' => $notification,
// 'data'=>['fcmapp'=>[]],
"condition"=> "!('anytopicyoudontwanttouse' in topics)"
);
$fields = json_encode ( $fields );
$headers = array (
'Authorization: key=' . config('fcmapp.server_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_POSTFIELDS, $fields );
$result = curl_exec ( $ch );
curl_close ( $ch );
return $result;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment