File: /home/clientsoftwares/public_html/ecom.clientsoftwares.com/.gitignore
/node_modules
/public/hot
/public/storage
/storage/*.key
/vendor
.env
.env.backup
.phpunit.result.cache
Homestead.json
Homestead.yaml
npm-debug.log
yarn-error.log
/.idea
/.vscode
public function sendPushNotification()
{
$credentialsFilePath = "firebase/fcm.json";
$client = new Google_Client();
$client->setAuthConfig($credentialsFilePath);
$client->addScope('https://www.googleapis.com/auth/firebase.messaging');
$apiurl = 'https://fcm.googleapis.com/v1/projects/<PROJECT_ID>/messages:send';
$client->refreshTokenWithAssertion(); //refreshTokenWithAssertion();
$token = $client->getAccessToken();
$access_token = $token['access_token'];
$headers = [
"Authorization: Bearer $access_token",
'Content-Type: application/json'
];
$test_data = [
"title" => "TITLE_HERE",
"description" => "DESCRIPTION_HERE",
];
$data['data'] = $test_data;
$data['token'] = $user['fcm_token']; // Retrive fcm_token from users table
$payload['message'] = $data;
$payload = json_encode($payload);
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $apiurl);
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, $payload);
curl_exec($ch);
$res = curl_close($ch);
if ($res) {
return response()->json([
'message' => 'Notification has been Sent'
]);
}
}