Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- /**
- * Class ExternalService
- */
- class ExternalService
- {
- public $request;
- public $method;
- public $url;
- public $response;
- public function __construct($url)
- {
- $this->url = $url;
- }
- /**
- * Получение ответа от внешнего сервиса
- */
- public function getResponse($method, $request = null)
- {
- 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