namibia
df0489e1eeeeab5a9bd44e1d84fce49924fe1bac
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 |
<?php namespace Utility\Comms; /** * Facilitates chatting to android devices via GCM. * @author andre.fourie */ class Gcm { /** * Send message via GCM. * @param string|array $registrationIds * @param array $messageData * @param array $collapse * @return array */ static public function send($registrationIds, array $messageData, array $collapse = array()) { //-- Preparation work. if (!is_array($registrationIds)) { $registrationIds = array($registrationIds); } if (0 == count($registrationIds)) { return array( 'Success' => 0, 'Failed' => 0 ); } //-- GCM client. $client = new \ZendService\Google\Gcm\Client(); $client->setApiKey('AIzaSyCrg16ZpPKm0QU2NhhCanH0O-MaxwoO8LU'); $httpClient = new \Zend\Http\Client(null, array( 'adapter' => 'Zend\Http\Client\Adapter\Socket', 'sslverifypeer' => false )); $client->setHttpClient($httpClient); //-- GCM message. $message = new \ZendService\Google\Gcm\Message(); $message->setRegistrationIds($registrationIds); $message->setData($messageData); foreach ($collapse as $collapseKey) { $message->setCollapseKey($collapseKey); } $message->setRestrictedPackageName('com.nirph.bid4cars'); $message->setDelayWhileIdle(false); $message->setTimeToLive(600); $message->setDryRun(false); //-- Send the message. try { $response = $client->send($message); } catch (\Exception $e) { \Utility\Debug::errorLog(__METHOD__ . ':ERROR', $e->getMessage()); return array( 'Success' => 0, 'Failed' => count($registrationIds) ); } return array( 'Success' => $response->getSuccessCount(), 'Failed' => $response->getFailureCount() ); } } |
Commits for namibiamodule/Utility/src/Utility/Comms/Gcm.php
Revision | Author | Commited | Message |
---|---|---|---|
df0489 ... | Mark | Fri 14 Oct, 2016 10:01:00 +0000 | initial commit |