Net_SMS
[ class tree: Net_SMS ] [ index: Net_SMS ] [ all elements ]

Source for file generic_smpp.php

Documentation is available at generic_smpp.php

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

Documentation generated on Mon, 11 Mar 2019 15:57:15 -0400 by phpDocumentor 1.4.4. PEAR Logo Copyright © PHP Group 2004.