SHOW:
|
|
- or go back to the newest paste.
1 | <?php | |
2 | - | //OJO. Descomenta si quieres saber donde estan los ficheros libreria |
2 | + | set_include_path(get_include_path() . |
3 | - | /*echo("Library path: " . get_include_path() . |
3 | + | PATH_SEPARATOR . |
4 | - | PATH_SEPARATOR . |
4 | + | realpath(dirname(__FILE__) . "/../../../library") . |
5 | - | realpath(dirname(__FILE__) . "/../../../library") . |
5 | + | PATH_SEPARATOR . |
6 | - | PATH_SEPARATOR . |
6 | + | realpath(dirname(__FILE__) . "/../../../../../") |
7 | - | realpath(dirname(__FILE__) . "/../../../../../") |
7 | + | ); |
8 | - | );*/ |
8 | + | |
9 | require_once 'Zend/Mobile/Push/Gcm.php'; | |
10 | - | set_include_path(get_include_path() . |
10 | + | |
11 | - | PATH_SEPARATOR . |
11 | + | |
12 | - | realpath(dirname(__FILE__) . "/../../../library") . |
12 | + | function sendPush($registrationId) { |
13 | - | PATH_SEPARATOR . |
13 | + | $message = new Zend_Mobile_Push_Message_Gcm(); |
14 | - | realpath(dirname(__FILE__) . "/../../../../../")); |
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 | - | $message = new Zend_Mobile_Push_Message_Gcm(); |
22 | + | |
23 | - | $message->addToken('MY_REGISTRATION'); |
23 | + | try { |
24 | - | $message->setData(array( |
24 | + | $response = $gcm->send($message); |
25 | - | 'foo' => 'bar', |
25 | + | } catch (Zend_Mobile_Push_Exception $e) { |
26 | - | 'bar' => 'foo', |
26 | + | // exceptions require action or implementation of exponential backoff. |
27 | - | )); |
27 | + | die($e->getMessage()); |
28 | } | |
29 | - | $gcm = new Zend_Mobile_Push_Gcm(); |
29 | + | return $response; |
30 | - | $gcm->setApiKey('MY_API_KEY'); |
30 | + | |
31 | ||
32 | - | try { |
32 | + | if(isset($_POST["escuchar"])) { |
33 | - | $response = $gcm->send($message); |
33 | + | $response = sendPush($_POST['registration_id']); |
34 | - | } catch (Zend_Mobile_Push_Exception $e) { |
34 | + | |
35 | - | // exceptions require action or implementation of exponential backoff. |
35 | + | |
36 | - | die($e->getMessage()); |
36 | + | |
37 | ?> | |
38 | <form method="post" action="<?=$_SERVER['PHP_SELF']?>"> | |
39 | - | function sendPush(){ |
39 | + | <input type="text" name="registration_id" /> |
40 | - | $message = new Zend_Mobile_Push_Message_Gcm(); |
40 | + | |
41 | - | $message->addToken('MY_Registration'); |
41 | + |