当前位置: 首页>>代码示例>>PHP>>正文


PHP Curl::setCookie方法代码示例

本文整理汇总了PHP中Curl\Curl::setCookie方法的典型用法代码示例。如果您正苦于以下问题:PHP Curl::setCookie方法的具体用法?PHP Curl::setCookie怎么用?PHP Curl::setCookie使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Curl\Curl的用法示例。


在下文中一共展示了Curl::setCookie方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: login

 /**
  * @author mohuishou<1@lailin.xyz>
  * @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;
 }
开发者ID:mohuishou,项目名称:scuplus-jwc-package,代码行数:33,代码来源:JwcBase.php

示例2: getSim

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;
    }
}
开发者ID:kukua,项目名称:kukua-dashboard,代码行数:29,代码来源:cronjob_sim_availability.php

示例3: request

 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;
     }
 }
开发者ID:nanodesu88,项目名称:amocrm,代码行数:22,代码来源:AmoCrm.php

示例4: Curl

<?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;
开发者ID:fifths,项目名称:php_curl,代码行数:11,代码来源:post.php

示例5: testCookieEncoding

 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]);
 }
开发者ID:aguillem,项目名称:festival-manager,代码行数:10,代码来源:PHPCurlClassTest.php

示例6: testCookieEncodingColon

 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]);
 }
开发者ID:ice-wolf,项目名称:polyglotcode,代码行数:10,代码来源:PHPCurlClassTest.php

示例7: getSim

 /**
  * 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";
//.........这里部分代码省略.........
开发者ID:kukua,项目名称:kukua-dashboard,代码行数:101,代码来源:Eseye.php

示例8: execute

 /**
  *
  * 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);
 }
开发者ID:superkresek,项目名称:custom-instagram-sdk,代码行数:40,代码来源:Request.php

示例9: Curl

<?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');
开发者ID:madnh,项目名称:php-curl-class,代码行数:8,代码来源:set_cookie.php

示例10: authenticateWithSessionCookie

 /**
  * 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;
 }
开发者ID:raphy,项目名称:epitech-intranet,代码行数:22,代码来源:Intranet.php

示例11: execute

 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);
 }
开发者ID:rodrigopa,项目名称:instagram-sdk-php,代码行数:25,代码来源:Request.php

示例12: getGrade

 /**
  * 获取成绩
  * @author mohuishou<1@lailin.xyz>
  * @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;
     }
 }
开发者ID:mohuishou,项目名称:swugpa,代码行数:85,代码来源:Swugpa.php


注:本文中的Curl\Curl::setCookie方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。