Example #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;
 }
Example #2
0
 private function doTest($service_id, $text = 'Logic_SelfCheck_Sms')
 {
     $recipient = new Logic_WebService_Sms_Recipient($this->_testTel);
     $this->_service = new Logic_WebService_Element_Service();
     $this->_service->getService($service_id);
     $multiinfo = new Logic_Service_Multiinfo($this->_service->getParams()->service_login, $this->_service->getParams()->service_password, $this->_service->getParams()->new_api);
     $handler = new Logic_Service_Multiinfo_Response(new Logic_Service_Multiinfo_Response_Raw());
     $model = new SmsStorage();
     $sms_nr = $model->getPastSms($service_id)->smsid;
     if (empty($sms_nr)) {
         return;
     }
     $response = $handler->handle($multiinfo->infosms($sms_nr));
     if ($response[15] == '11') {
         $sms_nr_2nd = $model->getPastSms(time() - 120, $service_id)->smsid;
         if (empty($sms_nr)) {
             return;
         }
         $response = $handler->handle($multiinfo->infosms($sms_nr), $sms_nr_2nd);
         if ($response[15] == '11') {
             return array('errorType' => 'critical', 'errorMessage' => 'błędny status dwóch kolejno sprawdzonych wiadomości ("Błąd fatalny, wysyłanie nieudane" ' . $sms_nr . ', ' . $sms_nr_2nd . ')', 'errorCode' => '11', 'response' => $response);
         }
     }
     $response = $handler->handle($multiinfo->infosms($sms_nr));
     if ($response[15] == '7') {
         $sms_nr_2nd = $model->getPastSms(time() - 120, $service_id)->smsid;
         if (empty($sms_nr)) {
             return;
         }
         $response = $handler->handle($multiinfo->infosms($sms_nr), $sms_nr_2nd);
         if ($response[15] == '7') {
             return array('errorType' => 'critical', 'errorMessage' => 'błędny status dwóch kolejno sprawdzonych wiadomości ("Wiadomość wstrzymana z powodu przekroczenia limitu" ' . $sms_nr . ', ' . $sms_nr_2nd . ')', 'errorCode' => '11', 'response' => $response);
         }
     }
     if ($response[0] === '<html>') {
         return array('errorType' => 'critical', 'errorMessage' => 'błąd 404 przy wykonywaniu zapytania do multiinfo - nieprawidłowy url usługi', 'errorCode' => '404');
     } else {
         if ($response[0] !== '0') {
             return array('errorType' => 'critical', 'errorMessage' => $response[1], 'errorCode' => $response[0], 'raw' => $response);
         }
     }
 }
Example #3
0
 /**
  * @param array $numbers
  * @param mixed $content
  * @param string $startDate
  * @throws Logic_WebService_Sms_Exception
  * @return Logic_Service_Multiinfo_Response_Container
  */
 public function handle(array $numbers = array(), $content = null, $startDate = null)
 {
     $timeLimit = 30;
     // zabezpieczenie przed przekroczeniem limitu czasu wykonywania skryptu
     if ($startDate) {
         $validator = new Logic_Validate_DdMMyyHHmmss();
         if (!$validator->isValid($startDate)) {
             throw new Logic_WebService_Sms_Exception('Nieprawidlowy format daty/czasu: ' . $startDate . '/ddMMyyHHmmss', 453);
         }
     }
     $content = new Logic_WebService_Sms_Content($content);
     $toSend = array();
     $toReport = array();
     if (empty($numbers)) {
         throw new Logic_WebService_Sms_Exception('Nie podano numerow do rozsylki', 450);
     }
     foreach ($numbers as $number => $individualContent) {
         set_time_limit($timeLimit + 30);
         try {
             $recipient = new Logic_WebService_Sms_Recipient($number);
             if (!$this->_environment->checkStatus()) {
                 $recipient->checkNumberOnWhiteList();
             }
             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());
                 continue;
             }
             $recipient->checkLimit($this->_client, $this->_service);
             $numberContent = $individualContent ? new Logic_WebService_Sms_Content($individualContent) : $content;
             $recipient->checkLimitByContent($this->_client, $this->_service, $numberContent);
             if (key_exists(strval($recipient->getNumber()), $toSend)) {
                 throw new Logic_WebService_Exception('Zdublowny numer na liscie wysylki: ' . $recipient->getNumber(), 451);
             }
             $toSend[strval($recipient->getNumber())] = $individualContent ? $numberContent->getContent() : null;
             unset($recipient);
             unset($numberContent);
         } catch (Logic_WebService_Exception $e) {
             $toReport[] = array('number' => $number, 'content' => $individualContent, 'reason' => $e->getMessage());
         }
     }
     if (empty($toSend)) {
         throw new Logic_WebService_Sms_Exception('Brak numerow do rozeslania - zaden nie przeszedl weryfikacji', 452);
     } else {
         $multiinfo = new Logic_Service_Multiinfo($this->_service->getParams()->service_login, $this->_service->getParams()->service_password, $this->_service->getParams()->new_api);
         $handler = new Logic_Service_Multiinfo_Response(new Logic_Service_Multiinfo_Response_Package());
         $response = $handler->handle($multiinfo->package($this->_service->getParams()->special_id, $toSend, $content->getContent(), false, $startDate));
         $response->report = $toReport;
         $smsLog = new Logic_WebService_Sms_Log();
         if ($response->status == true) {
             $modelPackage = new SmsPackage();
             $packageID = $modelPackage->addPackage(array('packageid' => $response->packageId, 'start_date' => $startDate));
         } else {
             $this->_errorHandler($response->errorCode, $response->errorMessage, $this->_service->getParams()->id);
         }
         $modelStorage = new SmsStorage();
         foreach ($toSend as $number => $individualContent) {
             set_time_limit($timeLimit + 30);
             $recipient = new Logic_WebService_Sms_Recipient($number);
             $modelStorage->addSms($recipient->getRecipient()->id, $this->_client->getParams()->id, $this->_service->getParams()->id, $individualContent ? md5($individualContent) : $content->getHash(), $individualContent ? $individualContent : $content->getContentToLog(), $response, $packageID);
         }
         return $response;
     }
 }
Example #4
0
 /**
  * 
  * @param array $dataToSave
  */
 private function _saveStorageMany(array &$variableData, array $contstantData, $idPackage)
 {
     $model = new SmsStorage();
     $constDataMerged = array_merge($contstantData, $this->_getBasicClientData());
     return $model->addSmsMany($variableData, $constDataMerged, $idPackage);
 }