false, 'authorized' => false]; public $errorCurlRequest; /* / определяет ключ авторизации из заголовка / */ public function beforeAction($action) { //$this->checkAuth(); return parent::beforeAction($action); //Yii::$app->response->format = \yii\web\Response::FORMAT_JSON; // return parent::beforeAction($action); } public function checkAuth($key = '') { if( Yii::$app->params['api']['authAppKey'] == $key ) { $this->datas['authorized'] = true; } else { throw new \yii\web\HttpException(401); } } public function curlRequest($url, $arrayParams = [] ) { $arrayParams = $json_encode($arrayParams); $result = ''; //$url = $arrayParams['url'];//'http://localhost/api/web/locomotive/index'; $curl = curl_init(); curl_setopt($curl, CURLOPT_URL, $url); curl_setopt($curl, CURLOPT_HTTPHEADER, array("Content-Type: application/json","Accept: application/json","AppKey: " . Yii::$app->params['api']['appKey'])); curl_setopt($curl, CURLOPT_TIMEOUT, 20); curl_setopt($curl, CURLOPT_RETURNTRANSFER, true); curl_setopt($curl, CURLOPT_FOLLOWLOCATION, true); curl_setopt($curl, CURLOPT_POST, 1); curl_setopt($curl, CURLOPT_POSTFIELDS, $arrayParams); curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, false); curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false); $result = curl_exec($curl); if ( !$result ){ $this->errorCurlRequest = curl_getinfo($curl, CURLINFO_HEADER_OUT); return ''; } curl_close($curl); return $result; } /* * Возвращает время в милисекундах */ public function seconds() { return explode(' ', microtime())[1]; //$mt = explode(' ', microtime()); //((int)$mt[1]) * 1000 + ((int)round($mt[0] * 1000)); } } ?>