Want more features on Pastebin? Sign Up, it's FREE!
Guest

Untitled

By: a guest on Jul 9th, 2012  |  syntax: PHP  |  size: 1.11 KB  |  views: 617  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
This paste has a previous version, view the difference. Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  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>
clone this paste RAW Paste Data