Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- $json_data = array(
- 'to' => 'dRbCRkw774Y:APA91bEXSfFnm-1bJzgECCGEK9ImhS40ZjG7wzyTA2e4pUKxtCx_lW5B2oriTCwqQfB1-TJaGWs3lN-OpCuAErrUW3szyFLgasCZfAvGCJ_y_BEWDWcw4PfvRLv9sHdk8qPk2Oa3Mht8',
- 'notification' => array(
- 'body' => 'something',
- 'title' => 'something',
- ),
- 'data' => null,
- );
- // print(json_encode($json_data));
- $data = json_encode($json_data);
- //FCM API end-point
- $url = 'https://fcm.googleapis.com/fcm/send';
- //api_key in Firebase Console -> Project Settings -> CLOUD MESSAGING -> Server key
- $server_key = 'AAAAQGz59Vw:APA91bE-arA2TUKPFw3Lsk2_PaesNhoWAZfpmFxVfijUrpS3d6OmuBKBZZfV-JhGDFQNEjN2_4VxG8qbgQXBBD8HviFEqyh4FUTWp-0EiqI3uhh7unk4jISYMSSq77ndG8uB3bAPxO0c';
- //header with content_type api key
- $headers = array(
- 'Content-Type:application/json',
- 'Authorization:key=' . $server_key
- );
- //CURL request to route notification to FCM connection server (provided by Google)
- $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, $data);
- $result = curl_exec($ch);
- if ($result === FALSE) {
- die('Oops! FCM Send Error: ' . curl_error($ch));
- }
- curl_close($ch);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement