CURL 请求外部接口
protected function getData()
{
curl_setopt($this->curlHandle, CURLOPT_SSL_VERIFYHOST, false);
curl_setopt($this->curlHandle, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($this->curlHandle, CURLOPT_URL, $this->request_url);
curl_setopt($this->curlHandle, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($this->curlHandle, CURLOPT_TIMEOUT, $this->timeout);
curl_setopt($this->curlHandle, CURLOPT_HEADER, 0);
$result = curl_exec($this->curlHandle);
if (curl_errno($this->curlHandle)) {
return false;
} else {
return $result;
}
}
private function postData($data)
{
$data = json_encode($data, JSON_UNESCAPED_UNICODE);
curl_setopt($this->curlHandle, CURLOPT_SSL_VERIFYHOST, false);
curl_setopt($this->curlHandle, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($this->curlHandle, CURLOPT_URL, $this->request_url);
curl_setopt($this->curlHandle, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($this->curlHandle, CURLOPT_POST, 1);
curl_setopt($this->curlHandle, CURLOPT_TIMEOUT, $this->timeout);
curl_setopt($this->curlHandle, CURLOPT_POSTFIELDS, $data);
$result = curl_exec($this->curlHandle);
if (curl_errno($this->curlHandle)) {
echo curl_errno($this->curlHandle).':'.curl_error($this->curlHandle);
return false;
} else {
return $result;
}
}