Exemplo n.º 1
0
 /**
  * prepare parts of message
  * @throws Exception
  */
 protected function _prepareParts()
 {
     //
     $headerSize = self::HEADER_SIZE;
     $max = Helper::getLimit('normal');
     if ($this->_isUnicode) {
         // max length sms to unicode
         $max = Helper::getLimit('unicode');
         // can't compress message
         $this->getPdu()->getDcs()->setTextCompressed(FALSE)->setTextAlphabet(DCS::ALPHABET_UCS2);
         // type alphabet is UCS2
     }
     // if message is compressed
     if ($this->getPdu()->getDcs()->getTextCompressed()) {
         $max = Helper::getLimit('compress');
         $headerSize++;
     }
     $parts = $this->_splitMessage($max, $headerSize);
     $header = count($parts) > 1;
     $uniqid = rand(0, 65535);
     // message will be splited, need headers
     if ($header) {
         $this->getPdu()->getType()->setUdhi(1);
     }
     foreach ($parts as $index => $text) {
         $params = $header ? array('SEGMENTS' => count($parts), 'CURRENT' => $index + 1, 'POINTER' => $uniqid) : NULL;
         $part = NULL;
         $size = 0;
         switch ($this->getPdu()->getDcs()->getTextAlphabet()) {
             case DCS::ALPHABET_DEFAULT:
                 PDU::debug("Helper::encode7bit()");
                 list($size, $part) = Helper::encode7bit($text);
                 break;
             case DCS::ALPHABET_8BIT:
                 PDU::debug("Helper::encode8BitMessage()");
                 list($size, $part) = Helper::encode8Bit($text);
                 break;
             case DCS::ALPHABET_UCS2:
                 PDU::debug("Helper::encode16BitMessage()");
                 list($size, $part) = Helper::encode16Bit($text);
                 break;
             default:
                 throw new Exception("Unknown alphabet");
         }
         if ($header) {
             $size += $headerSize;
         }
         $this->_parts[] = new Data\Part($this, $part, $size, $params);
     }
 }
Exemplo n.º 2
0
 /**
  * set phone number
  * @param string $phone
  * @param boolean $SC 
  */
 public function setPhone($phone, $SC = FALSE)
 {
     $this->_phone = $phone;
     $clear = preg_replace('/([^a-c0-9\\*\\#]*)/', NULL, $phone);
     $this->_isAddress = !$SC;
     if ($this->getType()->getType() == SCA\Type::TYPE_ALPHANUMERICAL) {
         list($this->_size, $this->_encoded) = PDU\Helper::encode7bit($clear);
     } else {
         // get size
         // service center addres counting by octets OA or DA as length numbers
         $this->_size = $SC ? 1 + (strlen($clear) + 1) / 2 : strlen($clear);
         $this->_encoded = implode("", array_map(array('self', '_map_filter_encode'), str_split($clear)));
     }
 }
Exemplo n.º 3
0
 /**
  * parse pdu string
  * @param \Data $data
  * @return array [decded text, text size, self object]
  * @throws Exception
  */
 public static function parse(Data $data)
 {
     $alphabet = $data->getPdu()->getDcs()->getTextAlphabet();
     $header = NULL;
     $length = $data->getPdu()->getUdl() * ($alphabet == PDU\DCS::ALPHABET_UCS2 ? 4 : 2);
     if ($data->getPdu()->getType()->getUdhi()) {
         PDU::debug("Header::parse()");
         $header = Header::parse();
     }
     $hex = PDU::getPduSubstr($length);
     PDU::debug("Data (hex): " . $hex);
     switch ($alphabet) {
         case PDU\DCS::ALPHABET_DEFAULT:
             PDU::debug("Helper::decode7bit()");
             $text = PDU\Helper::decode7bit($hex);
             break;
         case PDU\DCS::ALPHABET_8BIT:
             PDU::debug("Helper::decode8bit()");
             $text = PDU\Helper::decode8bit($hex);
             break;
         case PDU\DCS::ALPHABET_UCS2:
             PDU::debug("Helper::decode16Bit()");
             $text = PDU\Helper::decode16Bit($hex);
             break;
         default:
             throw new Exception("Unknown alpabet");
     }
     $size = mb_strlen($text, 'UTF-8');
     $self = new self($data, $hex, $size, $header ? $header->toArray() : NULL);
     $self->_text = $text;
     return array($text, $size, $self);
 }