⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 smppclass.php

📁 Class for SMPP Protocol for SE Domain
💻 PHP
📖 第 1 页 / 共 2 页
字号:
<?phpdefine(CM_BIND_TRANSMITTER, 0x00000002);define(CM_SUBMIT_SM, 0x00000004);define(CM_SUBMIT_MULTI, 0x00000021);define(CM_UNBIND, 0x00000006);define(CM_ENQUIRELINK, 0x00000015);class SMPPClass {// public members:/*Constructor.Parameters:none.Example:$smpp = new SMPPClass();*/function SMPPClass(){/* seed random generator */list($usec, $sec) = explode(' ', microtime());$seed = (float) $sec + ((float) $usec * 100000);srand($seed);/* initialize member variables */$this->_debug = true; /* set this to false if you want to suppress debug output. */$this->_socket = NULL;$this->_command_status = 0;$this->_sequence_number = 1;$this->_source_address = "";$this->_message_sequence = rand(1,255);}/*For SMS gateways that support sender-ID branding, the methodcan be used to set the originating address.Parameters:$from    :    Originating addressExample:$smpp->SetSender("31495595392");*/function SetSender($from){if (strlen($from) > 20) {$this->debug("Error: sender id too long.\n");return;}$this->_source_address = $from;}/*This method initiates an SMPP session.It is to be called BEFORE using the Send() method.Parameters:$host        : SMPP ip to connect to.$port        : port # to connect to.$username    : SMPP system ID$password    : SMPP passord.$system_type    : SMPP System typeReturns:true if successful, otherwise falseExample:$smpp->Start("smpp.chimit.nl", 2345, "chimit", "my_password", "client01");*/function Start($host, $port, $username, $password, $system_type){/*$testarr = stream_get_transports();$have_tcp = false;reset($testarr);while (list(, $transport) = each($testarr)) {if ($transport == "tcpp") {$have_tcp = true;}}if (!$have_tcp) {$this->debug("No TCP support in this version of PHP.\n");return false;}*/$this->_socket = fsockopen($host, $port, $errno, $errstr, 20);// todo: sanity check on input parametersif (!$this->_socket) {$this->debug("Error opening SMPP session.\n");$this->debug("Error was: $errstr.\n");return;}socket_set_timeout($this->_socket, 1200);$status = $this->SendBindTransmitter($username, $password, $system_type);if ($status != 0) {$this->debug("Error binding to SMPP server. Invalid credentials?\n");}return ($status == 0);}/*This method sends out one SMS message.Parameters:$to    : destination address.$text    : text of message to send.$unicode: Optional. Indicates if input string is html encoded unicode.Returns:true if messages sent successfull, otherwise false.Example:$smpp->Send("31649072766", "This is an SMPP Test message.");$smpp->Send("31648072766", "?????????", true);*/function Send($to, $text, $unicode = false){if (strlen($to) > 20) {$this->debug("to-address too long.\n");return;}if (!$this->_socket) {$this->debug("Not connected, while trying to send SUBMIT_SM.\n");// return;}$service_type = "";//default source TON and NPI for international sender$source_addr_ton = 1;$source_addr_npi = 1;$source_addr = $this->_source_address;if (preg_match('/\D/', $source_addr)) //alphanumeric sender{$source_addr_ton = 5;$source_addr_npi = 0;}elseif (strlen($source_addr) < 11) //national or shortcode sender{$source_addr_ton = 2;$source_addr_npi = 1;}$dest_addr_ton = 1;$dest_addr_npi = 1;$destination_addr = $to;$esm_class = 3;$protocol_id = 0;$priority_flag = 0;$schedule_delivery_time = "";$validity_period = "";$registered_delivery_flag = 0;$replace_if_present_flag = 0;$data_coding = 241;$sm_default_msg_id = 0;if ($unicode) {$text = mb_convert_encoding($text, "UCS-2BE", "HTML-ENTITIES"); /* UCS-2BE */$data_coding = 8; /* UCS2 */$multi = $this->split_message_unicode($text);}else {$multi = $this->split_message($text);}$multiple = (count($multi) > 1);if ($multiple) {$esm_class += 0x00000040;}$result = true;reset($multi);while (list(, $part) = each($multi)) {$short_message = $part;$sm_length = strlen($short_message);$status = $this->SendSubmitSM($service_type, $source_addr_ton, $source_addr_npi, $source_addr, $dest_addr_ton, $dest_addr_npi, $destination_addr, $esm_class, $protocol_id, $priority_flag, $schedule_delivery_time, $validity_period, $registered_delivery_flag, $replace_if_present_flag, $data_coding, $sm_default_msg_id, $sm_length, $short_message);if ($status != 0) {$this->debug("SMPP server returned error $status.\n");$result = false;}}return $result;}/*This method ends a SMPP session.Parameters:noneReturns:true if successful, otherwise falseExample: $smpp->End();*/function End(){if (!$this->_socket) {// not connectedreturn;}$status = $this->SendUnbind();if ($status != 0) {$this->debug("SMPP Server returned error $status.\n");}fclose($this->_socket);$this->_socket = NULL;return ($status == 0);}/*This method sends an enquire_link PDU to the server and waits for a response.Parameters:noneReturns:true if successfull, otherwise false.Example: $smpp->TestLink()*/function TestLink(){$pdu = "";$status = $this->SendPDU(CM_ENQUIRELINK, $pdu);return ($status == 0);}/*This method sends a single message to a comma separated list of phone numbers.There is no limit to the number of messages to send.Parameters:$tolist        : comma seperated list of phone numbers$text        : text of message to send$unicode: Optional. Indicates if input string is html encoded unicode string.Returns:true if messages received by smpp server, otherwise false.Example:$smpp->SendMulti("31777110204,31649072766,...,...", "This is an SMPP Test message.");*/function SendMulti($tolist, $text, $unicode = false){if (!$this->_socket) {$this->debug("Not connected, while trying to send SUBMIT_MULTI.\n");// return;}$service_type = "";$source_addr = $this->_source_address;//default source TON and NPI for international sender$source_addr_ton = 1;$source_addr_npi = 1;$source_addr = $this->_source_address;if (preg_match('/\D/', $source_addr)) //alphanumeric sender{$source_addr_ton = 5;$source_addr_npi = 0;}elseif (strlen($source_addr) < 11) //national or shortcode sender{$source_addr_ton = 2;$source_addr_npi = 1;}$dest_addr_ton = 1;$dest_addr_npi = 1;$destination_arr = explode(",", $tolist);$esm_class = 3;$protocol_id = 0;$priority_flag = 0;$schedule_delivery_time = "";$validity_period = "";$registered_delivery_flag = 0;$replace_if_present_flag = 0;$data_coding = 241;$sm_default_msg_id = 0;if ($unicode) {$text = mb_convert_encoding($text, "UCS-2BE", "HTML-ENTITIES");$data_coding = 8; /* UCS2 */$multi = $this->split_message_unicode($text);}else {$multi = $this->split_message($text);}$multiple = (count($multi) > 1);if ($multiple) {$esm_class += 0x00000040;}$result = true;reset($multi);while (list(, $part) = each($multi)) {$short_message = $part;$sm_length = strlen($short_message);$status = $this->SendSubmitMulti($service_type, $source_addr_ton, $source_addr_npi, $source_addr, $dest_addr_ton, $dest_addr_npi, $destination_arr, $esm_class, $protocol_id, $priority_flag, $schedule_delivery_time, $validity_period, $registered_delivery_flag, $replace_if_present_flag, $data_coding, $sm_default_msg_id, $sm_length, $short_message);if ($status != 0) {$this->debug("SMPP server returned error $status.\n");$result = false;}}return $result;}// private members (not documented):function ExpectPDU($our_sequence_number){do {$this->debug("Trying to read PDU.\n");if (feof($this->_socket)) {$this->debug("Socket was closed.!!\n");}$elength = fread($this->_socket, 4);

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -