Esempio n. 1
0
 /**
  * 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");
     }
 }
Esempio n. 2
0
 public function testPolishChar()
 {
     $pdu = new Submit();
     $pdu->setAddress("+48660548430");
     $pdu->setVp(3600 * 24 * 4);
     $pdu->setData("łóśćąę");
     // łóśćąę
     $parts = $pdu->getParts();
     $this->assertNotNull($parts);
     $this->assertCount(1, $parts);
     foreach ($parts as $part) {
         echo (string) $part . " == 07911356131313F301000B918466508434F000080C014200F3015B010701050119\n";
         $this->assertTrue((string) $part == '0011000B918466508434F00008AA0C014200F3015B010701050119');
     }
 }
Esempio n. 3
0
 public function sendPdu()
 {
     $pdu = new Submit();
     $pdu->setAddress($this->argument('number'));
     $pdu->setData($this->argument('message'));
     $promises = [];
     foreach ($pdu->getParts() as $part) {
         $promises[] = $this->request('DongleSendPdu', ['Device' => $this->getDevice(), 'PDU' => (string) $part]);
     }
     $promise = \React\Promise\map($promises, function (Response $response) {
         Event::fire('ami.dongle.sms.sended', [$this, $response]);
         $message = Arr::get($response->getFields(), 'Message', null);
         $this->line($message);
     });
     $promise->then([$this, 'stop'], [$this, 'writeException']);
 }
Esempio n. 4
0
 /**
  * get pdu object by type
  * @return Deliver|Submit|Report
  * @throws Exception
  */
 public static function getPduByType()
 {
     // parse type of sms
     $type = Type::parse();
     $self = NULL;
     switch ($type->getMti()) {
         case Type::SMS_DELIVER:
             $self = new Deliver();
             break;
         case Type::SMS_SUBMIT:
             $self = new Submit();
             // get mr
             $self->setMr(hexdec(PDU::getPduSubstr(2)));
             break;
         case Type::SMS_REPORT:
             $self = new Report();
             // get reference
             $self->setReference(hexdec(PDU::getPduSubstr(2)));
             break;
         default:
             throw new Exception("Unknown sms type");
     }
     // set type
     $self->setType($type);
     return $self;
 }