/**
*
* [curl_post post方式请求]
*
* @param [type] $url [description]
*
* @param string $data [description]
*
* @return [type] [description]
*
*/
protected function curl_post($url,$data='')
{
if(empty($url) || empty($data)){
return false;
}
$postUrl = $url;
$curlPost = $data;
//初始化curl
$ch = curl_init();
//抓取指定网页
curl_setopt($ch, CURLOPT_URL,$postUrl);
//设置header
curl_setopt($ch, CURLOPT_HEADER, 0);
//要求结果为字符串且输出到屏幕上
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
//post提交方式
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $curlPost);
//运行curl
$data = curl_exec($ch);
curl_close($ch);
return $data;
}
/**
*
* [curl_get get方式请求]
*
* @param [type] $url [description]
*
* @param string $data [description]
*
* @return [type] [description]
*
*/
protected function curl_get($url,$data='')
{
if(empty($url)){
return false;
}
//初始化
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL,$url);
// 执行后不直接打印出来
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HEADER, false);
// 跳过证书检查
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
// 不从证书中检查SSL加密算法是否存在
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
//执行并获取HTML文档内容
$output = curl_exec($ch);
//释放curl句柄
curl_close($ch);
$output = json_decode($output,1);
return $output;
}