示例#1
0
 public function translate($phrase, $lang_from = "ru", $lang_to = "en")
 {
     $params = ['key' => $this->config['key'], 'text' => $phrase, 'lang' => "{$lang_from}-{$lang_to}"];
     $response = json_decode($this->curl->get("api/v1.5/tr.json/translate", $params), true);
     if ($response['code'] != 200) {
         throw new Exception($this->error_codes[$this->curl->last_http_code] ?: "Unknown error", $this->curl->last_http_code);
     }
     return $response;
 }
示例#2
0
 /**
  * @param Url $url
  *
  * @return File
  * @throws DownloadFailedException
  */
 public function download(Url $url)
 {
     $this->output->writeInfo(sprintf('Downloading %s', $url));
     $response = $this->curl->get($url);
     if ($response->getHttpCode() !== 200) {
         throw new DownloadFailedException(sprintf('Download failed (HTTP status code %s) %s', $response->getHttpCode(), $response->getErrorMessage()));
     }
     if (empty($response->getBody())) {
         throw new DownloadFailedException('Download failed - response is empty');
     }
     return new File($this->getFilename($url), $response->getBody());
 }
示例#3
0
 public function run()
 {
     $pageURL = $this->getUrl();
     $pageHTML = $this->curl->get($pageURL);
     $emails = $this->parser->getEmails($pageHTML);
     $countEmails = count($emails);
     $URLs = $this->parser->getURLs($pageHTML);
     $this->model->saveEmails($emails);
     $this->model->saveURLs($URLs);
     echo "Download emails from address '{$pageURL}' is complete.\n";
     echo "There are {$countEmails} records.\n";
 }
 /**
  * @param string $keyId
  *
  * @return string
  * @throws DownloadFailedException
  */
 public function download($keyId)
 {
     $params = ['search' => '0x' . $keyId, 'op' => 'get', 'options' => 'mr'];
     foreach ($this->keyServers as $keyServer) {
         $this->output->writeInfo(sprintf('Trying %s', $keyServer));
         $result = $this->curl->get(new Url($keyServer . self::PATH), $params);
         if ($result->getHttpCode() == 200) {
             $this->output->writeInfo('Sucessfully downloaded key');
             return $result->getBody();
         }
         $this->output->writeWarning(sprintf('Failed with status code %s: %s', $result->getHttpCode(), $result->getErrorMessage()));
     }
     throw new DownloadFailedException(sprintf('Key %s not found on key servers', $keyId));
 }
 public static function getProblemInfo($problemId)
 {
     // 新建一个curl
     $ch = new Curl();
     $url = 'http://poj.org/problem?id=' . $problemId;
     $html = $ch->get($url);
     if (empty($html) || $ch->error()) {
         $ch->close();
         return false;
     }
     $ch->close();
     $problemInfo = array();
     $matches = array();
     // 获取标题
     preg_match('/<div class="ptt" lang="en-US">(.*)<\\/div>/sU', $html, $matches);
     $problemInfo['title'] = '';
     if (!empty($matches[1])) {
         $problemInfo['title'] = trim($matches[1]);
     }
     // 获取来源
     preg_match('/<a href="searchproblem\\?field=source.*>(.*)<\\/a>/sU', $html, $matches);
     $problemInfo['source'] = '';
     if (!empty($matches[1])) {
         $problemInfo['source'] = trim($matches[1]);
     }
     $problemInfo['problem_id'] = $problemId;
     $problemInfo['problem_code'] = $problemId;
     return $problemInfo;
 }
示例#6
0
 public function process_user($username, $password, $facility_code)
 {
     $curl = new Curl();
     $response = array();
     //Get Supplier
     $supplier = $this->get_supplier($facility_code);
     if ($supplier == "kemsa") {
         //Use nascop url
         $url = $this->default_url;
         $post = array("email" => $username, "password" => $password);
         $url = $this->default_url . 'sync/user';
         $curl->post($url, $post);
     } else {
         //Use escm url
         $curl->setBasicAuthentication($username, $password);
         $curl->setOpt(CURLOPT_RETURNTRANSFER, TRUE);
         $url = $this->default_url . 'user/' . $username;
         $curl->get($url);
     }
     //Handle Response
     if ($curl->error) {
         $response['error'] = TRUE;
         $response['content'] = array($curl->error_code);
     } else {
         $response['error'] = FALSE;
         $response['content'] = json_decode($curl->response, TRUE);
     }
     return json_encode($response);
 }
