Skip to content
This repository was archived by the owner on Mar 16, 2025. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions Api.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
use Zelenin\SmsRu\Entity\StoplistPhone;
use Zelenin\SmsRu\Exception\Exception;
use Zelenin\SmsRu\Response\AuthCheckResponse;
use Zelenin\SmsRu\Response\CallCodeResponse;
use Zelenin\SmsRu\Response\MyBalanceResponse;
use Zelenin\SmsRu\Response\MyLimitResponse;
use Zelenin\SmsRu\Response\MySendersResponse;
Expand Down Expand Up @@ -263,6 +264,21 @@ public function stoplistGet()
return $stoplistGetResponse;
}

public function codeCall($phone)
{
$params = array_merge(['phone' => $phone], $this->getAuth()->getAuthParams());
$response = $this->client->request('code/call', $params);

$json = json_decode($response, true);

if (is_array($json) == false) {
$response = explode("\n", $response);
return new CallCodeResponse(array_shift($response));
}

return CallCodeResponse::makeByJson($json);
}

/**
* @param string $method
* @param array $params
Expand Down
50 changes: 50 additions & 0 deletions Response/CallCodeResponse.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
<?php

namespace Zelenin\SmsRu\Response;

class CallCodeResponse extends AbstractResponse
{
/** @var int|null */
public $checkCode;

/** @var float|null */
public $balance;

/** @var float|null */
public $cost;

/** @var string|null */
public $callId;

protected $availableDescriptions = [
'100' => 'Запрос выполнен.',
'200' => 'Неправильный api_id.',
'210' => 'Используется GET, где необходимо использовать POST.',
'211' => 'Метод не найден.',
'220' => 'Сервис временно недоступен, попробуйте чуть позже.',
'300' => 'Неправильный token (возможно истек срок действия, либо ваш IP изменился).',
'301' => 'Неправильный пароль, либо пользователь не найден.',
'302' => 'Пользователь авторизован, но аккаунт не подтвержден (пользователь не ввел код, присланный в регистрационной смс).',
];

public static function makeByJson(array $json)
{
if ($json['status'] == 'ERROR') {
$code = '400';

$response = new CallCodeResponse($code);
$response->availableDescriptions[$code] = $json['status_text'];

return $response;
}

$response = new CallCodeResponse('100');

$response->checkCode = $json['code'];
$response->balance = $json['balance'];
$response->cost = $json['cost'];
$response->callId = $json['call_id'];

return $response;
}
}
1 change: 1 addition & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
},
"require": {
"php": ">=5.5.0",
"ext-json": "*",
"guzzlehttp/guzzle": "~6 || ~7"
},
"autoload": {
Expand Down
7 changes: 7 additions & 0 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,13 @@ $client->stoplistDel($phone);
$client->stoplistGet();
```

Отправить четырехзначный авторизационный код звонком:

```php
$response = $client->codeCall($phone);
echo $response->checkCode;
```

## Автор

[Александр Зеленин](https://github.com/zelenin/), e-mail: [aleksandr@zelenin.me](mailto:aleksandr@zelenin.me)