File manager - Edit - /home/cipherteam/htdocs/cipherteam.in/admin/notification/send_noti.php
Back
<?php require "Connection.php"; require_once 'new/google-api-php-client--php8.3/vendor/autoload.php'; use Google\Client; $msg = $_POST['msg']; $title = $_POST['title']; $activity = $_POST['activity']; function getAccessToken($serviceAccountPath) { $client = new Client(); $client->setAuthConfig($serviceAccountPath); $client->addScope('https://www.googleapis.com/auth/firebase.messaging'); $client->useApplicationDefaultCredentials(); $token = $client->fetchAccessTokenWithAssertion(); return $token['access_token']; } function sendMessage($accessToken, $projectId, $message) { $url = 'https://fcm.googleapis.com/v1/projects/' . $projectId . '/messages:send'; $headers = [ 'Authorization: Bearer ' . $accessToken, 'Content-Type: application/json', ]; $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_POST, true); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); curl_setopt($ch, CURLOPT_HTTPHEADER, $headers); curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode(['message' => $message])); $response = curl_exec($ch); if ($response === false) { throw new Exception('Curl error: ' . curl_error($ch)); } curl_close($ch); return json_decode($response, true); } $serviceAccountPath = 'service-account-file.json'; $projectId = 'sharemarketipo-60b20'; if($activity == "NONE") { // Example message payload $message = [ 'topic' => 'IPO', 'notification' => [ 'title'=> $title, 'body'=> $msg ] ]; } else { // Example message payload $message = [ 'topic' => 'IPO', 'notification' => [ 'title'=> $title, 'body'=> $msg ], 'android' => [ 'notification' => [ 'click_action' => $activity ] ] ]; } try { $accessToken = getAccessToken($serviceAccountPath); $response = sendMessage($accessToken, $projectId, $message); echo 'Message sent successfully: ' . print_r($response, true); } catch (Exception $e) { echo 'Error: ' . $e->getMessage(); } ?>
| ver. 1.4 |
Github
|
.
| PHP 8.2.9 | Generation time: 0.02 |
proxy
|
phpinfo
|
Settings