Source for file soapclient.php

Documentation is available at soapclient.php

  1. <?php
  2. /**
  3.  * smsAPI_SOAPClient
  4.  *
  5.  * Copyright (c) 2010, ComVision
  6.  * All rights reserved.
  7.  *
  8.  * Redistribution and use in source and binary forms, with or without modification,
  9.  * are permitted provided that the following conditions are met:
  10.  *
  11.  *  - Redistributions of source code must retain the above copyright notice,
  12.  *    this list of conditions and the following disclaimer.
  13.  *  - Redistributions in binary form must reproduce the above copyright notice,
  14.  *    this list of conditions and the following disclaimer in the documentation and/or
  15.  *    other materials provided with the distribution.
  16.  *  - Neither the name of the smsAPI.pl nor the names of its contributors may be used to
  17.  *    endorse or promote products derived from this software without specific prior written permission.
  18.  *
  19.  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
  20.  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
  21.  * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
  22.  * IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY
  23.  * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  24.  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
  25.  * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
  26.  * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
  27.  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  28.  *
  29.  * @author ComVision <info@smsapi.pl>
  30.  * @copyright 2010 ComVision
  31.  * @license BSD-3
  32.  * @package smsapi
  33.  * @subpackage client\soap
  34.  * @version 1.0 14.10.2010
  35.  */
  36.  
  37. /**
  38.  * Client smsAPI przez SOAP
  39.  *
  40.  * Przyklad:
  41.  * <code>
  42.  * require_once 'smsapi.php';
  43.  * spl_autoload_register(array('smsAPI','__autoload'));
  44.  *
  45.  * try {
  46.  *
  47.  *     $smsapi = new smsAPI_SOAPClient('login', md5('password') );
  48.  *
  49.  *     $msg = $smsapi->new_sms_multi();
  50.  *     $msg->recipient    = array('xxxxxxxxx','yyyyyyyyy');
  51.  *     $msg->message    = 'test';
  52.  *     $msg->eco        = TRUE;
  53.  *     $msg->flash        = FALSE;
  54.  *     $result = $msg->send();
  55.  *
  56.  *     var_dump($result);
  57.  * }
  58.  * catch ( Exception $e )
  59.  * {
  60.  *     echo $e->getMessage();
  61.  * }
  62.  * </code>
  63.  *
  64.  * @see https://www.smsapi.pl/webservices/v2/?wsdl
  65.  */
  66. {
  67.     /**
  68.      * @var SoapClient 
  69.      */
  70.     protected $h_sopa = null;
  71.  
  72.     /**
  73.      * Dane klienta
  74.      *
  75.      * @var array 
  76.      */
  77.     protected $client;
  78.  
  79.     /**
  80.      * Inicializacjia
  81.      *
  82.      * @param bool $ssl SOAP przez http lub https
  83.      */
  84.     public function  __construct($username$password$ssl true)
  85.     {
  86.         $this->h_sopa = new SoapClient(
  87.             $ssl == true 'https' 'http' .'://www.smsapi.pl/soap/v2/webservice?wsdl',
  88.             array(
  89.                 'features'        => SOAP_SINGLE_ELEMENT_ARRAYS,
  90.                 'cache_wsdl'    => WSDL_CACHE_NONE
  91.             )
  92.         );
  93.  
  94.         $this->client = array(
  95.  
  96.             'username'    => $username,
  97.             'password'    => $password
  98.         );
  99.     }
  100.  
  101.     /**
  102.      * Wysylanie pojedynczej wiadomosci
  103.      *
  104.      * @throws SoapFault
  105.      * @param smsAPI_SOAP_SMS $sms 
  106.      * @return smsAPI_SOAP_Response_SMS 
  107.      */
  108.     public function send_sms($sms)
  109.     {
  110.         if!($sms instanceof smsAPI_SOAP_SMS) )
  111.             throw new smsAPI_Exception('Invalid function argument'-18);
  112.  
  113.         $request array(
  114.             'client'    => $this->client,
  115.             'sms'        => $sms->_get_params()
  116.         );
  117.         $response $this->___soapCall('send_sms'$request );
  118.  
  119.         if!isset($response->response) ) $response->response array();
  120.  
  121.         return $response;
  122.     }
  123.  
  124.     /**
  125.      * @param array $params 
  126.      * @return smsAPI_SOAP_SMS 
  127.      */
  128.     public function new_sms($params null)
  129.     {
  130.         return new smsAPI_SOAP_SMS($params$this);
  131.     }
  132.  
  133.     /**
  134.      * Wysylanie wiadomosci masowych
  135.      *
  136.      * @throws SoapFault
  137.      * @param smsAPI_SOAP_SMSMulti $sms 
  138.      * @return smsAPI_SOAP_Response_SMS 
  139.      */
  140.     public function send_sms_multi($sms)
  141.     {
  142.         if!($sms instanceof smsAPI_SOAP_SMSMulti) )
  143.             throw new smsAPI_Exception('Invalid function argument'-18);
  144.  
  145.         $request array(
  146.             'client'    => $this->client,
  147.             'sms'        => $sms->_get_params()
  148.         );
  149.         $response $this->___soapCall('send_sms_multi'$request);
  150.  
  151.         if!isset($response->response) ) $response->response array();
  152.  
  153.         return $response;
  154.     }
  155.  
  156.     /**
  157.      * @param array $params 
  158.      * @return smsAPI_SOAP_SMSMulti 
  159.      */
  160.     public function new_sms_multi($params null)
  161.     {
  162.         return new smsAPI_SOAP_SMSMulti($params$this);
  163.     }
  164.  
  165.     /**
  166.      * Sprawdzanie raportow doreczenia wiadomosci po wskazaniu ich ID
  167.      *
  168.      * @throws SoapFault
  169.      * @param array $ids 
  170.      * @return smsAPI_SOAP_Response_SMSStatus 
  171.      */
  172.     public function get_sms_by_ids($ids)
  173.     {
  174.         if!is_array($ids) )
  175.             $ids func_get_args();
  176.  
  177.         if!is_array($ids) )
  178.             throw new smsAPI_Exception('Invalid function argument'-18);
  179.  
  180.         $request array(
  181.             'client'    => $this->client,
  182.             'ids'        => (array)$ids
  183.         );
  184.         $response $this->___soapCall('get_sms_by_ids'$request);
  185.  
  186.         return $response;
  187.     }
  188.  
  189.     /**
  190.      * Sprawdzanie raportow doreczenia wiadomosci wyslanych w okreslonym przedziale czasowym
  191.      *
  192.      * @throws SoapFault
  193.      * @param int $from 
  194.      * @param int $until 
  195.      * @return smsAPI_SOAP_Response_SMSStatus 
  196.      */
  197.     public function get_sms_by_date($from$until)
  198.     {
  199.         $request array(
  200.             'client'    => $this->client,
  201.             'from'        => (int)$from,
  202.             'until'        => (int)$until
  203.         );
  204.         $response $this->___soapCall('get_sms_by_date'$request);
  205.  
  206.         if!isset($response->status) ) $response->status array();
  207.  
  208.         return $response;
  209.     }
  210.  
  211.     /**
  212.      * Usuwanie wiadomosci zaplanowanych
  213.      *
  214.      * @throws SoapFault
  215.      * @param string $id 
  216.      * @return smsAPI_SOAP_Response 
  217.      */
  218.     public function delete_sms_by_id($id)
  219.     {
  220.         if!isset($idOR empty($id) )
  221.             throw new smsAPI_Exception('Invalid function argument'-18);
  222.  
  223.         $request array(
  224.             'client'    => $this->client,
  225.             'id'        => (string)$id
  226.         );
  227.         $response $this->___soapCall('delete_sms_by_id'$request);
  228.  
  229.         if!isset($response->status) ) $response->status array();
  230.  
  231.         return $response;
  232.     }
  233.  
  234.     /**
  235.      * Dodawanie grupy do ksiazki telefonicznej
  236.      *
  237.      * @throws SoapFault
  238.      * @param string $name Nazwa grupy
  239.      * @param string $info Opis grupy
  240.      * @return smsAPI_SOAP_Response_AddGroup 
  241.      */
  242.     public function add_group($name$info '')
  243.     {
  244.         if!isset($nameOR empty($name) )
  245.             throw new smsAPI_Exception('Invalid function argument'-18);
  246.  
  247.         $request array(
  248.             'client'    => $this->client,
  249.             'name'        => (string)$name,
  250.             'info'        => (string)$info
  251.         );
  252.         $response $this->___soapCall('add_group'$request);
  253.  
  254.         return $response;
  255.     }
  256.  
  257.     /**
  258.      * Pobiera grupy z ksiazki telefonicznej uzytkownika
  259.      *
  260.      * @throws SoapFault
  261.      * @return smsAPI_SOAP_Response_GetGroups 
  262.      */
  263.     public function get_groups()
  264.     {
  265.         $response $this->___soapCall('get_groups'$this->client);
  266.  
  267.         return $response;
  268.     }
  269.  
  270.     /**
  271.      * Usuwa grupe z ksiazki telefonicznej
  272.      *
  273.      * @throws SoapFault
  274.      * @param int $group_id    ID grupy w ksiazce telefonicznej
  275.      * @return smsAPI_SOAP_Response 
  276.      */
  277.     public function delete_group($group_id)
  278.     {
  279.         if!($group_id 0) )
  280.             throw new smsAPI_Exception('Invalid function argument'-18);
  281.  
  282.         $request array(
  283.             'client'    => $this->client,
  284.             'group_id'    => (int)$group_id
  285.         );
  286.         $response $this->___soapCall('delete_group'$request);
  287.  
  288.         return $response;
  289.     }
  290.  
  291.     /**
  292.      * Dodaje numer do ksiazki telefonicznej
  293.      *
  294.      * @throws SoapFault
  295.      * @param string $number    Nazwa grupy
  296.      * @param string $name        Nazwa w ksiazce telefonicznej
  297.      * @param int $group_id        Numer grupy uzytkownik'ow w ksiazce telefonicznej
  298.      * @return smsAPI_SOAP_Response 
  299.      */
  300.     public function add_number($number$name$group_id)
  301.     {
  302.         if!preg_match('/^[0-9]{9,11}$/'$number) )
  303.             throw new smsAPI_Exception('Invalid function argument'-18);
  304.         if!isset($nameOR empty($name) )
  305.             throw new smsAPI_Exception('Invalid function argument'-18);
  306.         if!($group_id 0) )
  307.             throw new smsAPI_Exception('Invalid function argument'-18);
  308.  
  309.         $request array(
  310.             'client'    => $this->client,
  311.             'number'    => (string)$number,
  312.             'name'        => (string)$name,
  313.             'group_id'    => (int)$group_id
  314.         );
  315.         $response $this->___soapCall('add_number'$request);
  316.  
  317.         return $response;
  318.     }
  319.  
  320.     /**
  321.      * Pobieranie numer'ow z ksiazki telefonicznej uzytkownika
  322.      *
  323.      * @throws SoapFault
  324.      * @param int $group_id    ID grupy w ksiazce telefonicznej
  325.      * @return smsAPI_SOAP_Response_GetNumbers 
  326.      */
  327.     public function get_numbers($group_id)
  328.     {
  329.         if!($group_id 0) )
  330.             throw new smsAPI_Exception('Invalid function argument'-18);
  331.  
  332.         $request array(
  333.             'client'    => $this->client,
  334.             'group_id'    => (int)$group_id
  335.         );
  336.         $response $this->___soapCall('get_numbers'$request);
  337.         
  338.         if!isset($response->numbers) ) $response->numbers array();
  339.  
  340.         return $response;
  341.     }
  342.  
  343.     /**
  344.      * Usuwanie numeru z ksiazki telefonicznej
  345.      *
  346.      * @throws SoapFault
  347.      * @param string $number    Numer telefonu
  348.      * @param int $group_id        ID grupy w ksiazce telefonicznej
  349.      * @return smsAPI_SOAP_Response 
  350.      */
  351.     public function delete_number($number$group_id)
  352.     {
  353.         if!preg_match('/^[0-9]{9,11}$/'$number) )
  354.             throw new smsAPI_Exception('Invalid function argument'-18);
  355.         if!($group_id 0) )
  356.             throw new smsAPI_Exception('Invalid function argument'-18);
  357.  
  358.         $request array(
  359.             'client'    => $this->client,
  360.             'number'    => (string)$number,
  361.             'group_id'    => (int)$group_id
  362.         );
  363.         $response $this->___soapCall('delete_number'$request);
  364.  
  365.         return $response;
  366.     }
  367.  
  368.     /**
  369.      * Sprawdzanie ilosci punktow na koncie.
  370.      *
  371.      * @throws SoapFault
  372.      * @return smsAPI_SOAP_Response_GetPoints 
  373.      */
  374.     public function get_points()
  375.     {
  376.         $response $this->___soapCall('get_points'$this->client );
  377.  
  378.         return $response;
  379.     }
  380.  
  381.     /**
  382.      * Pobieranie dostepnych pol nadawcy
  383.      *
  384.      * @throws SoapFault
  385.      * @return smsAPI_SOAP_Response_GetSenders 
  386.      */
  387.     public function get_senders()
  388.     {
  389.         $response $this->___soapCall('get_senders'$this->client);
  390.  
  391.         return $response;
  392.     }
  393.  
  394.     /**
  395.      * Wywolanie funkcji SOAP
  396.      *
  397.      * @throws SoapFault
  398.      * @param string $function 
  399.      * @param array $request 
  400.      * @return mixed 
  401.      */
  402.     protected function ___soapCall($function$request array())
  403.     {
  404.         smsAPI::call_listners(__CLASS__.' '.$function.' request'$request);
  405.  
  406.         $response $this->h_sopa->$function$request );
  407.  
  408.         smsAPI::call_listners(__CLASS__.' '.$function.' response'$response);
  409.  
  410.         return $response;
  411.     }
  412.  
  413.     /**
  414.      * Pobierz uchwyt do SoapClient
  415.      *
  416.      * @return SoapClient 
  417.      */
  418.     public function __getSoapClient()
  419.     {
  420.         return $this->h_sopa;
  421.     }
  422. }

Documentation generated on Thu, 27 Jan 2011 16:17:36 +0100 by phpDocumentor 1.4.3