<?php
/**
 * [UQcms System] Copyright uqcms.com
 * QQ: 2200631718
 * Author: gj.name
 * This is NOT a freeware
*/  class curl { public static function get($url){ $curl = curl_init(); curl_setopt($curl, CURLOPT_URL, $url); curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1); curl_setopt($curl, CURLOPT_HEADER, 0); curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, FALSE); curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, FALSE); curl_setopt($curl, CURLOPT_FOLLOWLOCATION, TRUE); curl_setopt($curl, CURLOPT_USERAGENT, 'Mozilla/5.0 (compatible; MSIE 5.01; Windows NT 5.0)'); curl_setopt($curl, CURLOPT_TIMEOUT, 15); $output = curl_exec($curl); curl_close($curl); return $output; } public static function post($url, $data, $header = null){ $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST"); curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE); curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE); curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1); curl_setopt($ch, CURLOPT_AUTOREFERER, 1); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/5.0 (compatible; MSIE 5.01; Windows NT 5.0)'); curl_setopt($ch, CURLOPT_TIMEOUT, 15); curl_setopt($ch, CURLOPT_POSTFIELDS, $data); if($header){ $headers = array(); foreach ($header as $key => $val){ array_push($headers, "$key: $val"); } curl_setopt($ch, CURLOPT_HTTPHEADER, $headers); } $output = curl_exec($ch); curl_close($ch); return $output; } public static function put($url, $data, $header = null){ $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "PUT"); curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE); curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE); curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1); curl_setopt($ch, CURLOPT_AUTOREFERER, 1); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch, CURLOPT_HEADER, 0); curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/5.0 (compatible; MSIE 5.01; Windows NT 5.0)'); curl_setopt($ch, CURLOPT_TIMEOUT, 15); curl_setopt($ch, CURLOPT_POSTFIELDS, $data); if($header){ $headers = array(); foreach ($header as $key => $val){ array_push($headers, "$key: $val"); } curl_setopt($ch, CURLOPT_HTTPHEADER, $headers); } $output = curl_exec($ch); curl_close($ch); return $output; } public static function post2($url, $para, $input_charset = ''){ if (trim($input_charset) != '') { $url = $url."_input_charset=".$input_charset; } $curl = curl_init($url); curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, FALSE); curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, FALSE); curl_setopt($curl, CURLOPT_HEADER, 0 ); curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1); curl_setopt($curl, CURLOPT_POST,true); curl_setopt($curl, CURLOPT_POSTFIELDS,$para); $responseText = curl_exec($curl); var_dump( curl_error($curl) ); curl_close($curl); return $responseText; } public static function downloadFile($url, $filename = null, $type = 0){ if (trim($url) == '') { return false; } if($type){ $header = array("Connection: Keep-Alive", "Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8", "Pragma: no-cache", "Accept-Language: zh-Hans-CN,zh-Hans;q=0.8,en-US;q=0.5,en;q=0.3", "User-Agent: Mozilla/5.0 (Windows NT 5.1; rv:29.0) Gecko/20100101 Firefox/29.0"); $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_HTTPHEADER, $header); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 20); curl_setopt($ch, CURLOPT_ENCODING, 'gzip,deflate'); $content = curl_exec($ch); $curl_info = curl_getinfo($ch); curl_close($ch); }else{ ob_start(); readfile($url); $content = ob_get_contents(); ob_end_clean(); } file::mk_dir($filename, true); file::write_file($filename, $content); $filesize = strlen($content); unset($content, $url); return array( 'filename' => $filename, 'filesize' => $filesize ); } static function asynGET($url){ $host = $_SERVER['SERVER_NAME']; $port = $_SERVER['SERVER_PORT']; $fp = fsockopen($host, $port, $errno, $errstr, 20); if($fp){ $out = "GET ".cfg('site_url').$url." HTTP/1.1\r\n"; $out .= "Host: ".$host.":".$port."\r\n"; $out .= "Connection: Close\r\n\r\n"; fwrite($fp, $out); fclose($fp); } } static function asynPost($url, $param){ $host = $_SERVER['SERVER_NAME']; $port = $_SERVER['SERVER_PORT']; $fp = fsockopen($host, $port, $errno, $errstr, 20); if($fp){ $query = http_build_query($param); $out = "POST ".HOST_URI.$url." HTTP/1.0\r\n"; $out .= "Host:".cfg('site_url').":".$port."\r\n"; $out .= "Content-type:application/x-www-form-urlencoded\r\n"; $out .= "Content-Length:".strlen($query)."\r\n"; $out .= "Connection:close\r\n\r\n"; $out .= $query."\r\n"; fwrite($fp, $out); fclose($fp); } } }