示例#1
0
文件: SCTS.php 项目: jackkum/phppdu
 /**
  * parse pdu string
  * @return \self
  */
 public static function parse()
 {
     $hex = PDU::getPduSubstr(14);
     $params = array_merge(array("20%02d-%02d-%02d %02d:%02d:%02d"), array_map('intval', array_map('strrev', str_split($hex, 2))));
     $dtime = call_user_func_array('sprintf', $params);
     return new self($dtime);
 }
示例#2
0
文件: VP.php 项目: jackkum/phppdu
 /**
  * parse pdu string
  * @param PDU $pdu
  * @return \self
  * @throws Exception
  */
 public static function parse(Submit $pdu)
 {
     $vp = new self($pdu);
     switch ($pdu->getType()->getVpf()) {
         case Type::VPF_NONE:
             return $vp;
         case Type::VPF_ABSOLUTE:
             return SCTS::parse();
         case Type::VPF_RELATIVE:
             $byte = hexdec(PDU::getPduSubstr(2));
             if ($byte <= 143) {
                 $vp->_interval = ($byte + 1) * (5 * 60);
             } else {
                 if ($byte <= 167) {
                     $vp->_interval = 3600 * 24 * 12 + ($byte - 143) * (30 * 60);
                 } else {
                     if ($byte <= 196) {
                         $vp->_interval = ($byte - 166) * (3600 * 24);
                     } else {
                         $vp->_interval = ($byte - 192) * (3600 * 24 * 7);
                     }
                 }
             }
             return $vp;
         default:
             throw new Exception("Unknown VPF");
     }
 }
示例#3
0
文件: Type.php 项目: jackkum/phppdu
 /**
  * parse sms type
  * @return PDU\Type
  * @throws Exception
  */
 public static function parse()
 {
     $byte = hexdec(PDU::getPduSubstr(2));
     $type = NULL;
     switch (3 & $byte) {
         case self::SMS_DELIVER:
             $type = new Type\Deliver();
             break;
         case self::SMS_SUBMIT:
             $type = new Type\Submit();
             break;
         case self::SMS_REPORT:
             $type = new Type\Report();
             break;
         default:
             throw new Exception("Unknown type sms");
     }
     $type->_rp = 1 & $byte >> 7;
     $type->_udhi = 1 & $byte >> 6;
     $type->_srr = 1 & $byte >> 5;
     $type->_vpf = 3 & $byte >> 3;
     $type->_rd = 1 & $byte >> 2;
     $type->_mti = 3 & $byte;
     return $type;
 }
示例#4
0
文件: PID.php 项目: jackkum/phppdu
 public static function parse()
 {
     $byte = hexdec(PDU::getPduSubstr(2));
     $self = new self();
     $self->setPid($byte >> 6);
     $self->setIndicates($byte >> 5);
     $self->setType($byte);
     return $self;
 }
示例#5
0
文件: Header.php 项目: jackkum/phppdu
 /**
  * parse header
  * @return \self
  */
 public static function parse()
 {
     $udhl = hexdec(PDU::getPduSubstr(2));
     $type = hexdec(PDU::getPduSubstr(2));
     $psize = hexdec(PDU::getPduSubstr(2));
     $pointer = hexdec(PDU::getPduSubstr(($psize - 2) * 2));
     // psize is pointer + segments + current
     $sergments = hexdec(PDU::getPduSubstr(2));
     $current = hexdec(PDU::getPduSubstr(2));
     $self = new self(array('UDHL' => $udhl, 'TYPE' => $type, 'PSIZE' => $psize, 'POINTER' => $pointer, 'SEGMENTS' => $sergments, 'CURRENT' => $current));
     return $self;
 }
示例#6
0
文件: SCA.php 项目: jackkum/phppdu
 /**
  * magic method for cast to string
  * @return srting|null
  */
 public function __toString()
 {
     $PDU = sprintf("%02X", $this->getSize());
     if ($this->getSize()) {
         $PDU .= $this->getType();
         if ($this->getType()->getType() != SCA\Type::TYPE_ALPHANUMERICAL) {
             // reverse octets
             $l = strlen($this->_encoded);
             for ($i = 0; $i < $l; $i += 2) {
                 $b1 = substr($this->_encoded, $i, 1);
                 $b2 = $i + 1 >= $l ? 'F' : substr($this->_encoded, $i + 1, 1);
                 // add to pdu
                 $PDU .= $b2 . $b1;
             }
         }
     }
     PDU::debug("SCA::__toString() " . $PDU);
     return $PDU;
 }
