setCookie() public method

Set Cookie
public setCookie ( $key, $value )
$key
$value
Esempio n. 1
0
 /**
  * @author mohuishou<*****@*****.**>
  * @return $this
  * @throws \Exception
  */
 protected function login()
 {
     //判断是否已经登录
     if (!empty($this->_login_cookie)) {
         return $this;
     }
     //设置header伪造来源以及ip
     $ip = rand(1, 233) . '.' . rand(1, 233) . '.' . rand(1, 233) . '.' . rand(1, 233);
     $this->_curl->setHeader("X-Forwarded-For", $ip);
     $this->_curl->setHeader("Referer", 'http://202.115.47.141/login.jsp');
     $param = ["zjh" => $this->_uid, "mm" => $this->_password];
     $this->_curl->post('http://202.115.47.141/loginAction.do', $param);
     if ($this->_curl->error) {
         throw new \Exception('Error: ' . $this->_curl->errorCode . ': ' . $this->_curl->errorMessage, 5001);
     }
     //判断是否登录成功
     $page = $this->_curl->response;
     $page = iconv('GBK', 'UTF-8//IGNORE', $page);
     $rule = ['err' => ['.errorTop', 'text']];
     $err = QueryList::Query($page, $rule)->data;
     if (!empty($err)) {
         throw new \Exception('Error:' . $err[0]['err'], 4011);
     }
     //登录成功之后设置cookie
     $this->_login_cookie = $this->_curl->getResponseCookie("JSESSIONID");
     $this->_curl->setCookie('JSESSIONID', $this->_login_cookie);
     return $this;
 }
function getSim($sim, $cookieName, $cookieValue)
{
    $url = "https://siam.eseye.com/Japi/Tigrillo";
    if (ENVIRONMENT === "development") {
        $url = "https://tigrillostaging.eseye.com/Japi/Tigrillo";
    }
    $curl = new Curl();
    $curl->setHeader("Content-type", "application/json");
    try {
        $curl->setCookie($cookieName, $cookieValue);
        $curl->post($url . "/getSIMLastActivity", ["ICCID" => $sim->ICCID]);
        $response = $curl->response;
        $sim->LastRadiusStop = $response->info->LastRadiusStop;
        $sim->LastRadiusBytes = $response->info->LastRadiusBytes;
        $difference = 96;
        if (!empty($sim->LastRadiusStop)) {
            $date = DateTime::createFromFormat("Y-m-d H:i:s", $sim->LastRadiusStop);
            $difference = $date->getTimestamp() / 3600;
        }
        if ($difference >= 48 && $difference < 96) {
            alert($sim, "medium");
        }
        if ($difference >= 96) {
            alert($sim, "high");
        }
    } catch (Exception $e) {
        throw $e;
    }
}
Esempio n. 3
0
 public function request($method, $requestName, $params)
 {
     if ($this->auth()) {
         foreach ($this->cookieContainer->getCookies() as $cookieName => $cookieValue) {
             $this->_curl->setCookie($cookieName, $cookieValue);
         }
         $url = 'https://' . $this->_subdomain . '.amocrm.ru/private/api/v2/json/' . $method;
         $result = $requestName == 'POST' ? $this->_curl->post($url, $params) : $this->_curl->get($url, $params);
         $code = $this->_curl->httpStatusCode;
         foreach ($this->_curl->getResponseCookies() as $cookieName => $cookieValue) {
             $this->cookieContainer->add($cookieName, $cookieValue);
         }
         if ($code != 200) {
             if ($code == 204) {
                 return [];
             }
             $this->lastError = $result;
             return false;
         }
         return $result;
     }
 }
Esempio n. 4
0
<?php

require __DIR__ . "/../vendor/autoload.php";
use Curl\Curl;
$curl = new Curl();
$url = 'http://localhost/php_curl/example/returnpost.php';
$data = array('b' => "post", 'a' => 2, 'c' => "中文测试");
$curl->setCookie('test1', '1');
$curl->setCookie('test2', '2');
$getData = $curl->post($url, $data);
echo $getData;
 public function testCookieEncoding()
 {
     $curl = new Curl();
     $curl->setCookie('cookie', 'Om nom nom nom');
     $reflectionClass = new ReflectionClass('\\Curl\\Curl');
     $reflectionProperty = $reflectionClass->getProperty('options');
     $reflectionProperty->setAccessible(true);
     $options = $reflectionProperty->getValue($curl);
     $this->assertEquals('cookie=Om%20nom%20nom%20nom', $options[CURLOPT_COOKIE]);
 }
Esempio n. 6
0
 public function testCookieEncodingColon()
 {
     $curl = new Curl();
     $curl->setCookie('JSESSIONID', '0000wd-PcsB3bZ-KzYGAqm_rKlm:17925chrl');
     $reflectionClass = new ReflectionClass('\\Curl\\Curl');
     $reflectionProperty = $reflectionClass->getProperty('options');
     $reflectionProperty->setAccessible(true);
     $options = $reflectionProperty->getValue($curl);
     $this->assertEquals('JSESSIONID=0000wd-PcsB3bZ-KzYGAqm_rKlm:17925chrl', $options[CURLOPT_COOKIE]);
 }
Esempio n. 7
0
 /**
  * Get single SIM card details
  *
  * @access public
  * @throws Exception
  * @return StdClass
  */
 public function getSim($station, $includeSimStatus = true)
 {
     $result = new StdClass();
     $result->LastRadiusStop = "-";
     $result->LastRadiusBytes = "";
     $statusBg = "";
     $statusText = "-";
     if ($includeSimStatus && $station->getSimId()) {
         $curl = new Curl();
         $curl->setHeader("Content-type", "application/json");
         $curl->post($this->_url . "/getCookieName");
         $cookieName = $curl->response;
         $cookieValue = $this->_login_eseye();
         try {
             $curl->setHeader("Content-type", "application/json");
             $curl->setCookie($cookieName, $cookieValue);
             $curl->post($this->_url . "/getSIMLastActivity", ["ICCID" => $station->getSimId()]);
             $response = $curl->response;
             if (isset($response->info)) {
                 $result = $response->info;
                 if (!isset($result->LastRadiusStop)) {
                     $result->LastRadiusStop = "0000-00-00 00:00:00";
                 }
                 if (!isset($result->LastRadiusBytes)) {
                     $result->LastRadiusBytes = "0";
                 }
                 $tsDate = (new DateTime())->createFromFormat("Y-m-d H:i:s", $result->LastRadiusStop, new DateTimeZone("UTC"));
                 $statusBg = $this->_getDifference($result->LastRadiusStop);
                 $statusText = $tsDate->format("Y-m-d H:i:s") . " | " . $result->LastRadiusBytes;
             }
         } catch (Exception $e) {
             throw $e;
         }
     }
     /* Battery voltage */
     $batteryBg = "";
     $batteryVoltage = (new Source())->getBatteryLevel($station->getDeviceId());
     switch ($batteryVoltage) {
         case $batteryVoltage >= 4000:
             $batteryBg = "green";
             break;
         case $batteryVoltage >= 3500 && $batteryVoltage < 4000:
             $batteryBg = "orange";
             break;
         default:
             $batteryBg = "red";
             break;
     }
     $timestamp = (new Source())->getLatestTimestamp($station->getDeviceId());
     $tsBg = $this->_getDifference($timestamp);
     /* Board temperature */
     $boardTemp = (new Source())->getExceedBoardTempDate($station->getDeviceId());
     $boardTempColor = "";
     if ($boardTemp >= 45) {
         $boardTempColor = "red";
     } elseif ($boardTemp < 45) {
         $boardTempColor = "green";
     } else {
         $boardTemp = "-";
     }
     $boardHumid = (new Source())->getMaxHumidity($station->getDeviceId());
     $boardHumidColor = "";
     if ($boardHumid >= 50) {
         $boardHumidColor = "green";
     } elseif ($boardHumid >= 30) {
         $boardHumidColor = "orange";
     } elseif ($boardHumid >= 1) {
         $boardHumidColor = "red";
     } else {
         $boardHumid = "-";
     }
     $lastOpened = (new Source())->getLastOpenedDate($station->getDeviceId());
     $lastOpenedColor = "";
     if ($lastOpened) {
         $lastOpenedColor = "red";
     } else {
         $lastOpened = "-";
     }
     $sigQual = (new Source())->getMinSigQual($station->getDeviceId());
     $sigQualColor = "";
     if ($sigQual >= 50) {
         $sigQualColor = "red";
     } elseif ($sigQual >= 1) {
         $sigQualColor = "green";
     } else {
         if (!is_numeric($sigQual)) {
             $sigQual = "-";
         }
     }
     $sigQualTime = (new Source())->getMaxSigQualMinTime($station->getDeviceId());
     $sigQualTimeColor = "";
     if ($sigQualTime >= "10") {
         $sigQualTimeColor = "red";
     } elseif ($sigQualTime >= 1) {
         $sigQualTimeColor = "green";
     } else {
         $sigQualTime = "-";
     }
     $result->name = $station->getName();
     $result->regionId = $station->getRegionId();
     $result->ICCID = $station->getSimId();
     $result->status = $statusText;
     $result->statusColor = $statusBg;
     $result->voltage = $batteryVoltage;
     $result->voltageColor = $batteryBg;
     $result->timestampColor = $tsBg;
     $result->timestamp = $timestamp;
     $result->boardTemp = $boardTemp;
     $result->boardTempColor = $boardTempColor;
     $result->boardHumid = $boardHumid;
     $result->boardHumidColor = $boardHumidColor;
     $result->lastOpened = $lastOpened;
     $result->lastOpenedColor = $lastOpenedColor;
     $result->sigQual = $sigQual;
     $result->sigQualColor = $sigQualColor;
     $result->sigQualTime = $sigQualTime;
     $result->sigQualTimeColor = $sigQualTimeColor;
     $result->link = $station->getLink();
     return $result;
 }
 /**
  *
  * Execute the Request
  *
  * @return Response The Response
  * @throws \Exception
  */
 public function execute()
 {
     $data = null;
     $curl = new Curl();
     $curl->setOpt(CURLOPT_SSL_VERIFYPEER, $this->verifyPeer);
     if ($this->proxy != null) {
         $curl->setOpt(CURLOPT_PROXY, $this->proxy);
     }
     if ($this->proxyCredentials != null) {
         $curl->setOpt(CURLOPT_PROXYUSERPWD, $this->proxyCredentials);
     }
     foreach ($this->getHeaders() as $key => $value) {
         $curl->setHeader($key, $value);
     }
     foreach ($this->getCookies() as $key => $value) {
         $curl->setCookie($key, $value);
     }
     $error_format = "Instagram Request failed: [%s] [%s] %s";
     switch ($this->getMethod()) {
         case self::GET:
             $data = $curl->get($this->getUrl(), $this->getParams());
             break;
         case self::POST:
             $data = $curl->post($this->getUrl(), $this->getParams());
             if ($curl->curlError) {
                 throw new InstagramException(sprintf($error_format, "POST", $this->getUrl(), $curl->errorMessage));
             }
             break;
         default:
             throw new InstagramException(sprintf($error_format, "UNKNOWN", $this->getUrl(), "Unsupported Request Method"));
     }
     return new Response($curl, $data);
 }
Esempio n. 9
0
<?php

require __DIR__ . '/vendor/autoload.php';
use Curl\Curl;
$curl = new Curl();
$curl->setCookie('foo', 'bar');
$curl->get('https://httpbin.org/cookies');
var_dump($curl->response->cookies->foo === 'bar');
Esempio n. 10
0
 /**
  * Authenticate the client with the PHPSESSID cookie
  *
  * @param string $sessionCookie The value of the cookie PHPSESSID provided by Epitech's Intranet
  * @return bool TRUE if authenticated, otherwise FALSE
  */
 public function authenticateWithSessionCookie($sessionCookie)
 {
     if ($this->isAuthenticated()) {
         return $this->isAuthenticated();
     }
     $curl = new Curl();
     $curl->setOpt(CURLOPT_FRESH_CONNECT, true);
     $curl->setOpt(CURLOPT_COOKIESESSION, true);
     $curl->setCookie("PHPSESSID", $sessionCookie);
     $curl->get("https://intra.epitech.eu/?format=json");
     $this->isAuthenticated = $curl->http_status_code == 200;
     if ($this->isAuthenticated) {
         $this->sessionCookie = $sessionCookie;
     }
     return $this->isAuthenticated;
 }
Esempio n. 11
0
 public function execute()
 {
     $curl = new Curl();
     $curl->setOpt(CURLOPT_SSL_VERIFYPEER, $this->verifyPeer);
     $curl->setOpt(CURLOPT_SSL_VERIFYHOST, $this->verifyPeer);
     $curl->setOpt(CURLOPT_FOLLOWLOCATION, true);
     foreach ($this->getHeaders() as $key => $value) {
         $curl->setHeader($key, $value);
     }
     foreach ($this->getCookies() as $key => $value) {
         $curl->setCookie($key, $value);
     }
     switch ($this->getMethod()) {
         case RequestConstants::GET:
             $data = $curl->get($this->getUrl());
             break;
         case RequestConstants::POST:
             $data = $curl->post($this->getUrl(), $this->getParams());
             break;
     }
     if ($curl->curlError) {
         throw new RequestException($curl->curlErrorMessage, $curl->curlErrorCode);
     }
     return new Response($curl, $data);
 }
Esempio n. 12
0
 /**
  * 获取成绩
  * @author mohuishou<*****@*****.**>
  * @param int $year 学年
  * @param int $term 学期代码
  * @param null|int $uid 用户学号|不填使用$this->_uid
  * @param null|array $jwc_cookie 教务处cookie|不填使用$this->_jwc_cookie
  * @return array
  */
 public function getGrade($year, $term, $uid = null, $jwc_cookie = null)
 {
     $uid || ($uid = $this->_uid);
     $jwc_cookie || ($jwc_cookie = $this->_jwc_cookie);
     $grade_param = ["doType" => "query", "sessionUserKey" => $uid, "xnm" => $year, "xqm" => $term, "queryModel.showCount" => 40, "queryModel.currentPage" => 1];
     $this->_curl->setHeader('X-Requested-With', 'XMLHttpRequest');
     foreach ($jwc_cookie as $k => $v) {
         $this->_curl->setCookie($k, $v);
     }
     $this->_curl->post($this->_url_grade, $grade_param);
     if ($this->_curl->error) {
         $error_msg = 'Error: ' . $this->_curl->errorCode . ': ' . $this->_curl->errorMessage;
         return $this->returnData($error_msg, 20004);
     } else {
         if (empty($this->_curl->response->items)) {
             return ['status' => 20005, 'msg' => '该学期暂时没有成绩'];
         }
         $re = $this->_curl->response->items;
         $data['name'] = $re[0]->xm;
         $data['time'] = $re[0]->xnmmc;
         $data['term'] = $re[0]->xqmmc;
         $data['nj'] = $re[0]->njdm_id;
         $data['sid'] = $re[0]->xh;
         $grade_data = [];
         $sum_grade = 0;
         $sum_require_grade = 0;
         $sum_gpa = 0;
         $sum_require_gpa = 0;
         $sum_xf = 0;
         $sum_require_xf = 0;
         foreach ($re as $k => $v) {
             $grade_data[$k]['class_name'] = $v->kcmc;
             $grade_data[$k]['grade'] = $v->cj;
             $grade_val = $this->gradeSwap($v->cj);
             //所有成绩换算为分数
             $grade_data[$k]['grade_val'] = $grade_val;
             $grade_data[$k]['gpa'] = $v->jd;
             $grade_data[$k]['credit'] = $v->xf;
             $sum_xf += $v->xf;
             //总分和总的绩点
             $sum_grade += $grade_val * $v->xf;
             $sum_gpa += $v->jd * $v->xf;
             if (isset($v->kcxzmc)) {
                 if (in_array($v->kcxzdm, ['01', '03', '04'])) {
                     $grade_data[$k]['type'] = 1;
                     //该门课程为必修
                     $grade_data[$k]['type_name'] = '必修';
                     //必修学分和绩点
                     $sum_require_grade += $grade_val * $v->xf;
                     $sum_require_gpa += $v->jd * $v->xf;
                     $sum_require_xf += $v->xf;
                 } else {
                     $grade_data[$k]['type'] = 2;
                     //该门课程为选修
                     $grade_data[$k]['type_name'] = '选修';
                 }
                 //                    $grade_data[$k]['type_name']=$v->kcxzmc;
             } else {
                 //必修学分和绩点
                 $sum_require_grade += $grade_val * $v->xf;
                 $sum_require_gpa += $v->jd * $v->xf;
                 $sum_require_xf += $v->xf;
                 $grade_data[$k]['type'] = 1;
                 //该门课程为必修
                 $grade_data[$k]['type_name'] = '必修';
             }
         }
         $data['avg']['all']['grade'] = round($sum_grade / $sum_xf, 2);
         $data['avg']['all']['gpa'] = round($sum_gpa / $sum_xf, 2);
         $data['avg']['require']['grade'] = round($sum_require_grade / $sum_require_xf, 2);
         $data['avg']['require']['gpa'] = round($sum_require_gpa / $sum_require_xf, 2);
         $data['grade'] = $grade_data;
         $data['status'] = 200;
         return $data;
     }
 }