示例#7
0
 public function getAllGroups()
 {
     $url = $this->apiUrl . "/cgi-bin/groups/get?access_token={$this->access_token}";
     $content = Curl::get($url);
     $result = json_decode($content, true);
     return $this->get($result);
 }
示例#8
0
 function get($url, $get = array())
 {
     $curl = Curl::get($url, $get);
     $curl->option(array(CURLOPT_COOKIESESSION => true, CURLOPT_RETURNTRANSFER => true, CURLOPT_COOKIEJAR => $this->cookie, CURLOPT_HTTPHEADER => $this->header, CURLOPT_CONNECTTIMEOUT => 100));
     $r = $curl->call();
     return $r->raw_body;
 }
示例#9
0
 public function total()
 {
     $url = $this->apiUrl . "/cgi-bin/material/get_materialcount?access_token={$this->access_token}";
     $content = Curl::get($url);
     $result = json_decode($content, true);
     return $this->get($result);
 }
示例#10
0
 public function getUserLists($next_openid = '')
 {
     $url = $this->apiUrl . "/cgi-bin/user/get?access_token={$this->access_token}&next_openid={$next_openid}";
     $content = Curl::get($url);
     $result = json_decode($content, true);
     return $this->get($result);
 }
示例#11
0
文件: CurlTest.php 项目: nickl-/curl
 function testValidatedSsl()
 {
     $curl = new Curl();
     $curl->setValidateSsl(true);
     $response = $curl->get('https://www.facebook.com/');
     $this->assertEquals(200, $response->headers['Status-Code']);
 }
示例#12
0
 function test_error()
 {
     assert_throws('CurlException', function () {
         $curl = new Curl();
         $curl->get('diaewkaksdljf-invalid-url-dot-com.com');
     });
 }
 public static function getProblemInfo($problemId)
 {
     // 新建一个curl
     $ch = new Curl();
     $url = 'http://acm.hdu.edu.cn/showproblem.php?pid=' . $problemId;
     $html = $ch->get($url);
     if (empty($html) || $ch->error()) {
         $ch->close();
         return false;
     }
     $ch->close();
     $problemInfo = array();
     $matches = array();
     // 获取标题
     preg_match('/<td align=center><h1 style=\'color:#1A5CC8\'>(.*)<\\/h1>/sU', $html, $matches);
     $problemInfo['title'] = '';
     if (!empty($matches[1])) {
         $problemInfo['title'] = trim($matches[1]);
         $problemInfo['title'] = iconv('GBK', 'UTF-8', $problemInfo['title']);
     }
     // 获取来源
     preg_match('/>Source.*<a.*\\/search.php.*>(.*)<\\/a>/sU', $html, $matches);
     $problemInfo['source'] = '';
     if (!empty($matches[1])) {
         $problemInfo['source'] = trim($matches[1]);
         $problemInfo['source'] = iconv('GBK', 'UTF-8', $problemInfo['source']);
     }
     $problemInfo['problem_id'] = $problemId;
     $problemInfo['problem_code'] = $problemId;
     return $problemInfo;
 }
 public function expressTakeDetail($userID)
 {
     $curl = new Curl();
     $expressTakeDetail = $curl->get($this->url['expressTakeUser'] . "?userID=" . $userID);
     $expressListUsers = $curl->get($this->url['expressListUsers']);
     foreach ($expressTakeDetail as $key => &$takeDetail) {
         $createUserID = $takeDetail->express_create_user_id;
         $fromUserID = $takeDetail->express_from_user_id;
         $toUserID = $takeDetail->express_to_user_id;
         $takeDetail->express_create_user_id_attr = $expressListUsers->{$createUserID};
         $takeDetail->express_from_user_id_attr = $expressListUsers->{$fromUserID};
         $takeDetail->express_to_user_id_attr = $expressListUsers->{$toUserID};
         $takeDetail->express_take_status_attr = self::$error[$takeDetail->express_take_status];
     }
     return $expressTakeDetail;
 }
