PHP code example of coder966 / fcm-simple
1. Go to this page and download the library: Download coder966/fcm-simple library. Choose the download type require. 2. Extract the ZIP file and open the index.php. 3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
coder966 / fcm-simple example snippets
use FCMSimple\Client;
use FCMSimple\Message;
// create the client
$client = new Client("YOUR_SERVER_KEY");
// create the message
$msg = new Message();
$msg->put("key1", "value1");
$msg->put("key2", "value2");
// send the message to a specific topic
$client->sendToTopic($msg, "my_topic");
// or you can send to specific devices using their registration tokens
// so first prepare your array of tokens, typically retrieve from DB
$tokens = [
"token_1",
"token_2",
"token_3"
];
// and send
$client->sendToTokens($msg, $tokens);