Skip to content

Commit

Permalink
small fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
zelenin committed Apr 20, 2014
1 parent 87ba1a0 commit a6dc779
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 70 deletions.
8 changes: 0 additions & 8 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,9 +1 @@
.idea
.git
index.php
cookie.txt
curl.cookie.txt
vendor
composer.lock
composer.phar
post.txt
4 changes: 2 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
{
"name": "zelenin/smsru",
"description": "PHP-класс для работы с api сервиса [sms.ru](http://sms.ru)",
"version": "1.4.2",
"version": "1.4.3",
"type": "library",
"keywords": ["sms", "sms.ru", "api"],
"homepage": "https://github.com/zelenin/sms_ru",
"time": "2014-01-10",
"time": "2014-04-20",
"license": "MIT",
"authors": [
{
Expand Down
6 changes: 1 addition & 5 deletions example.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php

require_once 'vendor/autoload.php';
require_once 'src/smsru.php';

$sms = new \Zelenin\smsru('api_id', 'login', 'password');
// $sms = new \Zelenin\smsru( 'api_id' );
Expand Down Expand Up @@ -39,7 +39,3 @@
// $result = $sms->stoplist_get();

// $result = $sms->stoplist_del( '79112223344' );

echo '<pre>';

print_r($result);
92 changes: 37 additions & 55 deletions src/smsru.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,14 @@
* @author Aleksandr Zelenin <aleksandr@zelenin.me>
* @link https://github.com/zelenin/sms_ru
* @license MIT
* @version 1.4.2
* @version 1.4.3
*/

namespace Zelenin;

class smsru
{
const VERSION = '1.4.2';
const VERSION = '1.4.3';
const HOST = 'http://sms.ru/';
const SEND = 'sms/send?';
const STATUS = 'sms/status?';
Expand All @@ -27,13 +27,13 @@ class smsru
const DEL = 'stoplist/del?';
const GET = 'stoplist/get?';
const UCS = 'sms/ucs?';
private $_api_id;
private $_login;
private $_password;
private $_params;
private $_token;
private $_sha512;
protected $response_code = array(
private $apiId;
private $login;
private $password;
private $params;
private $token;
private $sha512;
private $response_code = array(
'send' => array(
'100' => 'Сообщение принято к отправке. На следующих строчках вы найдете идентификаторы отправленных сообщений в том же порядке, в котором вы указали номера, на которых совершалась отправка.',
'200' => 'Неправильный api_id',
Expand Down Expand Up @@ -131,41 +131,25 @@ class smsru
'get' => array(
'100' => 'Запрос обработан. На последующих строчках будут идти номера телефонов, указанных в стоплисте в формате номер;примечание.'
)

);

public function __construct($api_id = null, $login = null, $pwd = null)
{
$this->_api_id = $api_id;
$this->_login = $login;
$this->_password = $pwd;
$this->apiId = $api_id;
$this->login = $login;
$this->password = $pwd;

$this->_params = $this->getAuthParams();
$this->params = $this->getAuthParams();
}

public function sms_send(
$to,
$text,
$from = null,
$time = null,
$translit = false,
$test = false,
$partner_id = null
) {
public function sms_send($to, $text, $from = null, $time = null, $translit = false, $test = false, $partner_id = null) {
$messages = array(array($to, $text));
return $this->multi_sms_send($messages, $from, $time, $translit, $test, $partner_id);
}

public function multi_sms_send(
$messages,
$from = null,
$time = null,
$translit = false,
$test = false,
$partner_id = null
) {
public function multi_sms_send($messages, $from = null, $time = null, $translit = false, $test = false, $partner_id = null) {
$url = self::HOST . self::SEND;
$params = $this->_params;
$params = $this->params;

foreach ($messages as $message) {
$params['multi'][$message[0]] = $message[1];
Expand All @@ -191,7 +175,7 @@ public function multi_sms_send(
$params['partner_id'] = $partner_id;
}

$result = $this->curl($url, http_build_query($params));
$result = $this->curl($url, http_build_query($params, '', '&'));
$result = explode("\n", $result);

$response = array();
Expand All @@ -213,7 +197,7 @@ public function multi_sms_send(

public function sms_mail($to, $text, $from = null)
{
$mail = $this->_api_id . '@' . self::HOST;
$mail = $this->apiId . '@' . self::HOST;
$subject = isset($from) ? $to . ' from:' . $from : $to;
$headers = 'Content-Type: text/html; charset=UTF-8';
return mail($mail, $subject, $text, $headers);
Expand All @@ -222,7 +206,7 @@ public function sms_mail($to, $text, $from = null)
public function sms_status($id)
{
$url = self::HOST . self::STATUS;
$params = $this->_params;
$params = $this->params;
$params['id'] = $id;
$result = $this->curl($url, $params);

Expand All @@ -235,7 +219,7 @@ public function sms_status($id)
public function sms_cost($to, $text)
{
$url = self::HOST . self::COST;
$params = $this->_params;
$params = $this->params;
$params['to'] = $to;
$params['text'] = $text;

Expand All @@ -253,7 +237,7 @@ public function sms_cost($to, $text)
public function my_balance()
{
$url = self::HOST . self::BALANCE;
$params = $this->_params;
$params = $this->params;
$result = $this->curl($url, $params);
$result = explode("\n", $result);
return array(
Expand All @@ -266,7 +250,7 @@ public function my_balance()
public function my_limit()
{
$url = self::HOST . self::LIMIT;
$params = $this->_params;
$params = $this->params;
$result = $this->curl($url, $params);
$result = explode("\n", $result);
return array(
Expand All @@ -280,7 +264,7 @@ public function my_limit()
public function my_senders()
{
$url = self::HOST . self::SENDERS;
$params = $this->_params;
$params = $this->params;
$result = $this->curl($url, $params);
$result = explode("\n", rtrim($result));

Expand All @@ -297,7 +281,7 @@ public function my_senders()
public function auth_check()
{
$url = self::HOST . self::CHECK;
$params = $this->_params;
$params = $this->params;
$result = $this->curl($url, $params);

$response = array();
Expand All @@ -309,7 +293,7 @@ public function auth_check()
public function stoplist_add($stoplist_phone, $stoplist_text)
{
$url = self::HOST . self::ADD;
$params = $this->_params;
$params = $this->params;
$params['stoplist_phone'] = $stoplist_phone;
$params['stoplist_text'] = $stoplist_text;
$result = $this->curl($url, $params);
Expand All @@ -323,7 +307,7 @@ public function stoplist_add($stoplist_phone, $stoplist_text)
public function stoplist_del($stoplist_phone)
{
$url = self::HOST . self::DEL;
$params = $this->_params;
$params = $this->params;
$params['stoplist_phone'] = $stoplist_phone;
$result = $this->curl($url, $params);

Expand All @@ -336,7 +320,7 @@ public function stoplist_del($stoplist_phone)
public function stoplist_get()
{
$url = self::HOST . self::GET;
$params = $this->_params;
$params = $this->params;
$result = $this->curl($url, $params);

$result = explode("\n", rtrim($result));
Expand All @@ -358,22 +342,22 @@ public function stoplist_get()
public function sms_ucs()
{
$url = self::HOST . self::UCS;
$params = $this->_params;
$params = $this->params;
$result = $this->curl($url, $params);
return $result;
}

private function getAuthParams()
{
if (!empty($this->login) && !empty($this->pwd)) {
$this->_token = $this->authGetToken();
$this->_sha512 = $this->getSha512();
$this->token = $this->authGetToken();
$this->sha512 = $this->getSha512();

$params['login'] = $this->_login;
$params['token'] = $this->_token;
$params['sha512'] = $this->_sha512;
$params['login'] = $this->login;
$params['token'] = $this->token;
$params['sha512'] = $this->sha512;
} else {
$params['api_id'] = $this->_api_id;
$params['api_id'] = $this->apiId;
}
return $params;
}
Expand All @@ -386,11 +370,9 @@ private function authGetToken()

private function getSha512()
{
if (!$this->_api_id || empty($this->_api_id)) {
return hash('sha512', $this->_password . $this->_token);
} else {
return hash('sha512', $this->_password . $this->_token . $this->_api_id);
}
return !$this->apiId || empty($this->apiId)
? hash('sha512', $this->password . $this->token)
: hash('sha512', $this->password . $this->token . $this->apiId);
}

private function getAnswer($key, $code)
Expand Down

0 comments on commit a6dc779

Please sign in to comment.