-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
base method, send and status for one message voice
- Loading branch information
1 parent
57e340b
commit 7bd049e
Showing
3 changed files
with
136 additions
and
15 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,134 @@ | ||
<?php | ||
/** | ||
* Created by PhpStorm. | ||
* User: Ignatenkov Nikita | ||
* Site: http://IgnatenkovNikita.ru/ | ||
* Date: 20.03.2016 | ||
* Time: 22:47 | ||
*/ | ||
|
||
namespace ignatenkovnikita\digitaldirectivr; | ||
|
||
|
||
use yii\base\Component; | ||
use yii\helpers\ArrayHelper; | ||
use yii\httpclient\Client; | ||
use yii\httpclient\Response; | ||
|
||
|
||
class ClientVoice extends Component | ||
{ | ||
/** @var string $login */ | ||
public $login; | ||
/** @var string $pass */ | ||
public $pass; | ||
/** @var string $url */ | ||
public $url; | ||
/** @var Client $_client */ | ||
private $_client; | ||
|
||
/** | ||
* Return array errors for one is method | ||
* @return array | ||
*/ | ||
protected function errorsForStatusMessage() | ||
{ | ||
return [ | ||
1 => 'Внутренняя ошибка', | ||
100 => 'Не все поля (параметры) были указаны', | ||
200 => 'Неверный логин/пароль, либо пользователь не является «особенным» - необходим Статус «привилегированного пользователя»', | ||
300 => 'MID <= 0 (идентификатор указан некорректно)', | ||
400 => 'Сообщение с указанным ID не найдено или сообщение находится в обработке (т.е. состояние рассылки, в которую входят номера телефонов, имеет одно из состояний: «постановка в очередь», «подтверждена (ожидает начала)» или «завершается»)', | ||
2100 => 'Для пользователя не включен функционал голосовых рассылок' | ||
]; | ||
} | ||
|
||
public function init() | ||
{ | ||
$this->_client = new Client([ | ||
'baseUrl' => $this->url, | ||
'requestConfig' => [ | ||
'format' => Client::FORMAT_URLENCODED | ||
], | ||
'responseConfig' => [ | ||
'format' => Client::FORMAT_JSON | ||
], | ||
]); | ||
|
||
parent::init(); // TODO: Change the autogenerated stub | ||
} | ||
|
||
/** | ||
* Private method to send request for all methods | ||
* @param $url | ||
* @param $params | ||
* @param string $format | ||
* @return Response | ||
*/ | ||
private function _send($url, $params, $format = 'post') | ||
{ | ||
$data = ArrayHelper::merge([ | ||
'login' => $this->login, | ||
'pass' => $this->pass | ||
], $params); | ||
|
||
return $this->_client->createRequest()->setUrl($url)->setMethod($format)->setData($data)->send(); | ||
} | ||
|
||
public function sendMessage($params) | ||
{ | ||
/** @var Response $response */ | ||
$response = $this->_send('submit_acmessage', $params, 'post'); | ||
return $response->isOk ? $response->content : $this->getError('errorsForSendMessage', $response->content); | ||
} | ||
|
||
public function sendMessages() | ||
{ | ||
// todo implement | ||
} | ||
|
||
public function uploadVoiceFile() | ||
{ | ||
// todo implement | ||
} | ||
|
||
public function listVoiceFiles() | ||
{ | ||
// todo implement | ||
} | ||
|
||
public function deleteVoiceFile() | ||
{ | ||
// todo implement | ||
} | ||
|
||
public function listZoneTariff() | ||
{ | ||
// todo implement | ||
} | ||
|
||
public function statusOneMessage($mid) | ||
{ | ||
/** @var Response $response */ | ||
$response = $this->_send('status_acmessage', ['mid' => $mid], 'post'); | ||
return $response->isOk ? $response->content : $this->getError('errorsForStatusMessage', $response->content); | ||
} | ||
|
||
public function statusMessages() | ||
{ | ||
// todo implement | ||
} | ||
|
||
/** | ||
* Method return error text | ||
* @param $name string name array to find | ||
* @param $code integer code error | ||
* @return mixed | ||
*/ | ||
public function getError($name, $code) | ||
{ | ||
$errors = call_user_func('self::' . $name); | ||
return ArrayHelper::getValue($errors, $code); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters