SMS.ruを便利に送信します

ハブで滑ったことがありました-sms.ruサービスについて

私はそれを試しました、それは動作します。 気に入った。 その後、これで問題は終わりました。

しかし最近、SMSをサブスクライブされたクライアントに送信する必要がありました。 サービスサイトのAPIは十分に文書化されており、例も提供されていますが、使いやすさが不足しています。 その結果、sms.ruとやり取りするための小さなクラスを作成しました。







<?php



/**

* sms.ru

*/

class Z_Service_Sms {



protected $_apiId = NULL;

protected $_responseCode = NULL;

protected $_lastAction = NULL;



const HOST = 'http://sms.ru/' ;

const SEND = 'sms/send?' ;

const STATUS = 'sms/status?' ;

const BALANCE = 'my/balance?' ;

const LIMIT = 'my/limit?' ;



protected $_responseCodeTranstale = array(

'send' => array(

'100' => ' ' ,

'200' => ' api_id' ,

'201' => ' ' ,

'202' => ' ' ,

'203' => ' ' ,

'204' => ' ' ,

'205' => ' ( 5 )' ,

'206' => ' ' ,

'207' => ' ' ,

'208' => ' time ' ,

'210' => ' GET, POST' ,

'211' => ' ' ,

'220' => ' , .' ,

),

'status' => array(

'-1' => ' ' ,

'100' => ' ' ,

'101' => ' ' ,

'102' => ' ( )' ,

'103' => ' ' ,

'104' => ' : ' ,

'105' => ' : ' ,

'106' => ' : ' ,

'107' => ' : ' ,

'108' => ' : ' ,

'200' => ' api_id' ,

'210' => ' GET, POST' ,

'211' => ' ' ,

'220' => ' , ' ,

),

'balance' => array(

'100' => ' ' ,

'200' => ' api_id' ,

'210' => ' GET, POST' ,

'211' => ' ' ,

'220' => ' , .' ,

),

'limit' => array(

'100' => ' ' ,

'200' => ' api_id' ,

'210' => ' GET, POST' ,

'211' => ' ' ,

'220' => ' , .' ,

),

);



/**

*

* api_id

* @param string $id

*/

public function __construct($id)

{

$ this ->_apiId = $id;

}



/**

*

* @param string $to : 11 . 79060000000

* @param string $text

* @param string $from

* @return string id

*/

public function send($to,$text,$ from =NULL)

{

$apiParams[ 'api_id' ] = $ this ->_apiId;

$apiParams[ 'to' ] = $to;

$apiParams[ 'text' ] = $text;

if ($ from )

$apiParams[ 'from' ] = $ from ;

$url = self::HOST.self::SEND.http_build_query($apiParams);;

$body = file_get_contents($url);

@list($code,$smsId) = explode( "\n" , $body);

$ this ->_lastAction = 'send' ;

$ this ->_responseCode = $code;

return $smsId;

}



/**

*

* @param string $id id

* @return string .

*/

public function status($id)

{

$apiParams[ 'api_id' ] = $ this ->_apiId;

$apiParams[ 'id' ] = $id;

$url = self::HOST.self::STATUS.http_build_query($apiParams);

$body = file_get_contents($url);

$status = $body;

$ this ->_lastAction = 'status' ;

$ this ->_responseCode = $status;

return $status;

}



/**

*

* @return string

*/

public function balance()

{

$apiParams[ 'api_id' ] = $ this ->_apiId;

$url = self::HOST.self::BALANCE.http_build_query($apiParams);

$body = file_get_contents($url);

@list($code,$balance) = explode( "\n" , $body);

$ this ->_lastAction = 'balance' ;

$ this ->_responseCode = $code;

return $balance;

}



/**

*

* @return int

*/

public function limit()

{

$apiParams[ 'api_id' ] = $ this ->_apiId;

$url = self::HOST.self::LIMIT.http_build_query($apiParams);

$body = file_get_contents($url);

@list($code,$count,$limit) = explode( "\n" , $body);

$ this ->_lastAction = 'limit' ;

$ this ->_responseCode = $code;

return ( int )($count - $limit);

}



/**

*

* @return string

*/

public function getResponseCode()

{

return $ this ->_responseCode;

}



/**

*

* @return string

*/

public function getResponseMessage()

{

if ($ this ->_lastAction)

return $ this ->_responseCodeTranstale[$ this ->_lastAction][$ this ->getResponseCode()];

else

return ' ' ;

}



}



* This source code was highlighted with Source Code Highlighter .








改善のためのヒントを使用してください。



All Articles