_httpClient) { $this->_httpClient = new Zend_Http_Client(); $this->_httpClient->setConfig(array( 'strictredirects' => true, )); } return $this->_httpClient; } /** * Set Http Client * * @return Zend_Mobile_Push_Mpns */ public function setHttpClient(Zend_Http_Client $client) { $this->_httpClient = $client; return $this; } /** * Send Message * * @param Zend_Mobile_Push_Message_Mpns $message * @return boolean * @throws Zend_Mobile_Push_Exception */ public function send(Zend_Mobile_Push_Message_Abstract $message) { if (!$message->validate()) { throw new Zend_Mobile_Push_Exception('The message is not valid.'); } $this->connect(); $client = $this->getHttpClient(); $client->setUri($message->getToken()); $client->setHeaders(array( 'Context-Type' => 'text/xml', 'Accept' => 'application/*', 'X-NotificationClass' => $message->getDelay() )); if ($message->getId()) { $client->setHeaders('X-MessageID', $message->getId()); } if ($message->getNotificationType() != Zend_Mobile_Push_Message_Mpns::TYPE_RAW) { $client->setHeaders('X-WindowsPhone-Target', $message->getNotificationType()); } $client->setRawData($message->getXmlPayload(), 'text/xml'); $response = $client->request('POST'); $this->close(); switch ($response->getStatus()) { case 200: // check headers for response? need to test how this actually works to correctly handle different states. if ($response->getHeader('NotificationStatus') == 'QueueFull') { #require_once 'Zend/Mobile/Push/Exception/DeviceQuotaExceeded.php'; throw new Zend_Mobile_Push_Exception_DeviceQuotaExceeded('The devices push notification queue is full, use exponential backoff'); } break; case 400: #require_once 'Zend/Mobile/Push/Exception/InvalidPayload.php'; throw new Zend_Mobile_Push_Exception_InvalidPayload('The message xml was invalid'); break; case 401: #require_once 'Zend/Mobile/Push/Exception/InvalidToken.php'; throw new Zend_Mobile_Push_Exception_InvalidToken('The device token is not valid or there is a mismatch between certificates'); break; case 404: #require_once 'Zend/Mobile/Push/Exception/InvalidToken.php'; throw new Zend_Mobile_Push_Exception_InvalidToken('The device subscription is invalid, stop sending notifications to this device'); break; case 405: throw new Zend_Mobile_Push_Exception('Invalid method, only POST is allowed'); // will never be hit unless overwritten break; case 406: #require_once 'Zend/Mobile/Push/Exception/QuotaExceeded.php'; throw new Zend_Mobile_Push_Exception_QuotaExceeded('The unauthenticated web service has reached the per-day throttling limit'); break; case 412: #require_once 'Zend/Mobile/Push/Exception/InvalidToken.php'; throw new Zend_Mobile_Push_Exception_InvalidToken('The device is in an inactive state. You may retry once per hour'); break; case 503: #require_once 'Zend/Mobile/Push/Exception/ServerUnavailable.php'; throw new Zend_Mobile_Push_Exception_ServerUnavailable('The server was unavailable.'); break; default: break; } return true; } }