Advertisement
Guest User

Untitled

a guest
Jul 9th, 2012
806
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. <?php
  2. set_include_path(get_include_path() .
  3.     PATH_SEPARATOR .
  4.     realpath(dirname(__FILE__) . "/../../../library") .
  5.     PATH_SEPARATOR .
  6.     realpath(dirname(__FILE__) . "/../../../../../")
  7. );
  8.  
  9. require_once 'Zend/Mobile/Push/Gcm.php';
  10. require_once 'Zend/Mobile/Push/Message/Gcm.php';
  11.  
  12. function sendPush($registrationId) {
  13.     $message = new Zend_Mobile_Push_Message_Gcm();
  14.     $message->addToken($registrationId);
  15.     $message->setData(array(
  16.         'foo' => 'bar',
  17.         'bar' => 'foo',
  18.     ));
  19.  
  20.     $gcm = new Zend_Mobile_Push_Gcm();
  21.     $gcm->setApiKey('MY_API_KEY');
  22.  
  23.     try {
  24.         $response = $gcm->send($message);
  25.     } catch (Zend_Mobile_Push_Exception $e) {
  26.         // exceptions require action or implementation of exponential backoff.
  27.         die($e->getMessage());
  28.     }
  29.     return $response;
  30. }
  31.  
  32. if(isset($_POST["escuchar"])) {
  33.   $response = sendPush($_POST['registration_id']);
  34.   print_r($response);
  35. }
  36.  
  37. ?>
  38. <form method="post" action="<?=$_SERVER['PHP_SELF']?>">
  39. <input type="text" name="registration_id" />
  40. <input type="submit" name="escuchar" value="Escuchar">
  41. </form>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement