sendNotification() public method

Send a notification.
public sendNotification ( string $endpoint, string | null $payload = null, string | null $userPublicKey = null, string | null $userAuthToken = null, boolean $flush = false, array $options = [], array $auth = [] ) : array | boolean
$endpoint string
$payload string | null If you want to send an array, json_encode it
$userPublicKey string | null
$userAuthToken string | null
$flush boolean If you want to flush directly (usually when you send only one notification)
$options array Array with several options tied to this notification. If not set, will use the default options that you can set in the WebPush object
$auth array Use this auth details instead of what you provided when creating WebPush
return array | boolean Return an array of information if $flush is set to true and the queued requests has failed. Else return true
Beispiel #1
0
 public function testSendGCMNotificationWithWrongGCMApiKey()
 {
     $webPush = new WebPush(array('GCM' => 'bar'));
     $res = $webPush->sendNotification($this->endpoints['GCM'], null, null, true);
     $this->assertTrue(is_array($res));
     // there has been an error
     $this->assertArrayHasKey('success', $res);
     $this->assertEquals(false, $res['success']);
     $this->assertArrayHasKey('statusCode', $res);
     $this->assertEquals(401, $res['statusCode']);
     $this->assertArrayHasKey('headers', $res);
 }
Beispiel #2
0
        $webPush = new WebPush(array('GCM' => $push_api));
        $endpoints = get_endpoints("Voting_End30");
        // send multiple notifications
        foreach ($endpoints as $endpoint) {
            $webPush->sendNotification($endpoint['Endpoint']);
        }
        $webPush->flush();
    }
    if (in_array("Voting_End", get_event(3600))) {
        $to = get_emails("Voting_End60");
        $message = '
    <html>
    <body>
    <p>Dear HiveMember,</p>
    <p>You are yet to vote for this weeks film night. Voting closes in an hour.
    <p>Please <a href="https://films.jakestockwin.co.uk/voting.php">click here</a> to vote</p>
    <br>
    <p>Best wishes,<br>The HiveBot&trade;</p>
    </body>
    </html>
    ';
        mail($to, "Film Night Voting", $message, "Content-type:text/html");
        $webPush = new WebPush(array('GCM' => $push_api));
        $endpoints = get_endpoints("Voting_End60");
        // send multiple notifications
        foreach ($endpoints as $endpoint) {
            $webPush->sendNotification($endpoint['Endpoint']);
        }
        $webPush->flush();
    }
}
Beispiel #3
0
 public function testSendGCMNotificationWithWrongGCMApiKey()
 {
     if (substr(self::$endpoints['GCM'], 0, strlen(WebPush::GCM_URL)) !== WebPush::GCM_URL) {
         $this->markTestSkipped('The provided GCM URL is not a GCM URL, but probably a FCM URL.');
     }
     $webPush = new WebPush(array('GCM' => 'bar'));
     $res = $webPush->sendNotification(self::$endpoints['GCM'], null, null, null, true);
     $this->assertTrue(is_array($res));
     // there has been an error
     $this->assertArrayHasKey('success', $res);
     $this->assertFalse($res['success']);
     $this->assertArrayHasKey('statusCode', $res);
     $this->assertEquals(400, $res['statusCode']);
     $this->assertArrayHasKey('headers', $res);
     $this->assertArrayHasKey('endpoint', $res);
     $this->assertEquals(self::$endpoints['GCM'], $res['endpoint']);
 }