fork download
  1. <?php
  2. $fcmToken = ['cFlXEwr4Y07ikw14-QuIHJ:APA91bE54mrOpFyzDSq7NfFnYqPXrA2B4mXrqFYlxaVphIsFvHiMEt4lHypW-IYmfZT1F41c-3ke-7rtDZSI_RVsioIkk2krlr4DSZrY1cor2hz2TBo9CJoleriKeB8OzxLzDxhjqj2L'];
  3. $title = "Test Push notification";
  4. $body = "This is test Push notification";
  5. $url = 'https://f...content-available-to-author-only...s.com/fcm/send';
  6. // $serverKey = env('FCM_SERVER_KEY');
  7. $serverKey = "AAAAmgAHb2U:APA91bGbQXS7Ptwo7gvFXqp0I11z9SbUslgOm62co6TPd4BuxY2NDUkAawNR6l4r9j69A7wVJldgxPe2y5tSzbFNl-lD8kdqeNgzT8vus5vRa8s956d_7VYO6sCVqyIS0ctEj0rIJSc1";
  8. $data = [
  9. "registration_ids" => $fcmToken,
  10. "notification" => [
  11. "title" => $title,
  12. "body" => $body,
  13. ]
  14. ];
  15. $encodedData = json_encode($data);
  16. $headers = [
  17. 'Authorization:key=' . $serverKey,
  18. 'Content-Type: application/json',
  19. ];
  20. $ch = curl_init();
  21.  
  22. curl_setopt($ch, CURLOPT_URL, $url);
  23. curl_setopt($ch, CURLOPT_POST, true);
  24. curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
  25. curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
  26. curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
  27. curl_setopt($ch, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_1);
  28. // Disabling SSL Certificate support temporarly
  29. curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
  30. curl_setopt($ch, CURLOPT_POSTFIELDS, $encodedData);
  31. // Execute post
  32. $result = curl_exec($ch);
  33. echo $result ? "results" : "false";
  34. if ($result === FALSE) {
  35. echo "false output";
  36. return false;
  37. }
  38. // Close connection
  39. curl_close($ch);
  40. // FCM response
  41. return true;
  42. ?>
Success #stdin #stdout 0.03s 26440KB
stdin
Standard input is empty
stdout
falsefalse output