示例#15
0
 public function get_link()
 {
     // Check Captcha
     $response = file_get_contents("https://www.google.com/recaptcha/api/siteverify?secret=6LfXLBwTAAAAAKog-gWVMOmDJKhHGEMCELdR-Ukn&response=" . Input::get('g-recaptcha-response'));
     $obj = json_decode($response);
     if ($obj->success == false) {
         echo 'Captcha error';
         exit;
     } else {
         libxml_use_internal_errors(true);
         require_once app_path('Libraries/Curl.php');
         $url = Input::get('url');
         $url = str_replace("http://", "https://", $url);
         // step 1: Login
         $curl = new \Curl();
         $curl->get('https://www.fshare.vn');
         $session_id = $curl->getCookie('session_id');
         $doc = new \DOMDocument();
         $doc->loadHTML($curl->response);
         $xpath = new \DOMXpath($doc);
         $array = $xpath->query("//*[@id='login-form']//*[@name='fs_csrf']");
         foreach ($array as $value) {
             $fs_csrf = $value->getAttribute('value');
         }
         $curl->setCookie('session_id', $session_id);
         $curl->post('https://www.fshare.vn/login', array("fs_csrf" => $fs_csrf, "LoginForm[email]" => "*****@*****.**", "LoginForm[password]" => "7508286", "LoginForm[rememberMe]" => "0", "yt0" => "Đăng nhập"));
         $session_id = $curl->getCookie('session_id');
         $curl->setCookie('session_id', $session_id);
         $curl->post('https://www.fshare.vn/login', array("fs_csrf" => $fs_csrf, "LoginForm[email]" => "*****@*****.**", "LoginForm[password]" => "7508286", "LoginForm[rememberMe]" => "0", "yt0" => "Đăng nhập"));
         echo "Step 1: Login - Done !!! <br>";
         // step 2: Get link download
         $curl->get($url);
         $doc = new \DOMDocument();
         $doc->loadHTML($curl->response);
         $xpath = new \DOMXpath($doc);
         $array = $xpath->query("//*[@id='download-form']/div[1]/input");
         foreach ($array as $value) {
             $fs_csrf = $value->getAttribute('value');
         }
         $split_url = explode('/', $url);
         $curl->post('https://www.fshare.vn/download/get', array("fs_csrf" => $fs_csrf, "DownloadForm[pwd]" => "", "DownloadForm[linkcode]" => end($split_url), "ajax" => "download-form", "undefined" => "undefined"));
         echo "Step 2: Get Link Download - Done !!! <br><br>";
         echo "URL: " . @$curl->response->url;
         return redirect()->away($curl->response->url);
     }
     // END IF CHECK RECAPTCHA
 }
示例#16
0
文件: CurlTest.php 项目: php-mod/curl
 public function testError()
 {
     $this->curl->setOpt(CURLOPT_CONNECTTIMEOUT_MS, 2000);
     $this->curl->get('http://1.2.3.4/');
     $this->assertTrue($this->curl->error === TRUE);
     $this->assertTrue($this->curl->curl_error === TRUE);
     $this->assertTrue($this->curl->curl_error_code === CURLE_OPERATION_TIMEOUTED);
 }
示例#17
0
    function __scrapeTVShow($url, $offset=0, $count=12) {
        if ($this->stats) {
            $this->stats->start('icefilms.info:tv', "$url");
        }
        $curl = new Curl();
        $html = $curl->get($url);
        if (!$html) {
            return false;
        }
        $dom = new DOMDocument();
        @$dom->loadHTML($html); // Suppress warnings - odds are there are PLENTY!
        $xpath = new DOMXPath($dom);
        $nodes = $xpath->query("//h1");
        $seasons = array();
        foreach ($nodes as $header) {
            // Scrape IMDB info (name, id, metainfo)
            $name = $header->nodeValue;
            # and starts-with(@href, 'http://www.imdb.com/title/tt')", $header);
            $imdblinks = $xpath->query(".//a[@class='iframe' and starts-with(@href, 'http://www.imdb.com/title/tt')]", $header);
            $metaInfo = array();
            foreach ($imdblinks as $imdblink) {
                $imdblink = $imdblink->attributes->getNamedItem('href')->nodeValue;
                if (preg_match('|/title/(tt[0-9]+)|', $imdblink, $matches)) {
                    $id = $matches[1];
                    $metaInfo = $this->metahandler->getMetaInfo($id);
                    $metaInfo['id'] = $id;
                }
                break;
            }
            $metaInfo['name'] = $name;

            // Scrape seasons
            $nodes = $xpath->query("//span[@class='list']/h4|//span[@class='list']/a[@href and starts-with(@href, '/ip.php')]");
            $season = FALSE;
            foreach ($nodes as $node) {
                // Should be both h4 and a nodes.
                if ($node->nodeName == 'h4') {
                    if ($season) {
                        $seasons[] = $season;
                    }
                    $season = array('name' => $node->nodeValue, 'episodes' => array());
                } else if ($node->nodeName == 'a' && $season) {
                    $episode = array('name' => $node->nodeValue, 'url' => $node->attributes->getNamedItem('href')->nodeValue);
                    $season['episodes'][] = $episode;
                }
            }
            if ($season) {
                $seasons[] = $season;
            }
            break;
        }
        $data = array('show' => $metaInfo, 'seasons' => $seasons, 'count' => sizeof($nodes));
        $this->pagecache->cacheMovies($url, 0, 0, $data);
        if ($this->stats) {
            $this->stats->end('icefilms.info:tv');
        }
        return $data;
    }
示例#18
0
    /**
     * Returns a MetaInfo object.
     **/
    function getMetaInfo($id)
    {
        if ($this->stats) {
            $this->stats->start('tmdb', "getMetaInfo, $id");
        }
        $curl = new Curl();
        // TODSELECT s1.name, ROUND(s1.microtime/1000) 'sec', COUNT(*), MIN(s2.microtime), AVG(s2.microtime), MAX(s2.microtime) FROM `icerss_stats` s1, `icerss_stats` s2 WHERE s1.name = s2.name GROUP BY s1.name, secO: protect against injections?
        $jsonData = $curl->get('http://api.themoviedb.org/2.1/Movie.imdbLookup/en/json/' . $this->api_key . '/' . $id);
        $data = json_decode($jsonData, true);
        if (!$data) {
            return False;
        }
		$data = $data[0];
        $genres = array();
		if (array_key_exists('genres', $data)) {
	        foreach ($data['genres'] as $genre) {
	        	$genres[] = $genre['name'];
	        }
		}
        // [0.0 - 10.0] -> 0-5
        $rating = floatval($data['rating']) / 2;
        $writers = preg_split(COMMA, $data->Writer);
        $actors = preg_split(COMMA, $data->Actors);
        $plot = array('en' => $data['overview']);
		$poster = 'N/A';
		if (array_key_exists('posters', $data)) {
			foreach ($data['posters'] as $img) {
				if ($img['image']['size'] == 'cover') {
					$poster = $img['image']['url'];
					break;
				}
			}
		}
		$runtime = intval($data['runtime']); // Minutes
		$runtime = intval(floor($runtime / 60)) . ' hr ' . ($runtime % 60) . ' mins';
		$year = $data['released'];
		if (strlen($year) > 4) {
			$year = substr($year, 0, 4);
		}
		$tmdb = $data['id'];
		// TODO: Fetch director, writers + actors
        if ($this->stats) {
            $this->stats->end('tmdb');
        }
        return array(
            'id' => $id,
            'title' => $data['name'],
            'year' => $year,
            'genres' => $genres,
            'plot' => $plot,
            'poster' => $poster,
            'runtime' => $runtime,
            'rating' => $rating,
            'director' => '',
            'writers' => array(),
            'actors' => array()
        );
    }
