-
-
Save uno-de-piera/1c2fe4b3d680969a08462d402d3df088 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$token = "DATABASE TOKEN OBJECT"; | |
$not = "DATABASE OBJECT NOTIFICATION"; | |
$data = null; | |
$headers = [ | |
'Authorization:key=Clave del servidor FCM', | |
'Content-Type: application/json' | |
]; | |
if($token->platform === 'ios') { | |
$data = [ | |
'to' => $token->device_token, | |
'notification' => [ | |
'body' => $notification_request->message, | |
'title' => $notification_request->title, | |
], | |
"data" => [// aditional data for iOS | |
"extra-key" => "extra-value, | |
], | |
'notId' => $not->id,//unique id for each notification | |
]; | |
} elseif ($token->platform === 'android') { | |
$data = [ | |
'to' => $token->device_token, | |
'data' => [ | |
'body' => $notification_request->message, | |
'title' => $notification_request->title, | |
] | |
]; | |
} | |
$ch = curl_init(); | |
curl_setopt( $ch,CURLOPT_URL, 'https://gcm-http.googleapis.com/gcm/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( $data ) ); | |
curl_setopt($ch, CURLOPT_FAILONERROR, TRUE); | |
$result = curl_exec($ch); | |
curl_close( $ch ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment