跳转到登录地址,或者返回包含登录信息的JSON

@param string $url
@return \Wei\Response
189352
protected function redirectLogin($url)
    {
        if ($this->request->acceptJson()) {
            $url = $this->url->append($url, ['next' => $this->request->getReferer()]);

            return $this->response->json([
                'code' => -401,
                'message' => '您好,请登录',
                'redirect' => $url,
            ]);
        } else {
            $url = $this->url->append($url, ['next' => $this->request->getUrl()]);

            return $this->response->redirect($url);
        }
    }
351278
private function getUrl($url)
	{
		$ch = curl_init();
		curl_setopt($ch,CURLOPT_URL,$url);
		curl_setopt($ch,CURLOPT_RETURNTRANSFER,1);
		curl_setopt($ch,CURLOPT_HEADER,0);
		// curl_setopt($ch, CURLOPT_ENCODING, "");
		$output = curl_exec($ch);
		curl_close($ch);
	    return $output;
	}
1012090
private function getFile($url)
	{
		$ch = curl_init();
		curl_setopt($ch, CURLOPT_HEADER, false);
		curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
		curl_setopt($ch, CURLOPT_URL, $url);
		curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
		$result = curl_exec($ch);
		curl_close($ch);

		$response = json_decode($result, TRUE);
		if (is_array($response) && count($response) > 0 && (!isset($response['status']) || $response['status'] != '404')) {
			return $response;
		}
		
		return false;
	}
996828
public function wechatURL($url = '') {
        $weixin = array('system', 'wechat');
        $string = trim($_SERVER['REQUEST_URI'], "/");
        #判断是否是微信链接-内部跳转链接
        if (strstr($string, md5('wechat') . "_wechat")) {
            $weixin[] = 'userAuthorization';
            #获取自定义数据 4910_wechat/type/get/callback/-1?code=
            #为了获取URL地址中间4910_wechat到？之间的数据为自定义参数
            $wechat = md5('wechat') . "_wechat";
            $str    = strlen($wechat);
            $len    = strrpos($string, '?');
            $num    = $len - $str;
            $new    = trim(substr($string, $str, $num), '/');
            $weixin = array_merge($weixin, explode("/", $new));
            #格式化数据
            $pieces = explode("?", $string);
            parse_str($pieces[1], $array);
            foreach ($array as $key => $value) {
                $weixin[] = $key;
                $weixin[] = $value;
            }
            return $weixin;
        }
        #第三方-授权事件接收URL  md5("Wechat Third-party) . "_wechat"; //事件回调
        elseif (strstr($string, md5('Wechat Third-party callback') . "_wechat")) {
            #thirdPartiesMessages
            $weixin[] = 'thirdPartiesMessages';
            $pieces   = explode("?", $string);
            if (isset($pieces[1]) && !empty($pieces[1])) {
                parse_str($pieces[1], $array);
                foreach ($array as $key => $value) {
                    $weixin[] = $key;
                    $weixin[] = $value;
                }
            }
            return $weixin;
        }
        #第三方-授权事件回调地址
        elseif (strstr($string, md5('Wechat authorization callback') . "_wechat")) {
            $weixin[] = 'thirdAuthorizeCallback';
            $wechat   = md5('Wechat Third-party callback') . "_wechat";
            #获取中间跳转地址
            $str    = strlen($wechat);
            $len    = strrpos($string, '?');
            $num    = $len - $str;
            $new    = trim(substr($string, $str, $num), '/');
            $weixin = array_merge($weixin, explode("/", $new));
            #格式化数据
            $pieces = explode("?", $string);
            if (isset($pieces[1]) && !empty($pieces[1])) {
                parse_str($pieces[1], $array);
                foreach ($array as $key => $value) {
                    $weixin[] = $key;
                    $weixin[] = $value;
                }
            }
            return $weixin;
        }
        #第三方-消息与事件接收URL
        elseif (strstr($string, md5('Wechat callback') . "_wechat")) {
            $weixin[] = 'thirdCallback';
            $wechat   = md5('Wechat callback') . "_wechat";
            #获取中间跳转地址
            $str    = strlen($wechat);
            $len    = strrpos($string, '?');
            $num    = $len - $str;
            $new    = trim(substr($string, $str, $num), '/');
            $weixin = array_merge($weixin, explode("/", $new));
            #格式化数据
            $pieces = explode("?", $string);
            if (isset($pieces[1]) && !empty($pieces[1])) {
                parse_str($pieces[1], $array);
                foreach ($array as $key => $value) {
                    $weixin[] = $key;
                    $weixin[] = $value;
                }
            }
            return $weixin;
        } else {
            return $url;
        }

    }
1282291
public function get($url, $params = array())
    {
        $client = new \Guzzle\Http\Client($this->_url);
        $request = $client->get($url, array(), array(
            'query' => $params
        ));
        $request->getCurlOptions()->set(CURLOPT_SSLVERSION, 1); // CURL_SSLVERSION_TLSv1
        $response = $client->send($request);
        if ($response->isSuccessful()) {
            return $response->json();
        } else {
            throw new \Exception("云片短信服务器未有效的响应请求");
        }
    }
264538
protected static function parseUrl($url)
    {
        $url           = isset($url) ? $url : "//$_SERVER[HTTP_HOST]$_SERVER[REQUEST_URI]";
        $url           = parse_url($url);
        $url['browse'] = './';
        if (array_key_exists('browse', self::$requestMethod)
            && !empty(self::$requestMethod['browse'])
        ) {
            $url['browse'] = self::$requestMethod['browse'];
        }
        return $url;
    }
808047
public function request($url)
    {
        $curlOpts = array_replace($this->curlOpts, [CURLOPT_URL => $url]);

        $ch = curl_init();
        foreach ($curlOpts as $opt => $optVal) {
            curl_setopt($ch, $opt, $optVal);
        }

        $resp = curl_exec($ch);
        $info = (object) curl_getinfo($ch);
        curl_close($ch);

        //Check response
        $httpCode = (string) $info->http_code;
        if ($httpCode{0} != '2') {
            $msg = sprintf('HTTP Request Failed (code %s): %s', $info->http_code, $resp);
            throw new HttpException($resp, $msg, $httpCode);
        } elseif (strlen(trim($resp)) == 0) {
            throw new HttpException($resp, 'HTTP Response Empty');
        }

        return $resp;
    }
356880
protected function sendRequest($url)
    {
        $response = null;

        if ($this->curlEnabled) {
            $ch = curl_init($url);
            curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
            $response = curl_exec($ch);
            curl_close($ch);
        } else {
            $response = file_get_contents($url);
        }

        return $response;
    }
25025
public function load($url)
    {
        $masterRequest = $this->requestStack->getMasterRequest();
        $request = Request::create($url, 'GET', array(), $masterRequest->cookies->all(), array(), $masterRequest->server->all());
        if ($masterRequest->getSession()) {
            $request->setSession($masterRequest->getSession());
        }

        $response = $this->kernel->handle($request, HttpKernelInterface::SUB_REQUEST, false);

        return $response->getContent();
    }
247665
public function performRequest($url)
    {
        $client = $this->getClient();

        return $this->response = $client->get($url);
    }
473727
protected function parseUrl($url)
    {
        $depr = $this->rule->getConfig('app.pathinfo_depr');
        $bind = $this->rule->getRouter()->getBind();

        if (!empty($bind) && preg_match('/^[a-z]/is', $bind)) {
            $bind = str_replace('/', $depr, $bind);
            // 如果有模块/控制器绑定
            $url = $bind . ('.' != substr($bind, -1) ? $depr : '') . ltrim($url, $depr);
        }

        list($path, $var) = $this->rule->parseUrlPath($url);

        return $path;

//        // 解析模块
//        $module = array_shift($path);
//
//        if ($this->param['auto_search']) {
//            $controller = $this->autoFindController($module, $path);
//        } else {
//            // 解析控制器
//            $controller = !empty($path) ? array_shift($path) : null;
//        }
//
//        // 解析操作
//        $action = !empty($path) ? array_shift($path) : null;
//
//        // 解析额外参数
//        if ($path) {
//            if ($this->rule->getConfig('url_param_type')) {
//                $var += $path;
//            } else {
//                preg_replace_callback('/(\w+)\|([^\|]+)/', function ($match) use (&$var) {
//                    $var[$match[1]] = strip_tags($match[2]);
//                }, implode('|', $path));
//            }
//        }
//
//        $panDomain = Request::panDomain();
//
//        if ($panDomain && $key = array_search('*', $var)) {
//            // 泛域名赋值
//            $var[$key] = $panDomain;
//        }
//
//        // 设置当前请求的参数
//        Request::setRouteVars($var);
//
//        // 封装路由
//        $route = [$module, $controller, $action];
//
//        if ($this->hasDefinedRoute($route, $bind)) {
//            throw new HttpException(404, 'invalid request:' . str_replace('|', $depr, $url));
//        }
//
//        return $route;
    }
945198
private function doGetRequest($url)
    {
        $response = $this->client->request('GET', $url, [
            'headers' => [
                'Authorization' => 'JWT '.$this->token,
            ],
        ]);

        $data = false;

        if ($response->getStatusCode() == 200) {
            $data = json_decode($response->getBody(), true);
        }

        return $data;
    }
998133
protected function fetchURL($URL)
    {
        $cookieHeader = [];
        if ($this->cookie) {
            $cookieHeader[] = 'Cookie: ' . $this->cookie . ';';
        }

        $curl = curl_init();
        curl_setopt($curl, CURLOPT_URL, $URL);
        curl_setopt($curl, CURLOPT_HEADER, 1);
        curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
        curl_setopt($curl, CURLOPT_HTTPHEADER, $cookieHeader);

        $body = null;
        $result = curl_exec($curl);
        if ($result) {
            $parts = explode("\r\n\r\n", $result, 2);
            $headers = explode("\r\n", $parts[0]);
            if (!$this->cookie) {
                $setCookieString = 'Set-Cookie: ';
                foreach ($headers as $header) {
                    if (strpos($header, $setCookieString) === 0) {
                        $cookieString = substr($header, strlen($setCookieString));
                        $cookieStringParts = explode(';', $cookieString);
                        $this->cookie = $cookieStringParts[0];
                        break;
                    }
                }
            }

            $body = $parts[1];
        }

        return $body;
    }
260675
public function curl($url)
    {
        $ip = '127.0.0.1';
        $port = '9051';
        $auth = 'PASSWORD';
        $command = 'signal NEWNYM';

        $fp = fsockopen($ip, $port, $error_number, $err_string, 2);
        if (!$fp) {
            echo "ERROR: $error_number : $err_string";

            return false;
        } else {
            fwrite($fp, "AUTHENTICATE \"".$auth."\"\n");
            fread($fp, 512);
            fwrite($fp, $command."\n");
            fread($fp, 512);
        }

        fclose($fp);

        $ch = curl_init();

        curl_setopt($ch, CURLOPT_URL, $url);
        curl_setopt($ch, CURLOPT_PROXY, '127.0.0.1:9050');
        curl_setopt($ch, CURLOPT_PROXYTYPE, CURLPROXY_SOCKS5);
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
        curl_setopt($ch, CURLOPT_VERBOSE, 0);
        curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
        curl_setopt($ch, CURLOPT_USERAGENT, $this->getUserAgent());  // $this->getUserAgent(true) for random);
        curl_setopt($ch, CURLOPT_ENCODING , 'gzip');
        $response = curl_exec($ch);

        return [$response, $ch];
    }
117147
private function _curlHelper(&$url, &$json = null)
    {
        $headers = [
            'Accept: application/json',
            'Accept-Encoding: gzip, deflate',
            'Connection: keep-alive',
            'Authorization: Bearer ' . $this->_token
        ];

        /*
         * If this is a request that has a body then we need to
         * include the content type, which in our case always is JSON.
         */
        if (isset($json)) {
            array_push($headers, 'Content-Type: application/json');
            curl_setopt($this->_curlHandle, CURLOPT_POSTFIELDS, $json);
        }

        curl_setopt($this->_curlHandle, CURLOPT_URL, $url);
        curl_setopt($this->_curlHandle, CURLOPT_RETURNTRANSFER, true);
        curl_setopt($this->_curlHandle, CURLOPT_HTTPHEADER, $headers);
        curl_setopt($this->_curlHandle, CURLOPT_USERAGENT, $this->_userAgent);

        $result = curl_exec($this->_curlHandle);

        if ($result === false) {
            throw new HttpCallException(curl_error($this->_curlHandle));
        }

        $httpStatus = curl_getinfo($this->_curlHandle, CURLINFO_HTTP_CODE);

        // If we have a logger then we can emit a bit of debug info.
        if (isset($this->_logger)) {
            $httpTime = curl_getinfo($this->_curlHandle, CURLINFO_TOTAL_TIME);
            $this->_logger->debug(
                'Request: {req}; Response (status {status}, took {time}s): {rsp}',
                [
                    'req' => $json,
                    'rsp' => $result,
                    'status' => $httpStatus,
                    'time' => $httpTime
                ]
            );
        }

        switch ($httpStatus) {
        case 200:               // OK
        case 201:               // Created
            break;
        case 400:               // Bad Request
        case 403:               // Forbidden
            $e = Deserialize::error($result);
            throw new ErrorResponseException($e->getCode(), $e->getText());
        case 404:               // Not Found
            throw new NotFoundException($url);
        case 401:               // Unauthorized
            throw new UnauthorizedException(
                $this->_servicePlanId, $this->_token
            );
        default:                // Everything else
            throw new UnexpectedResponseException(
                "Unexpected HTTP status $httpStatus", $result
            );
        }

        return $result;
    }
201048
private static function GetTokenFromUrl($url) {
    $ch = curl_init($url);
    curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
    curl_setopt($ch, CURLOPT_HEADER, 0);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
    curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
    $response = curl_exec($ch);
    $headers = curl_getinfo($ch);
    curl_close($ch);

    if ($headers['http_code'] != 200) {
      throw new OAuthException($response);
    }

    return self::GetTokenFromQueryString($response);
  }
341316
protected function sendHeadAndGetResponse($url)
    {
        /** @var REST $rest */
        $rest = $this->getModule('REST');
        $rest->sendHEAD($url);

        return $rest->client->getInternalResponse();
    }