/** * Reads incoming PDU from SMSC. * @return SmppPdu */ protected function readPDU() { // Read PDU length $bufLength = $this->transport->read(4); if (!$bufLength) { return false; } extract(unpack("Nlength", $bufLength)); // Read PDU headers $bufHeaders = $this->transport->read(12); if (!$bufHeaders) { return false; } extract(unpack("Ncommand_id/Ncommand_status/Nsequence_number", $bufHeaders)); // Read PDU body if ($length - 16 > 0) { $body = $this->transport->readAll($length - 16); if (!$body) { throw new RuntimeException('Could not read PDU body'); } } else { $body = null; } if ($this->debug) { call_user_func($this->debugHandler, "Read PDU : {$length} bytes"); call_user_func($this->debugHandler, ' ' . chunk_split(bin2hex($bufLength . $bufHeaders . $body), 2, " ")); call_user_func($this->debugHandler, " command id : 0x" . dechex($command_id)); call_user_func($this->debugHandler, " command status : 0x" . dechex($command_status) . " " . SMPP::getStatusMessage($command_status)); call_user_func($this->debugHandler, ' sequence number : ' . $sequence_number); } return new SmppPdu($command_id, $command_status, $sequence_number, $body); }
function sendSMS($to, $message) { //SMSC Configuration $server = "127.0.0.1"; $port = 2775; $system_id = 1; $system_type = 1; $login = "******"; $pass = "******"; $to_ok = ""; $from = "1234"; //Declare $lang global in order to access it outside the function global $lang; //Pase phone number //Remove spaces from number $to = preg_replace('/\\s+/', '', $to); //Match number 12345678 if (preg_match("/^(\\d{8})\$/", trim($to), $matches)) { $to_ok = "+45" . $matches[1]; } //Match number +4512345678 if (preg_match("/^(\\+\\d+)/", trim($to), $matches)) { $to_ok = str_replace(' ', '', $matches[1]); } //If we could not match number - fail: if (!$to_ok) { print "<div class=\"alert alert-danger\" role=\"alert\">\n"; print $lang['PAGE2_SMS_ERROR1'] . " {$to}...<br/>"; print "<a href=\"javascript:history.back()\">" . $lang['RETRY'] . "</a>"; print "</div>"; die; } //Save the mobile phone no for later use $_SESSION['portal-mobile'] = $to_ok; print "<div class=\"alert alert-success\" role=\"alert\">\n"; print $lang['PAGE2_SMS_ACK'] . " " . $to_ok . "<br/>"; print "</div>"; try { #require_once "smpp.php"; $tx = new SMPP($server, $port); #$tx->debug=true; $tx->system_type = $system_type; $tx->addr_npi = 1; #print "### open status: ".$tx->state."\n"; $tx->bindTransmitter($system_id, $login); $tx->sms_source_addr_npi = 1; $tx->sms_source_addr_ton = 1; $tx->sms_dest_addr_ton = 1; $tx->sms_dest_addr_npi = 1; #Send as FLASH SMS #$tx->$sms_data_coding=240; $ret = $tx->sendSMS($from, $to_ok, $message); $tx->close(); unset($tx); } catch (ErrorException $e) { print "ERROR: {$e}"; } return $ret; }
<?php /* this is the smpp server which uses smpp_tranreceiver class * to achive it's job * SCRIPT: smpp_server.php * AUTHOR: Nawar Nory * * PLATFORM: (Linux) * */ include_once 'smpp_transceiver.php'; /* * Declartion for the smpp receiver class */ declare (ticks=1); $tx = new SMPP('10.0.59.xxx', 5018); $tx->system_type = "SMSEMAIL"; $tx->addr_npi = 1; $tx->debug = true; $tx->bindTransceiver("SEMAIL", "pass"); // specify if you want to send or receive enquire_link // 0 for receive, 1 for send $tx->start_enquire = 1; pcntl_signal(SIGINT, "sig_handler"); pcntl_signal(SIGTERM, "sig_handler"); function sig_handler($signo) { global $tx; if ($signo == SIGINT || $signo == SIGTERM) { $tx->close(); unset($tx);