예제 #1
0
파일: Sender.php 프로젝트: Jay1991/Sms
 /**
  * {@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;
 }