Пример #1
0
 *
--><!DOCTYPE html>
<meta name="viewport" content="width=device-width, initial-scale=1">
<style>
	body {max-width: 960px; margin: 0 auto}
	pre {background: #999; color: white; padding: 0 4px}
	input, textarea {width: 100%; font: inherit; background: #eee; border: 0; padding: 2px 4px}
	button {font: inherit}
</style>
<body>
<h1>GCMnotifier Client</h1>

<pre><?php 
require __DIR__ . "/../GCMnotifier.php";
error_reporting(E_ERROR);
$client = new GCMnotifier();
if (@$_POST['command'] == 'send') {
    $data = ['title' => $_POST['title'], 'body' => $_POST['body'], 'id' => (string) time()];
    $notification = ['to' => $_POST['to'], 'data' => $data, "message_id" => (string) time()];
    $result = $client->send($notification);
}
if (@$_POST['command'] == 'stop') {
    $result = $client->send('stop');
}
?>
</pre>

<?php 
if (isset($result)) {
    ?>
	<p>Result: <?php 
Пример #2
0
<?php

/**
 * An example that represents a service, ie. a background process listening for client TCP connections,
 * taking their notifications and delivering them to Google Cloud Connection servers.
 *
 * Replace sender_id and api_key below with your official credentials obtained from Google's Developer Console.
 *
 * @package GCMnotifier
 */
require __DIR__ . "/../GCMnotifier.php";
$service = new GCMnotifier(['sender_id' => '000000000000', 'api_key' => 'XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX', 'onSend' => function ($message_id) {
    echo "Sent message #{$message_id} successfully.\n";
}, 'onFail' => function ($message_id, $error, $description) {
    echo "Failed message #{$message_id} with {$error} ({$description}).\n";
}, 'onExpire' => function ($old_token, $new_token) {
    if ($new_token) {
        echo "Need to replace expired token {$old_token} with #{$new_token}\n";
    } else {
        echo "Need to forget invalid token {$old_token}\n";
    }
}]);
$service->listen() or die("Cannot start service.\n");