📄 smppclass.php
字号:
if (empty($elength)) {$this->debug("Connection lost.\n");return;}extract(unpack("Nlength", $elength));$this->debug("Reading PDU : $length bytes.\n");$stream = fread($this->_socket, $length - 4);$this->debug("Stream len : " . strlen($stream) . "\n");extract(unpack("Ncommand_id/Ncommand_status/Nsequence_number", $stream));$command_id &= 0x0fffffff;$this->debug("Command id : $command_id.\n");$this->debug("Command status : $command_status.\n");$this->debug("sequence_number : $sequence_number.\n");$pdu = substr($stream, 12);switch ($command_id) {case CM_BIND_TRANSMITTER:$this->debug("Got CM_BIND_TRANSMITTER_RESP.\n");$spec = "asystem_id";extract($this->unpack2($spec, $pdu));$this->debug("system id : $system_id.\n");break;case CM_UNBIND:$this->debug("Got CM_UNBIND_RESP.\n");break;case CM_SUBMIT_SM:$this->debug("Got CM_SUBMIT_SM_RESP.\n");if ($command_status == 0) {$spec = "amessage_id";extract($this->unpack2($spec, $pdu));$this->debug("message id : $message_id.\n");}break;case CM_SUBMIT_MULTI:$this->debug("Got CM_SUBMIT_MULTI_RESP.\n");$spec = "amessage_id/cno_unsuccess/";extract($this->unpack2($spec, $pdu));$this->debug("message id : $message_id.\n");$this->debug("no_unsuccess : $no_unsuccess.\n");break;case CM_ENQUIRELINK:$this->debug("GOT CM_ENQUIRELINK_RESP.\n");break;default:$this->debug("Got unknown SMPP pdu.\n");break;}$this->debug("\nReceived PDU: ");for ($i = 0; $i < strlen($stream); $i++) {if (ord($stream[$i]) < 32) $this->debug("(" . ord($stream[$i]) . ")"); else $this->debug($stream[$i]);}$this->debug("\n");} while ($sequence_number != $our_sequence_number);return $command_status;}function SendPDU($command_id, $pdu){$length = strlen($pdu) + 16;$header = pack("NNNN", $length, $command_id, $this->_command_status, $this->_sequence_number);$this->debug("Sending PDU, len == $length\n");$this->debug("Sending PDU, header-len == " . strlen($header) . "\n");$this->debug("Sending PDU, command_id == " . $command_id . "\n");fwrite($this->_socket, $header . $pdu, $length);$status = $this->ExpectPDU($this->_sequence_number);$this->_sequence_number = $this->_sequence_number + 1;return $status;}function SendBindTransmitter($system_id, $smpppassword, $system_type){$system_id = $system_id . chr(0);$system_id_len = strlen($system_id);$smpppassword = $smpppassword . chr(0);$smpppassword_len = strlen($smpppassword);$system_type = $system_type . chr(0);$system_type_len = strlen($system_type);$pdu = pack("a{$system_id_len}a{$smpppassword_len}a{$system_type_len}CCCa1", $system_id, $smpppassword, $system_type, 0x33, 0, 0, chr(0));$this->debug("Bind Transmitter PDU: ");for ($i = 0; $i < strlen($pdu); $i++) {$this->debug(ord($pdu[$i]) . " ");}$this->debug("\n");$status = $this->SendPDU(CM_BIND_TRANSMITTER, $pdu);return $status;}function SendUnbind(){$pdu = "";$status = $this->SendPDU(CM_UNBIND, $pdu);return $status;}function 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){$service_type = $service_type . chr(0);$service_type_len = strlen($service_type);$source_addr = $source_addr . chr(0);$source_addr_len = strlen($source_addr);$destination_addr = $destination_addr . chr(0);$destination_addr_len = strlen($destination_addr);$schedule_delivery_time = $schedule_delivery_time . chr(0);$schedule_delivery_time_len = strlen($schedule_delivery_time);$validity_period = $validity_period . chr(0);$validity_period_len = strlen($validity_period);// $short_message = $short_message . chr(0);$message_len = $sm_length;$spec = "a{$service_type_len}cca{$source_addr_len}cca{$destination_addr_len}ccca{$schedule_delivery_time_len}a{$validity_period_len}ccccca{$message_len}";$this->debug("PDU spec: $spec.\n");$pdu = pack($spec,$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);$status = $this->SendPDU(CM_SUBMIT_SM, $pdu);return $status;}function 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){$service_type = $service_type . chr(0);$service_type_len = strlen($service_type);$source_addr = $source_addr . chr(0);$source_addr_len = strlen($source_addr);$number_destinations = count($destination_arr);$dest_flag = 1;$spec = "a{$service_type_len}cca{$source_addr_len}c";$pdu = pack($spec,$service_type,$source_addr_ton,$source_addr_npi,$source_addr,$number_destinations);$dest_flag = 1;reset($destination_arr);while (list(, $destination_addr) = each($destination_arr)) {$destination_addr .= chr(0);$dest_len = strlen($destination_addr);$spec = "ccca{$dest_len}";$pdu .= pack($spec, $dest_flag, $dest_addr_ton, $dest_addr_npi, $destination_addr);}$schedule_delivery_time = $schedule_delivery_time . chr(0);$schedule_delivery_time_len = strlen($schedule_delivery_time);$validity_period = $validity_period . chr(0);$validity_period_len = strlen($validity_period);$message_len = $sm_length;$spec = "ccca{$schedule_delivery_time_len}a{$validity_period_len}ccccca{$message_len}";$pdu .= pack($spec,$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);$this->debug("\nMulti PDU: ");for ($i = 0; $i < strlen($pdu); $i++) {if (ord($pdu[$i]) < 32) $this->debug("."); else $this->debug($pdu[$i]);}$this->debug("\n");$status = $this->SendPDU(CM_SUBMIT_MULTI, $pdu);return $status;}function split_message($text){$this->debug("In split_message.\n");$max_len = 153;$res = array();if (strlen($text) <= 160) {$this->debug("One message: " . strlen($text) . "\n");$res[] = $text;return $res;}$pos = 0;$msg_sequence = $this->_message_sequence++;$num_messages = ceil(strlen($text) / $max_len);$part_no = 1;while ($pos < strlen($text)) {$ttext = substr($text, $pos, $max_len);$pos += strlen($ttext);$udh = pack("cccccc", 5, 0, 3, $msg_sequence, $num_messages, $part_no);$part_no++;$res[] = $udh . $ttext;$this->debug("Split: UDH = ");for ($i = 0; $i < strlen($udh); $i++) {$this->debug(ord($udh[$i]) . " ");}$this->debug("\n");$this->debug("Split: $ttext.\n");}return $res;}function split_message_unicode($text){$this->debug("In split_message.\n");$max_len = 134;$res = array();if (mb_strlen($text) <= 140) {$this->debug("One message: " . mb_strlen($text) . "\n");$res[] = $text;return $res;}$pos = 0;$msg_sequence = $this->_message_sequence++;$num_messages = ceil(mb_strlen($text) / $max_len);$part_no = 1;while ($pos < mb_strlen($text)) {$ttext = mb_substr($text, $pos, $max_len);$pos += mb_strlen($ttext);$udh = pack("cccccc", 5, 0, 3, $msg_sequence, $num_messages, $part_no);$part_no++;$res[] = $udh . $ttext;$this->debug("Split: UDH = ");for ($i = 0; $i < strlen($udh); $i++) {$this->debug(ord($udh[$i]) . " ");}$this->debug("\n");$this->debug("Split: $ttext.\n");}return $res;}function unpack2($spec, $data){$res = array();$specs = explode("/", $spec);$pos = 0;reset($specs);while (list(, $sp) = each($specs)) {$subject = substr($data, $pos);$type = substr($sp, 0, 1);$var = substr($sp, 1);switch ($type) {case "N":$temp = unpack("Ntemp2", $subject);$res[$var] = $temp["temp2"];$pos += 4;break;case "c":$temp = unpack("ctemp2", $subject);$res[$var] = $temp["temp2"];$pos += 1;break;case "a":$pos2 = strpos($subject, chr(0)) + 1;$temp = unpack("a{$pos2}temp2", $subject);$res[$var] = $temp["temp2"];$pos += $pos2;break;}}return $res;}function debug($str){if ($this->_debug) {echo $str;}}};?>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -