/** * curl請求 * @author Steed * @param $url * @param string $method * @param array $param * @return mixed */ function curlRequest($url, $method='post', $param = []) { $curl = curl_init();//初始化 curl_setopt($curl, CURLOPT_URL, $url);//設(shè)置要訪問的URL curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);//設(shè)置獲取的信息以文件流的形式返回,而不是直接輸出 if($method === 'post'){ curl_setopt($curl, CURLOPT_POST, 1);//設(shè)置post方式提交 curl_setopt($curl, CURLOPT_POSTFIELDS, $param);//設(shè)置post數(shù)據(jù) curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false); curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, false); } $data = curl_exec($curl);//執(zhí)行命令 curl_close($curl); return $data; } |
|