Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- /**
- * Class ESService
- */
- class ESService
- {
- public $request;
- public $method;
- public $url;
- public $response;
- public function __construct()
- {
- $this->url = $this->getUrl();
- }
- // Получить url внешнего сервиса
- public function getUrl()
- {
- $url = Yii::app()->params['service'] . '/webresources/uin/generate';
- return $url;
- }
- // Возвращает тип запроса
- public function getRequestType()
- {
- $this->method = Yii::app()->request->getRequestType();
- return $this->method;
- }
- //Возвращает тело запроса
- public function getRawBody()
- {
- $this->request = Yii::app()->request->getRawBody();
- return $this->request;
- }
- //Получение ответа от внешнего сервиса
- public function getResponse($method, $request)
- {
- switch ($method) {
- case 'GET':
- $response = Yii::app()->httpClient->get($this->url,
- array('content-type' => 'application/json'))->getBody();
- break;
- case 'POST':
- $response = Yii::app()->httpClient->post($this->url,
- array('content-type' => 'application/json'), $request)->getBody();
- break;
- }
- return $response;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement