function smpp_send($smpp_hosts, $smpp_port, $smpp_login, $smpp_password, $smpp_from, $smpp_to, $message) { require_once '../httpsdocs/includes/smpp/smppclient.class.php'; require_once '../httpsdocs/includes/smpp/gsmencoder.class.php'; require_once '../httpsdocs/includes/smpp/sockettransport.class.php'; // Construct transport and client $transport = new SocketTransport($smpp_hosts, $smpp_port); $transport->setRecvTimeout(10000); $smpp = new SmppClient($transport); // Activate binary hex-output of server interaction $smpp->debug = false; $transport->debug = false; $transport->open(); $smpp->bindTransmitter($smpp_login, $smpp_password); // Optional connection specific overrides SmppClient::$sms_null_terminate_octetstrings = false; SmppClient::$csms_method = SmppClient::CSMS_PAYLOAD; SmppClient::$sms_registered_delivery_flag = SMPP::REG_DELIVERY_SMSC_BOTH; // Prepare message $tags = "CSMS_16BIT_TAGS"; if (preg_match('/^[\\p{Cyrillic}\\p{Common}]+$/u', $message)) { $data_coding = SMPP::DATA_CODING_UCS2; $encodedMessage = iconv("UTF-8", "UCS-2BE", $message); } else { $data_coding = SMPP::DATA_CODING_ISO8859_1; } if (is_null($encodedMessage)) { $encodedMessage = $message; } $from = new SmppAddress($smpp_from, SMPP::TON_ALPHANUMERIC); $to = new SmppAddress($smpp_to, SMPP::TON_INTERNATIONAL, SMPP::NPI_E164); // Send if ($smpp_id = $smpp->sendSMS($from, $to, $encodedMessage, $tags, $data_coding)) { // Close connection $smpp->close(); return trim($smpp_id); } else { // Close connection $smpp->close(); return false; } }
/** * {@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; }
require_once 'gsmencoder.class.php'; require_once 'sockettransport.class.php'; // Construct transport and client $transport = new SocketTransport(array('127.0.0.1'), 2775); $transport->setRecvTimeout(100000); $smpp = new SmppClient($transport); // Activate binary hex-output of server interaction $smpp->debug = true; $transport->debug = true; // Open the connection $transport->open(); $smpp->bindTransmitter("demouser", "demopass"); // Optional connection specific overrides //SmppClient::$sms_null_terminate_octetstrings = false; //SmppClient::$csms_method = SmppClient::CSMS_PAYLOAD; //SmppClient::$sms_registered_delivery_flag = SMPP::REG_DELIVERY_SMSC_BOTH; // Prepare message $tags = array(); $from = new SmppAddress('SMSIND', SMPP::TON_ALPHANUMERIC); $to = new SmppAddress(919942012345, SMPP::TON_INTERNATIONAL, SMPP::NPI_E164); for ($i = 0; $i < 1; $i++) { $message = 'Hello sms from Mr.ABC' . $i . '.'; //$encodedMessage = $message; $encodedMessage = utf8_encode($message); // $encodedMessage = GsmEncoder::utf8_to_gsm0338($message); // Send $msgid = $smpp->sendSMS($from, $to, $encodedMessage, $tags); print 'message ref id: ' . $msgid; } // Close connection $smpp->close();
function smpp_send($smpp_hosts, $smpp_port, $smpp_login, $smpp_password, $smpp_from, $smpp_to, $smpp_msg) { $transport = new SocketTransport($smpp_hosts, $smpp_port); $transport->setRecvTimeout(60000); $smpp = new SmppClient($transport); $tags = "CSMS_16BIT_TAGS"; $data_coding = SMPP::DATA_CODING_ISO8859_5; // Cyrillic $smpp->debug = false; $transport->debug = false; $transport->open(); $smpp->bindTransmitter($smpp_login, $smpp_password); $message = $smpp_msg; $encodedMessage = $message; $from = new SmppAddress($smpp_from, SMPP::TON_ALPHANUMERIC); $to = new SmppAddress($smpp_to, SMPP::TON_INTERNATIONAL, SMPP::NPI_E164); if ($smpp_id = $smpp->sendSMS($from, $to, $encodedMessage, $tags, $data_coding)) { $smpp->close(); return trim($smpp_id); } else { $smpp->close(); return false; } }
private function smpp_send($smpp_from, $smpp_to, $message) { global $smpp_hosts, $smpp_port, $smpp_login, $smpp_password; // Construct transport and client $transport = new SocketTransport($smpp_hosts, $smpp_port); $transport->setRecvTimeout(10000); $smpp = new SmppClient($transport); // Activate binary hex-output of server interaction $smpp->debug = false; $transport->debug = false; $transport->open(); $smpp->bindTransmitter($smpp_login, $smpp_password); // Optional connection specific overrides SmppClient::$sms_null_terminate_octetstrings = false; SmppClient::$csms_method = SmppClient::CSMS_PAYLOAD; SmppClient::$sms_registered_delivery_flag = SMPP::REG_DELIVERY_SMSC_BOTH; // Prepare message $tags = "CSMS_16BIT_TAGS"; if (preg_match('/[\\p{Cyrillic}\\p{Common}]+/u', $message)) { $data_coding = SMPP::DATA_CODING_UCS2; $encodedMessage = iconv("UTF-8", "UCS-2BE", $message); } else { $data_coding = SMPP::DATA_CODING_ISO8859_1; $encodedMessage = $message; } $from = new SmppAddress($smpp_from, SMPP::TON_ALPHANUMERIC); $to = new SmppAddress($smpp_to, SMPP::TON_INTERNATIONAL, SMPP::NPI_E164); if (!($smpp_id = $smpp->sendSMS($from, $to, $encodedMessage, $tags, $data_coding))) { $smpp->close(); throw new Exception('SMPP send error'); } $smpp_id = trim($smpp_id); $fields = ['from' => $smpp_from, 'phonenumber' => $smpp_to, 'msg' => $message, 'full_msg' => $smpp_id, 'direction' => 1, 'method' => 'smpp']; if (!($sms_id = $this->insert_into_db('sms', $fields))) { throw new Exception('SMPP Error insert into DB ' . $this->db->error); } $fields['dt'] = date('Y-m-d H:i:s'); $fields['result'] = 'OK'; $fields['process'] = '1'; if (!$this->update_into_db('sms', $sms_id, $fields)) { throw new Exception('SMPP Error update into DB ' . $this->db->error); } return $sms_id; }