示例#7
0
文件: Data.php 项目: jackkum/phppdu
 /**
  * split message
  * @param integer $max
  * @return array
  */
 protected function _splitMessage($max, $header = self::HEADER_SIZE)
 {
     // size less or equal max
     PDU::debug("Size: " . $this->getSize() . " <= " . $max);
     if ($this->getSize() <= $max) {
         return array($this->_data);
     }
     // parts of message
     $data = array();
     $offset = 0;
     $size = $max - $header;
     while (TRUE) {
         $part = mb_substr($this->_data, $offset, $size, 'UTF-8');
         PDU::debug("Part[" . $size . "]: " . $part);
         $data[] = $part;
         $offset += $size;
         if ($offset >= $this->getSize()) {
             break;
         }
     }
     return $data;
 }
示例#8
0
文件: Part.php 项目: jackkum/phppdu
 /**
  * magic method for cast part to string
  * @return string
  */
 public function __toString()
 {
     PDU::debug("_getPduString() " . $this->_getPduString());
     PDU::debug("_getPartSize() " . $this->_getPartSize());
     PDU::debug("getHeader() " . $this->getHeader());
     PDU::debug("getData() " . $this->getData());
     // concate pdu, size of part, headers, data
     return $this->_getPduString() . $this->_getPartSize() . $this->getHeader() . $this->getData();
 }
示例#9
0
文件: DCS.php 项目: jackkum/phppdu
 /**
  * parse pdu string
  * @return \self
  */
 public static function parse()
 {
     $DCS = new self();
     $byte = hexdec(PDU::getPduSubstr(2));
     $DCS->_encodeGroup = 0xf & $byte >> 4;
     $DCS->_dataEncoding = 0xf & $byte;
     $DCS->_alphabet = 3 & $DCS->_dataEncoding >> 2;
     $DCS->_classMessage = 3 & $DCS->_dataEncoding;
     switch ($DCS->_encodeGroup) {
         case 0xc:
             $DCS->_discardMessage = TRUE;
             break;
         case 0xd:
             $DCS->_storeMessage = TRUE;
             break;
         case 0xe:
             $DCS->_storeMessageUCS2 = TRUE;
             break;
         case 0xf:
             $DCS->_dataCodingAndMessageClass = TRUE;
             if ($DCS->_dataEncoding & 1 << 2) {
                 $DCS->_alphabet = self::ALPHABET_8BIT;
             }
             break;
         default:
             if ($DCS->_encodeGroup & 1 << 4) {
                 $DCS->_useMessageClass = TRUE;
             }
             if ($DCS->_encodeGroup & 1 << 5) {
                 $DCS->_compressedText = TRUE;
             }
     }
     if ($DCS->_discardMessage || $DCS->_storeMessage || $DCS->_storeMessageUCS2) {
         if ($DCS->_dataEncoding & 1 << 3) {
             $DCS->_messageIndication = TRUE;
             $DCS->_messageIndicationType = 3 & $DCS->_dataEncoding;
         }
     }
     return $DCS;
 }
示例#10
0
文件: Helper.php 项目: jackkum/phppdu
 public static function initVars(PDU $pdu)
 {
     // if is the report status
     if ($pdu->getType() instanceof Type\Report) {
         // parse timestamp
         $pdu->setDateTime(SCTS::parse());
         // parse discharge
         $pdu->setDischarge(SCTS::parse());
         // get status
         $pdu->setStatus(hexdec(PDU::getPduSubstr(2)));
     } else {
         // get pid
         $pdu->setPid(PDU\PID::parse());
         // parse dcs
         $pdu->setDcs(DCS::parse());
         // if this submit sms
         if ($pdu->getType() instanceof Type\Submit) {
             // parse vp
             $pdu->setVp(VP::parse($pdu));
         } else {
             // parse scts
             $pdu->setScts(SCTS::parse());
         }
         // get data length
         $pdu->setUdl(hexdec(PDU::getPduSubstr(2)));
         // parse data
         $pdu->setData(Data::parse($pdu));
     }
     return $pdu;
 }
示例#11
0
 public function testDeliverParse()
 {
     $pdu = PDU::parse('0791448720003023240DD0E474D81C0EBB010000111011315214000BE474D81C0EBB5DE3771B');
     $this->assertTrue($pdu instanceof Deliver);
     $this->assertTrue('diafaan' == $pdu->getAddress()->getPhone());
     $this->assertTrue('diafaan.com' == $pdu->getData()->getData());
 }