Exemplo n.º 1
0
 /**
  * {@inheritDoc}
  */
 public function match(SmsInterface $sms)
 {
     foreach ($this->gateways as $gateway) {
         if (!$this->supports($gateway)) {
             throw new InvalidGatewayException();
         }
         foreach ($gateway->getPrefixCodes() as $prefixCode) {
             $recipient = $sms->getRecipient();
             if ($prefixCode != '' && strrpos($recipient, $prefixCode, -strlen($recipient)) !== false) {
                 return $gateway;
             }
         }
     }
     return null;
 }
Exemplo n.º 2
0
 /**
  * {@inheritDoc}
  */
 public function send(SmsInterface $sms, GatewayInterface $gateway)
 {
     // Get the gateway configurations
     $configs = $gateway->getConfigs();
     // Create a new socket transport
     $transport = new \SocketTransport(array($gateway->getHost()), $gateway->getPort(), $configs['persistent']);
     $transport->setSendTimeout($configs['send_timeout']);
     $transport->setRecvTimeout($configs['receive_timeout']);
     $transport->debug = $configs['debug'];
     // Create a new SMPP client
     $smpp = new \SmppClient($transport);
     $smpp->debug = $configs['debug'];
     // Open the connection
     $transport->open();
     $smpp->bindTransmitter($gateway->getUsername(), $gateway->getPassword());
     // Configure a sender, recipient and message
     $sender = new \SmppAddress($sms->getSender(), $configs['sender']['ton'], $configs['sender']['npi']);
     $recipient = new \SmppAddress($sms->getRecipient(), $configs['recipient']['ton'], $configs['recipient']['npi']);
     $message = \GsmEncoder::utf8_to_gsm0338($sms->getMessage());
     // Send an SMS and close the connection
     $messageId = $smpp->sendSMS($sender, $recipient, $message);
     $smpp->close();
     return $messageId;
 }