示例#19
0
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $this->app = $this->getApplication();
     $curl = new \Curl();
     $response = $curl->get('https://api.github.com/zen');
     if ($response->headers['Status-Code'] != 200) {
         $output->writeln('GitHub has failed with :' . $response->headers['Status-Code']);
     }
     $output->writeln($response->body);
 }
示例#20
0
/**
    Error checking
*/
function latest_version()
{
    // only run the version check once per session
    if (($version = Session::get('latest_version')) === false) {
        // returns plain text string with version number or 0 on failure.
        $version = floatval(Curl::get('http://anchorcms.com/version'));
        Session::set('latest_version', $version);
    }
    return $version;
}
示例#21
0
 /**
  * 获得用户信息
  *
  */
 public function get_user_info($code)
 {
     $this->config->load('oauth_qq');
     $curl = new Curl();
     $access_token = $this->get_access_token($code);
     $open_id = $this->get_open_id($access_token);
     $url = 'https://graph.qq.com/user/get_user_info';
     $postdata = array('access_token' => $access_token, 'oauth_consumer_key' => $this->config->item('api_key'), 'openid' => $open_id);
     $response = $curl->get($url, $postdata);
     return $response;
 }
示例#22
0
 public function testHeader()
 {
     $c = new Curl();
     $c->init();
     // testing out of app, so have to initialize manually
     $result = $c->get('http://echo.jsontest.com/key/value/one/two');
     $json = json_decode($result);
     $this->assertEquals($json->key, 'value');
     $headers = $c->getHeaders();
     $this->assertContains('HTTP/1.1 200 OK', $headers);
 }
示例#23
0
 public function snsapiUserinfo()
 {
     $data = $this->request('snsapi_userinfo');
     if ($data !== FALSE) {
         $url = "https://api.weixin.qq.com/sns/userinfo?access_token=" . $data['access_token'] . "&openid=" . $data['openid'] . "&lang=zh_CN";
         $d = Curl::get($url);
         $res = $this->get(json_decode($d, TRUE));
         return isset($data['errcode']) ? FALSE : $res;
     }
     return FALSE;
 }
示例#24
0
 public function checkConnection()
 {
     //Check Internet Connection
     $curl = new Curl();
     $url = "http://google.com/";
     $curl->get($url);
     if ($curl->error) {
         echo json_encode('0');
     } else {
         echo json_encode('1');
     }
 }
示例#25
0
文件: IpType.php 项目: oyoy8629/test
 public static function ip($ip)
 {
     $url = 'http://apis.baidu.com/rtbasia/ip_type/ip_type?ip=' . $ip;
     $curl = new Curl();
     $curl->setHeader("apikey", "29ddcb64dbe2f42764115b28941d2154");
     $curl->get($url);
     $curl->close();
     if ($curl->error) {
         echo 'Error: ' . $curl->errorCode . ': ' . $curl->errorMessage;
     } else {
         return $curl->response;
     }
 }
示例#26
0
 public function testResponse()
 {
     $url = 'foo-bar';
     $options = [[CURLOPT_RETURNTRANSFER, TRUE], [CURLOPT_HEADER, TRUE]];
     $request = $this->getMockWithoutInvokingTheOriginalConstructor(Request::class);
     $response = $this->getMockWithoutInvokingTheOriginalConstructor(Response::class);
     $requestFactory = $this->getRequestFactory();
     $requestFactory->expects($this->once())->method('create')->with($url, $options)->willReturn($request);
     $responseFactory = $this->getResponseFactory();
     $responseFactory->expects($this->once())->method('create')->with($request)->willReturn($response);
     $curl = new Curl($url);
     $curl->setRequestFactory($requestFactory);
     $curl->setResponseFactory($responseFactory);
     $this->assertSame($response, $curl->get());
 }
