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; } }
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; }