protected function curl($url, $data, $headers = [], $return_header = 0, $method = 'post')
{
$curl = curl_init();
curl_setopt($curl, CURLOPT_HTTPHEADER, $headers);
curl_setopt($curl, CURLOPT_URL, $url);
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, false);
if (!empty($data)) {
curl_setopt($curl, CURLOPT_POST, 1);
// curl_setopt($curl,CURLOPT_POSTFIELDS,http_build_query($data));//$data可以是数组
curl_setopt($curl, CURLOPT_POSTFIELDS, $data);
if ($method != 'post') {
curl_setopt($curl, CURLOPT_CUSTOMREQUEST, $method);
}
}
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
if ($return_header == 1) {
curl_setopt($curl, CURLOPT_HEADER, TRUE);
}
$output = curl_exec($curl);
curl_close($curl);
return $output;
}
PHP调用第三方接口(CURL)
最新推荐文章于 2024-04-15 18:46:40 发布