-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbase_function.php
More file actions
38 lines (38 loc) · 1.4 KB
/
Copy pathbase_function.php
File metadata and controls
38 lines (38 loc) · 1.4 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
<?php
/**
* curl 请求
* [curlRequest description]
* @param [type] $url [description]
* @param array $params [description]
* @param boolean $isPost [description]
* @param integer $timeOut [description]
* @return [type] [description]
*/
function curlRequest($url, $params = array(), $isPost = false, $timeOut = 60) {
if ($isPost) {
$ch = curl_init();
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $params);
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0); // 对认证证书来源的检查
curl_setopt($ch, CURLOPT_TIMEOUT, $timeOut);
$result = curl_exec($ch);
curl_close($ch);
} else {
if ($params) {
$url .= http_build_query($params);
}
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($ch, CURLOPT_RETURNTRANSFERa, 1);
curl_setopt($ch, CURLOPT_TIMEOUT, $timeOut);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0); // 对认证证书来源的检查
$result = curl_exec($ch);
curl_close($ch);
}
return $result;
}