Source for file httpclient.php
Documentation is available at httpclient.php
* Copyright (c) 2010, ComVision
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
* - Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
* - Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation and/or
* other materials provided with the distribution.
* - Neither the name of the smsAPI.pl nor the names of its contributors may be used to
* endorse or promote products derived from this software without specific prior written permission.
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
* IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
* @author ComVision <info@smsapi.pl>
* @copyright 2010 ComVision
* @subpackage client\html
* @version 1.0 14.10.2010
* Client smsAPI przez HTTP/HTTPS
* require_once 'smsapi.php';
* //Instrukcja odpowiedziala za automatyczne wczytywanie class
* spl_autoload_register(array('smsAPI','__autoload'));
* $smsapi = new smsAPI_HTTPClient('login', md5('password'));
* $msg = $smsapi->new_sms();
* $msg->add_to( 'xxxxxxxxx' );
* $msg->message = 'test';
* $result = $msg->send();
* $smsapi->delete_sms( $result[0]->id );
* catch ( smsAPI_Exception $e )
* @see http://www.smsapi.pl/spec/smsAPI.pdf
* Sposob przesylania danych
* @see smsAPI_HTTPClient::METHOD_GET
* @see smsAPI_HTTPClient::METHOD_POST
* Przesylania danych metodą GET do smsAPI
* Przesylania danych metodą POST do smsAPI
public static $errors =
array(
11 =>
'Zbyt długa lub brak wiadomości',
12 =>
'Wiadomość zawiera ponad 160 znaków (gdy użyty parametr &single=1)',
13 =>
'Nieprawidłowy numer odbiorcy',
14 =>
'Nieprawidłowe pole nadawcy',
17 =>
'Nie można wysłać FLASH ze znakami specjalnymi',
18 =>
'Nieprawidłowa liczba parametrów',
19 =>
'Za dużo wiadomości w jednym odwołaniu (maksymalnie 100)',
20 =>
'Nieprawidłowa liczba parametrów IDX',
21 =>
'Wiadomość MMS ma za duży rozmiar (maksymalnie 100kB)',
22 =>
'Błędny format SMIL',
101 =>
'Niepoprawne lub brak danych autoryzacji',
102 =>
'Nieprawidłowy login lub hasło',
103 =>
'Brak punków dla tego użytkownika',
105 =>
'Błędny adres IP (włączony filtr IP dla interfejsu API)',
200 =>
'Nieudana próba wysłania wiadomości',
300 =>
'Nieprawidłowa wartość pola points (przy użyciu pola points jest wymagana wartość 1)',
301 =>
'ID wiadomości nie istnieje',
400 =>
'Nieprawidłowy ID statusu wiadomości',
999 =>
'Wewnętrzny błąd systemu (prosimy zgłosić)'
* $smsapi = new smsAPI_HTTPClient('login', md5('password'));
* catch ( smsAPI_Exception $e )
* @uses smsAPI_HTTPClient::METHOD_GET
* @uses smsAPI_HTTPClient::METHOD_POST
* @param string $username Nazwa użytkownika w serwisie smsAPI
* @param string $password Hasło do Twojego konta w serwisie smsAPI zaszyfrowane w MD5
* @param int $timeout Timeout polączenia
* @param bool $ssl http lub https
* @param int $method Sposób przesyania danych do smsAPI
public function __construct($username, $password, $timeout =
0,$ssl =
true, $method =
self::METHOD_POST)
$this->url =
$ssl ==
TRUE ?
'https://ssl.smsapi.pl/send.do' :
'http://api.smsapi.pl/send.do';
if( !isset
( $username ) OR empty ( $username ) )
if( !isset
( $password ) OR strlen( $password ) !=
32 )
$this->timeout = (int)
$timeout;
* $smsapi = new smsAPI_HTTPClient('login', md5('password'));
* $msg = $smsapi->new_sms();
* $msg->add_to( 'xxxxxxxxx', 'xxxxxxxxx' );
* $msg->message = 'test message';
* $result = $msg->send();
* // public 'id' => string '1010131304559538088' (length=19)
* // public 'points' => string '0.07' (length=1)
* catch ( smsAPI_Exception $e )
* @return smsAPI_HTTP_SMS
public function new_sms($params =
null)
* Wysyłanie pojedynczego SMS'a
* $msg = new smsAPI_HTTP_SMS();
* $msg->add_to( 'xxxxxxxxx', 'xxxxxxxxx' );
* $msg->message = 'test message';
* $smsapi = new smsAPI_HTTPClient('login', md5('password'));
* $result = $smsapi->send_sms($msg);
* // public 'id' => string '1010131304559538088' (length=19)
* // public 'points' => string '0.07' (length=1)
* catch ( smsAPI_Exception $e )
* @throws smsAPI_Exception
* @param smsAPI_HTTP_SMS $sms
* @return stdClass(id,points)
foreach ( $response as $r )
if( empty ($r) ) continue;
$tmp = (object)
array( 'id' =>
$r[1], 'points' =>
$r[2] );
$tmp = (object)
array( 'error' => (int)
@$r[1] );
if( isset
( $r[3] ) ) $tmp->phone =
$r[3];
* Usuwanie zaplanowanej wiadomości
* $smsapi = new smsAPI_HTTPClient('login', md5('password'), true);
* $smsapi->delete_sms('1010131304559538088');
* catch ( smsAPI_Exception $e )
* @throws smsAPI_Exception
* @param string $id ID wiadomości w systemie smsAPI
$result =
$this->server_call( array( 'sch_del' => (string)
$id ) );
$result =
explode(':', $result[0]);
$msg = isset
( $code ) ?
self::$errors[$code] :
self::$errors[0];
throw
new smsAPI_Exception($msg, $code );
* Sprawdzenie ilości punktów na koncie
* $smsapi = new smsAPI_HTTPClient('login', md5('password'), true);
* $result = $smsapi->get_points(true);
* catch ( smsAPI_Exception $e )
* @return stdClass(points,pro,eco)
'details' => (bool)
$details
$response[0] =
explode(':', $response[0]);
$result->error =
trim(@$response[0][1]);
$result->points =
trim(@$response[0][1]);
$count =
count($response);
if( $count >=
2 ) $result->pro =
trim(@$response[1]);
if( $count >=
3 ) $result->eco =
trim(@$response[2]);
public static $call =
self::CALL_AUTO;
if( in_array(self::$call, array( self::CALL_CURL, self::CALL_FOPEN )) ) return self::$call;
if( ini_get('allow_url_fopen') ==
1 ) return self::CALL_FOPEN;
throw
new smsAPI_Exception('allow_url_fopen is disabled and curl_init doesn\'t exists');
* Wywolanie zapytania do strony smsAPI.pl
* @uses smsAPI_HTTPClient::METHOD_GET
* @uses smsAPI_HTTPClient::METHOD_POST
* @throws smsAPI_Exception
'method' =>
($this->method ==
self::METHOD_POST ?
'POST' :
'GET'),
'user_agent' =>
'SMSApi_HTTP_Client'
$opts['http']['method'] =
'GET';
$opts['http']['method'] =
'POST';
$opts['http']['header'] =
'Content-type: application/x-www-form-urlencoded';
$opts['http']['content'] =
$data;
$opts['http']['timeout'] =
$this->timeout;
smsAPI::call_listners('server_call args', array( 'opts' =>
$opts, 'url' =>
$url ));
if( $this->method ==
self::METHOD_GET )
@curl_setopt($ch, CURLOPT_POSTFIELDS, $opts['http']['content']);
if( isset
( $opts['http']['timeout'] ) )
@curl_setopt($ch, CURLOPT_TIMEOUT, $opts['http']['timeout']);
throw
new smsAPI_Exception('allow_url_fopen is disabled and curl_init doesn\'t exists');
smsAPI::call_listners('server_call result', array( 'result' =>
$result ));
if( $result ===
false OR empty($result) )
$result =
trim($result, " ;\n\t\r");
Documentation generated on Thu, 27 Jan 2011 16:17:32 +0100 by phpDocumentor 1.4.3