headers 携带参数模拟请求方法
** curl 获取 https 请求
* @param String $url 请求的url
* @param mixed $data 要发送的数据
* @param mixed $header 请求时发送的header
* @param int $timeout 超时时间,默认30s
*/
function curl_https($url, $data = array(), $header = array(), $timeout = 30)
{
$ch = curl_init();
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_HTTPHEADER, $header);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_TIMEOUT, $timeout);
$response = curl_exec($ch);
if ($error = curl_error($ch)) {
die($error);
}
curl_close($ch);
return $response;
}
$path='www.xxxx.com';
$headers = [
"Content-Type: application/json",
"Accept: application/json",
'access_token: '.$_SERVER['access_token'],
];
$params=json_encode($param);
$result= curl_https($path, $params ,$headers);