summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorHans Duedal <hd@onlinecity.dk>2012-02-20 18:16:14 +0100
committerHans Duedal <hd@onlinecity.dk>2012-02-20 18:16:14 +0100
commit2b883a9ab3160cac91253acaa47a49c4043b621d (patch)
tree9a046993273f91a337214400d60f9cad47d8d8ff
parent7664118079141be22a4beec5cdb9709ad4c132cd (diff)
downloadphp-smpp-2b883a9ab3160cac91253acaa47a49c4043b621d.zip
php-smpp-2b883a9ab3160cac91253acaa47a49c4043b621d.tar.gz
php-smpp-2b883a9ab3160cac91253acaa47a49c4043b621d.tar.bz2
Fixed bug in IP4 validation, and added 8-bit CSMS
You can now select a CSMS method from three types; CSMS_16BIT_TAGS, CSMS_PAYLOAD or CSMS_8BIT_UDH.
-rw-r--r--README.md7
-rw-r--r--smppclient.class.php44
-rw-r--r--sockettransport.class.php2
3 files changed, 41 insertions, 12 deletions
diff --git a/README.md b/README.md
index 05d39c2..b8a6dc5 100644
--- a/README.md
+++ b/README.md
@@ -36,7 +36,7 @@ $smpp->bindTransmitter("USERNAME","PASSWORD");
// Optional connection specific overrides
//SmppClient::$sms_null_terminate_octetstrings = false;
-//SmppClient::$sms_use_msg_payload_for_csms = true;
+//SmppClient::$csms_method = SmppClient::CSMS_PAYLOAD;
//SmppClient::$sms_registered_delivery_flag = SMPP::REG_DELIVERY_SMSC_BOTH;
// Prepare message
@@ -109,6 +109,9 @@ Implementation notes
F.A.Q.
-----
+**I can't send more than 160 chars**
+There are three built-in methods to send Concatenated SMS (csms); CSMS_16BIT_TAGS, CSMS_PAYLOAD, CSMS_8BIT_UDH. CSMS_16BIT_TAGS is the default, if it don't work try another.
+
**Is this lib compatible with PHP 5.2.x ?**
It's tested on PHP 5.3, but is known to work with 5.2 as well.
@@ -134,4 +137,4 @@ It typically means your SMPP provider rejected your login credentials, ie. your
Many service providers can give you a demo account, but you can also use the [logica opensmpp simulator](http://opensmpp.logica.com/CommonPart/Introduction/Introduction.htm#simulator) (java) or [smsforum client test tool](http://www.smsforum.net/sctt_v1.0.Linux.tar.gz) (linux binary). In addition to a number of real-life SMPP servers this library is tested against these simulators.
**I have an issue that not mentioned here, what do I do?**
-Please obtain full debug information, and open an issue here on github. Make sure not to include the Send PDU hex-codes of the BindTransmitter call, since it will contain your username and password. Other hex-output is fine, and greatly appeciated. Any PHP Warnings or Notices could also be important. Please include information about what SMPP server you are connecting to, and any specifics. \ No newline at end of file
+Please obtain full debug information, and open an issue here on github. Make sure not to include the Send PDU hex-codes of the BindTransmitter call, since it will contain your username and password. Other hex-output is fine, and greatly appeciated. Any PHP Warnings or Notices could also be important. Please include information about what SMPP server you are connecting to, and any specifics.
diff --git a/smppclient.class.php b/smppclient.class.php
index 0dcbb7d..f2552e0 100644
--- a/smppclient.class.php
+++ b/smppclient.class.php
@@ -49,10 +49,24 @@ class SmppClient
public static $sms_null_terminate_octetstrings=true;
/**
- * Use the optional param, message_payload to send concatenated SMSes?
- * @var boolean
+ * Use sar_msg_ref_num and sar_total_segments with 16 bit tags
+ * @var integer
+ */
+ const CSMS_16BIT_TAGS = 0;
+
+ /**
+ * Use message payload for CSMS
+ * @var integer
+ */
+ const CSMS_PAYLOAD = 1;
+
+ /**
+ * Embed a UDH in the message with 8-bit reference.
+ * @var integer
*/
- public static $sms_use_msg_payload_for_csms=false;
+ const CSMS_8BIT_UDH = 2;
+
+ public static $csms_method = CSMS_16BIT_TAGS;
public $debug;
@@ -286,7 +300,7 @@ class SmppClient
// Figure out if we need to do CSMS, since it will affect our PDU
if ($msg_length > $singleSmsOctetLimit) {
$doCsms = true;
- if (!self::$sms_use_msg_payload_for_csms) {
+ if (!self::$csms_method != SmppClient::CSMS_PAYLOAD) {
$parts = $this->splitMessageString($message, $csmsSplit, $dataCoding);
$short_message = reset($parts);
$csmsReference = $this->getCsmsReference();
@@ -298,9 +312,17 @@ class SmppClient
// Deal with CSMS
if ($doCsms) {
- if (self::$sms_use_msg_payload_for_csms) {
+ if (self::$csms_method == SmppClient::CSMS_PAYLOAD) {
$payload = new SmppTag(SmppTag::MESSAGE_PAYLOAD, $message, $msg_length);
return $this->submit_sm($from, $to, null, (empty($tags) ? array($payload) : array_merge($tags,$payload)), $dataCoding, $priority, $scheduleDeliveryTime, $validityPeriod);
+ } else if (self::$csms_method == SmppClient::CSMS_8BIT_UDH) {
+ $seqnum = 1;
+ foreach ($parts as $part) {
+ $udh = pack('cccccc',5,0,3,substr($csmsReference,1,1),count($parts),$seqnum);
+ $res = $this->submit_sm($from, $to, $udh.$part, $tags, $dataCoding, $priority, $scheduleDeliveryTime, $validityPeriod, (SmppClient::$sms_esm_class|0x40));
+ $seqnum++;
+ }
+ return $res;
} else {
$sar_msg_ref_num = new SmppTag(SmppTag::SAR_MSG_REF_NUM, $csmsReference, 2, 'n');
$sar_total_segments = new SmppTag(SmppTag::SAR_TOTAL_SEGMENTS, count($parts), 1, 'c');
@@ -330,10 +352,13 @@ class SmppClient
* @param integer $priority
* @param string $scheduleDeliveryTime
* @param string $validityPeriod
+ * @param string $esmClass
* @return string message id
*/
- protected function submit_sm(SmppAddress $source, SmppAddress $destination, $short_message=null, $tags=null, $dataCoding=SMPP::DATA_CODING_DEFAULT, $priority=0x00, $scheduleDeliveryTime=null, $validityPeriod=null)
+ protected function submit_sm(SmppAddress $source, SmppAddress $destination, $short_message=null, $tags=null, $dataCoding=SMPP::DATA_CODING_DEFAULT, $priority=0x00, $scheduleDeliveryTime=null, $validityPeriod=null, $esmClass=null)
{
+ if (is_null($esmClass)) $esmClass = self::$sms_esm_class;
+
// Construct PDU with mandatory fields
$pdu = pack('a1cca'.(strlen($source->value)+1).'cca'.(strlen($destination->value)+1).'ccc'.($scheduleDeliveryTime ? 'a16x' : 'a1').($validityPeriod ? 'a16x' : 'a1').'ccccca'.(strlen($short_message)+(self::$sms_null_terminate_octetstrings ? 1 : 0)),
self::$sms_service_type,
@@ -343,7 +368,7 @@ class SmppClient
$destination->ton,
$destination->npi,
$destination->value,
- self::$sms_esm_class,
+ $esmClass,
self::$sms_protocol_id,
$priority,
$scheduleDeliveryTime,
@@ -374,9 +399,10 @@ class SmppClient
*/
protected function getCsmsReference()
{
- if (!isset($this->sar_msg_ref_num)) $this->sar_msg_ref_num = mt_rand(0,65535);
+ $limit = (SmppClient::$csms_method == SmppClient::CSMS_8BIT_UDH) ? 255 : 65535;
+ if (!isset($this->sar_msg_ref_num)) $this->sar_msg_ref_num = mt_rand(0,$limit);
$this->sar_msg_ref_num++;
- if ($this->sar_msg_ref_num>65535) $this->sar_msg_ref_num = 0;
+ if ($this->sar_msg_ref_num>$limit) $this->sar_msg_ref_num = 0;
return $this->sar_msg_ref_num;
}
diff --git a/sockettransport.class.php b/sockettransport.class.php
index a2773de..134ebc0 100644
--- a/sockettransport.class.php
+++ b/sockettransport.class.php
@@ -64,7 +64,7 @@ class SocketTransport
list($hostname,$port) = $host;
$ip4s = array();
$ip6s = array();
- if (preg_match('/^([12]?[0-5]?[0-9]\.){3}([12]?[0-5]?[0-9])$/',$hostname)) {
+ if (preg_match('/^([12]?[0-9]?[0-9]\.){3}([12]?[0-9]?[0-9])$/',$hostname)) {
// IPv4 address
$ip4s[] = $hostname;
} else if (preg_match('/^([0-9a-f:]+):[0-9a-f]{1,4}$/i',$hostname)) {