1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203
|
<?php
include_once 'Net/SMPP/Client.php';
/**
* SMPP based SMS driver.
*
* This driver interfaces with the email-to-sms gateways provided by many
* carriers, particularly those based in the U.S.
*
* $Horde: framework/Net_SMS/SMS/generic_smpp.php,v 1.2.2.1 2007/12/20 13:49:23 jan Exp $
*
* Copyright 2005-2007 WebSprockets, LLC
*
* See the enclosed file COPYING for license information (LGPL). If you
* did not receive this file, see http://www.fsf.org/copyleft/lgpl.html.
*
* @category Networking
* @package Net_SMS
* @author Ian Eure <ieure@php.net>
* @link http://pear.php.net/package/Net_SMS
* @since Net_SMS 0.2.0
* @since Horde 3.2
*/
class Net_SMS_generic_smpp extends Net_SMS {
/**
* Capabilities of this driver
*
* @var array
*/
var $capabilities = array(
'auth' => true,
'batch' => false,
'multi' => false,
'receive' => false,
'credit' => false,
'addressbook' => false,
'lists' => false
);
/**
* Driver parameters
*
* @var array
* @access private
*/
var $_params = array(
'host' => null,
'port' => 0,
'vendor' => null,
'bindParams' => array(),
'submitParams' => array()
);
/**
* Net_SMPP_Client instance
*
* @var Net_SMPP_Client
* @access private
*/
var $_client = null;
/**
* Constructor.
*
* @param array $params Parameters.
*/
function Net_SMS_generic_smpp($params = null)
{
parent::Net_SMS($params);
$this->_client =& new Net_SMPP_Client($this->_params['host'], $this->_params['port']);
if (!is_null($this->_params['vendor'])) {
Net_SMPP::setVendor($this->_params['vendor']);
}
}
/**
* Identifies this driver.
*
* @return array Driver info.
*/
function getInfo()
{
return array(
'name' => _("SMPP Gateway"),
'desc' => _("This driver allows sending of messages through an SMPP gateway.")
);
}
/**
* Get required paramaters
*
* @return array Array of required parameters.
*/
function getParams()
{
return array(
'host' => array(
'label' => _("Host"), 'type' => 'text'),
'port' => array(
'label' => _("Port"), 'type' => 'int'),
// 'bindParams' => array(
// 'label' => _('bind_transmitter paramaters'), 'type' => 'array'),
// 'submitParams' => array(
// 'label' => _('submit_sm parameters'), 'type' => 'array'
// )
);
}
/**
* Sends the message.
*
* @access private
*
* @param array $message Message to send.
* @param string $to The recipient.
*
* @return array An array with the success status and additional
* information.
*/
function _send($message, $to)
{
$pdu =& Net_SMPP::PDU('submit_sm', $this->_params['submitParams']);
$pdu->destination_addr = $to;
$pdu->short_message = $message['text'];
if (count($message) > 1) {
// Other params to set
$v = $message;
unset($v['text']);
$pdu->set($v);
unset($v);
}
$res =& $this->_client->sendPDU($pdu);
// Error sending?
if ($res === false) {
return array(0, _("Error sending PDU"));
}
$resp =& $this->_client->readPDU();
if ($resp === false) {
return array(0, _("Could not read response PDU"));
}
if ($resp->isError()) {
return array(0, sprintf(_("Sending failed: %s") . $resp->statusDesc()));
}
// Success!
return array(1, $resp->message_id);
}
/**
* Authenticates with the SMSC.
*
* This method connects to the SMSC (if not already connected) and
* authenticates with the bind_transmitter command (if not already bound).
*
* @access protected
*/
function _authenticate()
{
if ($this->_client->state == NET_SMPP_CLIENT_STATE_CLOSED) {
$res = $this->_client->connect();
if ($res === false) {
return false;
}
}
if ($this->_client->state == NET_SMPP_CLIENT_STATE_OPEN) {
$resp =& $this->_client->bind($this->_params['bindParams']);
if ($resp === false || (is_object($resp) && $resp->isError())) {
return false;
}
}
return true;
}
/**
* Accepts an object.
*
* @see Net_SMPP_Client::accept()
*
* @return mixed {@link Net_SMPP_Client::accept()}'s return value
*/
function accept(&$obj)
{
return $this->_client->accept($obj);
}
/**
* Returns a list of parameters specific for this driver.
*
* @return array Default sending parameters.
*/
function getDefaultSendParams()
{
return array();
}
}
|