DLT Tag #11
-
We are from India. We cannot send sms without DLT / PEID. No idea how DLT is tagged on this. Can you help? |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
Hello, something like this: <?php
declare(strict_types=1);
namespace app\components\Sms;
use Exception;
use smpp\{Address, Client as SmppClient, Smpp, Tag, transport\Socket};
class SmsBuilder
{
/** @var string 11 chars limit */
public const DEFAULT_SENDER = 'example';
protected Socket $transport;
protected SmppClient $smppClient;
protected bool $debug = false;
protected Address $from;
protected Address $to;
protected string $login;
protected string $password;
protected ?array $tags = null;
/**
* SmsBuilder constructor.
*
* @param string $address SMSC IP
* @param int $port SMSC port
* @param string $login
* @param string $password
* @param int $timeout timeout of reading PDU in milliseconds
* @param bool $debug - debug flag when true output additional info
*/
public function __construct(
string $address,
int $port,
string $login,
string $password,
int $timeout = 10000,
bool $debug = false
) {
$this->transport = new Socket([$address], $port);
// Activate binary hex-output of server interaction
$this->transport->debug = $debug;
$this->transport->setRecvTimeout($timeout);
$this->smppClient = new SmppClient($this->transport);
$this->login = $login;
$this->password = $password;
$this->from = new Address(self::DEFAULT_SENDER, SMPP::TON_ALPHANUMERIC);
$peId = getenv('PEID'); // DLT approved PEID (unique Entity ID)
$templateId = getenv('PEID'); // DLT approved Template ID
$this->tags = [
new Tag(0x1470, $peId, strlen((string)$peId)),
new Tag(0x1471, $templateId, strlen((string)$templateId))
];
}
/**
* @param string $sender
* @param int $ton
*
* @return $this
* @throws Exception
*/
public function setSender(string $sender, int $ton): SmsBuilder
{
return $this->setAddress($sender, 'from', $ton);
}
/**
* @param string $address
* @param string $type
* @param int $ton
* @param int $npi
*
* @return $this
* @throws Exception
*/
protected function setAddress(
string $address,
string $type,
int $ton = SMPP::TON_UNKNOWN,
int $npi = SMPP::NPI_UNKNOWN
): SmsBuilder {
// some example of data preparation
if ($ton === SMPP::TON_INTERNATIONAL) {
$npi = SMPP::NPI_E164;
}
$this->$type = new Address($address, $ton, $npi);
return $this;
}
/**
* @param string $address
* @param int $ton
*
* @return $this
* @throws Exception
*/
public function setRecipient(string $address, int $ton): SmsBuilder
{
return $this->setAddress($address, 'to', $ton);
}
/**
* @param string $message
*
* @throws Exception
*/
public function sendMessage(string $message): void
{
$this->transport->open();
$this->smppClient->bindTransceiver($this->login, $this->password);
// strongly recommend use SMPP::DATA_CODING_UCS2 as default encoding in project to prevent problems with non latin symbols
$this->smppClient->sendSMS($this->from, $this->to, $message, $this->tags, SMPP::DATA_CODING_UCS2);
$this->smppClient->close();
}
} its not a best practice - its just example, values 0x1470 and 0x1471 would works only with vonage |
Beta Was this translation helpful? Give feedback.
Hello,
it seems like you need to add two tags for messages (depended on your SMS gateway provider)
something like this: