protected function curlPost($url, $headers, $body)
{
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 6);
curl_setopt($ch, CURLOPT_TIMEOUT, 10); // 设置超时限制防止死循环
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
curl_setopt($ch, CURLOPT_POSTFIELDS, $body);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
$output = curl_exec($ch);
$getData = json_decode($output, true);

$httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
$errMsg = curl_error($ch);
if (!empty($getData)) {
return ['curl_status' => 'SUCCESS', 'output' => $output, 'data' => $getData];
} else{
$error_info = [
'httpCode' => $httpCode,
];
if(!empty($errMsg)){
$error_info['errMsg'] = $errMsg;
}
return ['curl_status' => 'FAILD', 'output' => json_encode($error_info)];
}
}

发表回复

您的电子邮箱地址不会被公开。 必填项已用 * 标注