You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
55 lines
1.5 KiB
55 lines
1.5 KiB
<?php |
|
|
|
use Illuminate\Support\Facades\Redis as RedisAlias; |
|
|
|
/** |
|
* CURL访问 |
|
* @param string $url |
|
* @param string $methon |
|
* @param array $postData |
|
*/ |
|
function getDataByCurl($url, $methon = "GET", $postData = []) |
|
{ |
|
//初始化 |
|
$curl = curl_init(); |
|
//设置抓取的url |
|
curl_setopt($curl, CURLOPT_URL, $url); |
|
//设置头文件的信息作为数据流输出 |
|
curl_setopt($curl, CURLOPT_HEADER, 1); |
|
//设置获取的信息以文件流的形式返回,而不是直接输出。 |
|
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1); |
|
//检测是以GET还是POST方式访问 |
|
if($methon == "POST"){ |
|
//设置post方式提交 |
|
curl_setopt($curl, CURLOPT_POST, 1); |
|
//设置post数据 |
|
curl_setopt($curl, CURLOPT_POSTFIELDS, $postData); |
|
} |
|
//执行命令 |
|
$data = curl_exec($curl); |
|
|
|
//请求成功时去除header数据(如url返回json格式时,去除header可取出完整的Json数据) |
|
if(curl_getinfo($curl, CURLINFO_HTTP_CODE) == "200"){ |
|
$headerSize = curl_getinfo($curl, CURLINFO_HEADER_SIZE); // 获取header长度 |
|
$data = substr($data, $headerSize); //截掉header |
|
} |
|
|
|
//关闭URL请求 |
|
curl_close($curl); |
|
|
|
return $data; |
|
} |
|
|
|
function getDateRange($start, $end) { |
|
$dates = []; |
|
$current = strtotime($start); |
|
$end = strtotime($end); |
|
while ($current <= $end) { |
|
$dates[] = date('Y-m-d', $current); |
|
$current = strtotime('+1 day', $current); |
|
} |
|
return $dates; |
|
} |
|
|
|
|
|
|
|
|