equal
deleted
inserted
replaced
13 * to license@zend.com so we can send you a copy immediately. |
13 * to license@zend.com so we can send you a copy immediately. |
14 * |
14 * |
15 * @category Zend |
15 * @category Zend |
16 * @package Zend_Mobile |
16 * @package Zend_Mobile |
17 * @subpackage Zend_Mobile_Push |
17 * @subpackage Zend_Mobile_Push |
18 * @copyright Copyright (c) 2005-2011 Zend Technologies USA Inc. (http://www.zend.com) |
18 * @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com) |
19 * @license http://framework.zend.com/license/new-bsd New BSD License |
19 * @license http://framework.zend.com/license/new-bsd New BSD License |
20 * @version $Id$ |
20 * @version $Id$ |
21 */ |
21 */ |
22 |
22 |
23 /** Zend_Mobile_Push_Abstract **/ |
23 /** Zend_Mobile_Push_Abstract **/ |
30 * APNS Push |
30 * APNS Push |
31 * |
31 * |
32 * @category Zend |
32 * @category Zend |
33 * @package Zend_Mobile |
33 * @package Zend_Mobile |
34 * @subpackage Zend_Mobile_Push |
34 * @subpackage Zend_Mobile_Push |
35 * @copyright Copyright (c) 2005-2011 Zend Technologies USA Inc. (http://www.zend.com) |
35 * @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com) |
36 * @license http://framework.zend.com/license/new-bsd New BSD License |
36 * @license http://framework.zend.com/license/new-bsd New BSD License |
37 * @version $Id$ |
37 * @version $Id$ |
38 */ |
38 */ |
39 class Zend_Mobile_Push_Apns extends Zend_Mobile_Push_Abstract |
39 class Zend_Mobile_Push_Apns extends Zend_Mobile_Push_Abstract |
40 { |
40 { |
207 } |
207 } |
208 |
208 |
209 /** |
209 /** |
210 * Connect to the Push Server |
210 * Connect to the Push Server |
211 * |
211 * |
212 * @param string $env |
212 * @param int|string $env |
|
213 * @throws Zend_Mobile_Push_Exception |
|
214 * @throws Zend_Mobile_Push_Exception_ServerUnavailable |
213 * @return Zend_Mobile_Push_Abstract |
215 * @return Zend_Mobile_Push_Abstract |
214 * @throws Zend_Mobile_Push_Exception |
|
215 * @throws Zend_Mobile_Push_Exception_ServerUnavailable |
|
216 */ |
216 */ |
217 public function connect($env = self::SERVER_PRODUCTION_URI) |
217 public function connect($env = self::SERVER_PRODUCTION_URI) |
218 { |
218 { |
219 if ($this->_isConnected) { |
219 if ($this->_isConnected) { |
220 if ($this->_currentEnv == self::SERVER_PRODUCTION_URI) { |
220 if ($this->_currentEnv == self::SERVER_PRODUCTION_URI) { |
269 } |
269 } |
270 |
270 |
271 /** |
271 /** |
272 * Send Message |
272 * Send Message |
273 * |
273 * |
274 * @param Zend_Mobile_Push_Message_Apns $message |
274 * @param Zend_Mobile_Push_Message_Abstract $message |
275 * @return boolean |
275 * @throws Zend_Mobile_Push_Exception |
276 * @throws Zend_Mobile_Push_Exception |
276 * @throws Zend_Mobile_Push_Exception_InvalidPayload |
277 * @throws Zend_Mobile_Push_Exception_ServerUnavailable |
|
278 * @throws Zend_Mobile_Push_Exception_InvalidToken |
277 * @throws Zend_Mobile_Push_Exception_InvalidToken |
279 * @throws Zend_Mobile_Push_Exception_InvalidTopic |
278 * @throws Zend_Mobile_Push_Exception_InvalidTopic |
280 * @throws Zend_Mobile_Push_Exception_InvalidPayload |
279 * @throws Zend_Mobile_Push_Exception_ServerUnavailable |
|
280 * @return bool |
281 */ |
281 */ |
282 public function send(Zend_Mobile_Push_Message_Abstract $message) |
282 public function send(Zend_Mobile_Push_Message_Abstract $message) |
283 { |
283 { |
284 if (!$message->validate()) { |
284 if (!$message->validate()) { |
285 throw new Zend_Mobile_Push_Exception('The message is not valid.'); |
285 throw new Zend_Mobile_Push_Exception('The message is not valid.'); |
303 $payload['aps']['alert'] = $alert; |
303 $payload['aps']['alert'] = $alert; |
304 } |
304 } |
305 if (!is_null($message->getBadge())) { |
305 if (!is_null($message->getBadge())) { |
306 $payload['aps']['badge'] = $message->getBadge(); |
306 $payload['aps']['badge'] = $message->getBadge(); |
307 } |
307 } |
308 $payload['aps']['sound'] = $message->getSound(); |
308 $sound = $message->getSound(); |
|
309 if (!empty($sound)) { |
|
310 $payload['aps']['sound'] = $sound; |
|
311 } |
309 |
312 |
310 foreach($message->getCustomData() as $k => $v) { |
313 foreach($message->getCustomData() as $k => $v) { |
311 $payload[$k] = $v; |
314 $payload[$k] = $v; |
312 } |
315 } |
313 $payload = json_encode($payload); |
316 |
|
317 if (version_compare(PHP_VERSION, '5.4.0') >= 0) { |
|
318 $payload = json_encode($payload, JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES); |
|
319 } else { |
|
320 $payload = json_encode($payload); |
|
321 } |
314 |
322 |
315 $expire = $message->getExpire(); |
323 $expire = $message->getExpire(); |
316 if ($expire > 0) { |
324 if ($expire > 0) { |
317 $expire += time(); |
325 $expire += time(); |
318 } |
326 } |