123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129 |
- <?php
- namespace app\models;
- use Yii;
- use yii\base\Model;
- use app\models\entity\Accounts;
- use app\models\Logs;
- use app\models\logger\LoggerFile;
- class MainModel extends Model
- {
- public $errors = [];
- public $message = [];
- protected $logger;
- protected $log;
-
- public function __construct() {
- $this->log = new LoggerFile();
- }
-
- /*
- * Делает пост запрос
- */
- public function curlRequest($url, $arrayParams = [] )
- {
- // var_dump($arrayParams);
- // var_dump($url);
- $arrayParams = json_encode($arrayParams);
- $result = '';
-
- $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_HTTPHEADER, array("Content-Type: application/json","Accept: application/json"));
- curl_setopt($curl, CURLOPT_USERPWD, "ПройдаковИА:Ip15351112");
- curl_setopt($curl, CURLOPT_TIMEOUT, 360);
- 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);
-
- //var_dump(curl_getinfo($curl, CURLINFO_RESPONSE_CODE));
-
- if ( !$result ){
- $this->errors['surlRequest'] = curl_getinfo($curl, CURLINFO_HEADER_OUT);
- return '';
- }
-
- curl_close($curl);
-
- return $result;
-
- }
-
- public function curlRequest2($params)
- {
- $urlWithParam = $params['url'] . '?user_id=' . $params['param'];
- $curl = curl_init();
- curl_setopt($curl, CURLOPT_URL, $urlWithParam);
- curl_setopt($curl, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
- curl_setopt($curl, CURLOPT_USERPWD, $params['login'] . ":" . $params['pass']);
- //curl_setopt($curl, CURLOPT_HTTPHEADER, array("Content-Type: application/json","Accept: application/json","AppKey:6a7bdbaa-6bc1-4159-a2f4-07a13c8907d1"));
- curl_setopt($curl, CURLOPT_HTTPHEADER, array("Content-Type: application/json","Accept: application/json","AppKey:33cd23bb-3b03-4638-afef-7104a13e9211"));
- 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_SSL_VERIFYHOST, false);
- curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
- $result = curl_exec($curl);
- curl_close($curl);
- return $result;
- }
-
- public function curlRequestUni( $params , $method = 'get'){
-
- $par = [];
- $curl = curl_init();
-
- foreach( $params['param'] as $key => $item) {
- $par[] = $key .'=' . $item ;
- }
- $parString = implode('&',$par);
- //var_dump(json_encode($params['param']));
- if ( 'post' == $method ){
-
- $parString = '';
- curl_setopt($curl, CURLOPT_POSTFIELDS, json_encode($params['param']));
- curl_setopt($curl, CURLOPT_POST, 1);
- }
- $urlWithParam = $params['url'].'?'. $parString ;
-
- curl_setopt($curl, CURLOPT_URL, $params['url']);
- //curl_setopt($curl, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
- //curl_setopt($curl, CURLOPT_USERPWD, $params['login'] . ":" . $params['pass']);
- //curl_setopt($curl, CURLOPT_HTTPHEADER, array("Content-Type: application/json","Accept: application/json", "AppKey: 6a7bdbaa-6bc1-4159-a2f4-07a13c8907d1"));
- curl_setopt($curl, CURLOPT_HTTPHEADER, array("Content-Type: application/json","Accept: application/json", "AppKey: 33cd23bb-3b03-4638-afef-7104a13e9211"));
- curl_setopt($curl, CURLOPT_TIMEOUT, 30);
- curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
- curl_setopt($curl, CURLOPT_FOLLOWLOCATION, true);
- curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, false);
- curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
- //echo '<pre>';
- $result = curl_exec($curl);
-
- //var_dump(curl_getinfo($curl));
- //echo '</pre>';
- //Logs::addlog(2,$urlWithParam );
- // Logs::addlog(2,$result);
- return $result;
- }
-
- /*
- * Возвращает время в милисекундах
- */
-
- public function milliseconds()
- {
- $mt = explode(' ', microtime());
- return ((int)$mt[1]) * 1000 + ((int)round($mt[0] * 1000));
- }
- }
|