示例#27
0
 /**
  * Execute
  * Currently only support json
  *
  * @param string $output preferred output json|xml (default:json)
  *
  * @throws \CurlException
  * @throws \BadMethodCallException
  * @return \CurlResponse|false
  */
 public function execute($output = 'json')
 {
     if ($this->getLocation() === null) {
         throw new \BadMethodCallException('location must be set location before execution');
     }
     $endpoint = self::ENDPOINT . $output;
     $param = array('key' => $this->getKey(), 'location' => $this->getLocation(), 'radius' => $this->getRadius(), 'sensor' => $this->getSensor());
     $param += $this->getOptParams();
     $curl = new \Curl();
     $response = json_decode($curl->get($endpoint, $param)->body);
     if ($response !== null && $response->status == 'OK') {
         return $response;
     } else {
         throw new \CurlException('Error to execute API', 500);
     }
 }
示例#28
0
 private function getMore($value, $id)
 {
     $pattern = '/<span\\s+class="code">(\\d+)<\\/span>/';
     $allId = array();
     for ($page = 1; $page < 200; $page++) {
         $url = "http://fundact.eastmoney.com/zhutijj/home/table?tp={$id}&rs=SYL_3Y&sort=SYL_3Y&sorttype=desc&pageindex={$page}";
         $html = Curl::get($url);
         if (empty(trim($html))) {
             self::log("{$id} Total Page : " . ($page - 1));
             break;
         }
         self::log("Get  {$id} At Page {$page} Ok");
         if (preg_match_all($pattern, $html, $matches)) {
             $allId = array_merge($allId, $matches[1]);
         }
     }
     return $allId;
 }
示例#29
0
 public function getPage($url, $i = 1)
 {
     $curl = new Curl();
     //$curl->get($url, array(), $this->proxy);
     $curl->get($url, array());
     $curl->setUserAgent($this->getUserAgent());
     echo $curl->http_status_code . "\n";
     if (200 == $curl->http_status_code) {
         $body = $curl->response;
         $findme = 'nid="' . $this->nid . '"';
         //echo $findme . "\n";
         //var_dump(strpos($body, $findme));
         //echo "\n";
         if (strpos($body, $findme)) {
             return $i;
         } else {
             if ($i >= 20) {
                 return -1;
             }
             //sleep();
             //$begin = microtime(true);
             $nextPagePattern = "/<\\/a><a href=\"\\/(.*?)\"  class=\"page-next\" trace='srp_select_pagedown'>/i";
             #$nextPagePattern = "/<a href=\"\/([_-=\.\?%&a-z0-9]+?)\"  class=\"page-next\" trace='srp_select_pagedown'>/i";
             preg_match_all($nextPagePattern, $body, $match);
             //$end = microtime(true);
             //echo "cost time: " . ($end - $begin);
             //echo "\n";
             //echo strpos($body, 'page-next');
             //echo $body;
             if (!$match[1][0]) {
                 print_r($match);
                 return -1;
             }
             $url = $this->taobaoSearchBaseUrl . $match[1][0];
             $sleepSecond = rand(2, 4);
             sleep($sleepSecond);
             $i++;
             echo $i . " not found\n";
             return $this->getPage($url, $i);
         }
     }
 }
示例#30
0
 /**
  * @biref       将网络文件上传到CDN源,非UTF-8的文本页面可能会出现乱码
  * @param       string  $url        网络文件的url
  * @param       int     $id         标识用户id,默认0
  * @param       string  $ext        文件的扩展名,$ext = 'jpg',如果不指定的话,会从url的扩展名中获取
  * @return      string  cdnKey      cdnKey
  * @exception   Exception
  */
 public static function uploadRemoteFile($url, $id = 0, $ext = '')
 {
     // 获取扩展名
     $path = Url::getPath($url);
     if (empty($ext) && strpos($path, '.')) {
         $arr = explode('.', $path);
         $ext = end($arr);
     }
     $ossClient = self::getOssClient();
     $cdnKey = self::makeKey($id, $ext);
     // 获取content type
     $contentType = '';
     if (!empty($ext)) {
         $mimeTypes = Response::getMimeTypes();
         $contentType = $mimeTypes[$ext];
     }
     $curl = new Curl();
     $ossClient->putObject(array('Bucket' => CdnConfig::BUCKET_NAME, 'Key' => $cdnKey, 'Content' => $curl->get($url), 'ContentEncoding' => GlobalConfig::CONTENT_CHARSET, 'ContentType' => $contentType));
     return $cdnKey;
 }