作者 lyh

gx

... ... @@ -119,6 +119,33 @@ if (!function_exists('http_get')) {
}
}
if (!function_exists('curl_get')) {
function curl_get($url,$is_array=true)
{
$header = array(
'Expect:',
'Content-Type: application/json; charset=utf-8'
);
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HEADER, false);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/42.0.2311.135 Safari/537.36 Edge/12.246');
curl_setopt($ch, CURLOPT_AUTOREFERER, true);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 120);
curl_setopt($ch, CURLOPT_TIMEOUT, 120);
curl_setopt($ch, CURLOPT_MAXREDIRS, 10);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
curl_setopt($ch, CURLOPT_SSLVERSION, 'all');
curl_setopt($ch, CURLOPT_HTTPHEADER, $header);
$content = curl_exec($ch);
curl_close($ch);
return $is_array ? json_decode($content, true) : $content;
}
}
if (!function_exists('curl_c')) {
/**
* @param $url
... ... @@ -148,7 +175,6 @@ if (!function_exists('curl_c')) {
$content = curl_exec($ch);
$http_code = curl_getinfo($ch,CURLINFO_HTTP_CODE);
curl_close($ch);
if($http_code == 200){
return $is_array ? json_decode($content, true) : $content;
}else{
... ...
... ... @@ -313,7 +313,7 @@ class NewsController extends BaseController
],[
'keyword.required' => 'keyword不能为空',
]);
$data = curl_c('http://gnews.globalso.com/gnews_news.php?keyword='.$this->param['keyword']);
$data = curl_get('http://gnews.globalso.com/gnews_news.php?keyword='.$this->param['keyword'],false);
$this->response('success',Code::SUCCESS,$data);
}
... ...