Пример #1
0
 /**
  * @param string $number
  * @param mixed $content
  * @param boolean $isContentConfidentially
  * @param Logic_Service_Multiinfo_Params $params
  * @throws Logic_WebService_Sms_Exception
  * @return Logic_Service_Multiinfo_Response_Container
  */
 public function handle($number = null, $content = null, $isContentConfidentially = false, Logic_Service_Multiinfo_Params $params = null)
 {
     $recipient = new Logic_WebService_Sms_Recipient($number);
     // jezeli to NIE jest produkcja sprawdzam, czy numer jest na liscie
     // numerow tel. bezpiecznych do wykonania testow
     if (!$this->_environment->checkStatus()) {
         $recipient->checkNumberOnWhiteList();
     }
     $content = new Logic_WebService_Sms_Content($content, $isContentConfidentially);
     // sprawdzam na liscie numerow zablokowanych do wysylki dla tej uslugi
     if ($recipient->checkNumberOnBlackList($this->_client->getParams()->id)) {
         $model = new SmsBlacklistStorage();
         $model->addSms($recipient->getRecipient()->id, $this->_client->getParams()->id, $this->_service->getParams()->id, $content->getHash(), $content->getContentToLog());
         throw new Logic_WebService_Sms_Exception('Proba wyslania sms na numer obecny na blacklist: ' . $this->_number, 417);
     }
     // test limitow ilosciowych miesiac/dzien
     $recipient->checkLimit($this->_client, $this->_service);
     // test numeru na limit ilosciowy sms z dana trescia
     $recipient->checkLimitByContent($this->_client, $this->_service, $content);
     // jesli wszystko jest ok, probuje wyslac sms
     if ($this->_service->getParams()->use_db) {
         $multiinfo = new Logic_Service_Multiinfo_ToDb($this->_service->getParams()->service_login, $this->_service->getParams()->service_password);
     } else {
         $multiinfo = new Logic_Service_Multiinfo($this->_service->getParams()->service_login, $this->_service->getParams()->service_password, $this->_service->getParams()->new_api);
     }
     $contentLenght = $content->countContentLenght();
     if ($contentLenght > 1377) {
         // maksymalny rozmiar sms long
         throw new Logic_WebService_Sms_Exception('Przekroczono limit maksymalnego rozmiaru sms (max. 1377; wiadomosc: ' . $contentLenght . ')', 423);
     } elseif ($contentLenght > 160) {
         // sms long
         $handler = new Logic_Service_Multiinfo_Response(new Logic_Service_Multiinfo_Response_SendSmsLong());
         $response = $handler->handle($multiinfo->sendsmslong($this->_service->getParams()->special_id, $recipient->getNumber(), $content->getContent(), $params->validTo, $params->delivNotifRequest, $params->advancedEncoding, $params->deleteContent));
     } elseif ($contentLenght > 0 && $contentLenght <= 160) {
         // sms standard
         $handler = new Logic_Service_Multiinfo_Response(new Logic_Service_Multiinfo_Response_SendSms());
         $response = $handler->handle($multiinfo->sendsms($this->_service->getParams()->special_id, $recipient->getNumber(), $content->getContent(), $params->validTo, $params->delivNotifRequest, $params->zeroclass, $params->advancedEncoding, $params->deleteContent));
     } else {
         // z jakiegos powodu wiadomosc jest pusta (nie podano tresci, pusty szablon, ogolnie awaria)
         throw new Logic_WebService_Sms_Exception('Proba wyslania pustego sms (brak tresci przygotowanej do wysylki)', 510);
     }
     $model = new SmsStorage();
     $model->addSms($recipient->getRecipient()->id, $this->_client->getParams()->id, $this->_service->getParams()->id, $content->getHash(), $content->getContentToLog(), $response);
     $smsLog = new Logic_WebService_Sms_Log();
     if ($response->status == true) {
         // wysylanie sms zakonczylo sie sukcesem
         $smsLog->log('Wyslano SMS', 5, $response->toArray());
     } else {
         // wysylanie sms zakonczylo sie bledem
         $smsLog->log('Blad bramki SMS', 3, $response->toArray());
         $this->_errorHandler($response->errorCode, $response->errorMessage, $this->_service->getParams()->id);
     }
     return $response;
 }
 private function sendSms($service_id, $number = null, $content = null, $isContentConfidentially = false, Logic_Service_Multiinfo_Params $params = null)
 {
     $recipient = new Logic_WebService_Sms_Recipient($number);
     $content = new Logic_WebService_Sms_Content($content, $isContentConfidentially);
     $this->_service = new Logic_WebService_Element_Service();
     $this->_service->getService($service_id);
     if ($this->_service->getParams()->use_db) {
         $multiinfo = new Logic_Service_Multiinfo_ToDb($this->_service->getParams()->service_login, $this->_service->getParams()->service_password);
     } else {
         $multiinfo = new Logic_Service_Multiinfo($this->_service->getParams()->service_login, $this->_service->getParams()->service_password, $this->_service->getParams()->new_api);
     }
     $contentLenght = $content->countContentLenght();
     if ($contentLenght > 1377) {
         // maksymalny rozmiar sms long
         throw new Logic_WebService_Sms_Exception('Przekroczono limit maksymalnego rozmiaru sms (max. 1377; wiadomosc: ' . $contentLenght . ')', 423);
     } elseif ($contentLenght > 160) {
         // sms long
         $handler = new Logic_Service_Multiinfo_Response(new Logic_Service_Multiinfo_Response_SendSmsLong());
         $response = $handler->handle($multiinfo->sendsmslong($this->_service->getParams()->special_id, $recipient->getNumber(), $content->getContent(), $params->validTo, $params->delivNotifRequest, $params->advancedEncoding, $params->deleteContent));
     } elseif ($contentLenght > 0 && $contentLenght <= 160) {
         // sms standard
         $handler = new Logic_Service_Multiinfo_Response(new Logic_Service_Multiinfo_Response_SendSms());
         $response = $handler->handle($multiinfo->sendsms($this->_service->getParams()->special_id, $recipient->getNumber(), $content->getContent(), $params->validTo, $params->delivNotifRequest, $params->zeroclass, $params->advancedEncoding, $params->deleteContent));
     } else {
         // z jakiegos powodu wiadomosc jest pusta (nie podano tresci, pusty szablon, ogolnie awaria)
         throw new Logic_WebService_Sms_Exception('Proba wyslania pustego sms (brak tresci przygotowanej do wysylki)', 510);
     }
     $smsLog = new Logic_WebService_Sms_Log();
     if ($response->status == true) {
         // wysylanie sms zakonczylo sie sukcesem
         $smsLog->log('Wyslano SMS', 5, $response->toArray());
     } else {
         // wysylanie sms zakonczylo sie bledem
         $smsLog->log('Blad bramki SMS', 3, $response->toArray());
         throw new Logic_WebService_Sms_Exception('Blad bramki SMS: ' . $response->errorCode . ' ' . $response->errorMessage, 512);
     }
     return $response;
 }