为己疯狂
2017-05-25 10:14
public function http_curl($url='',$type='',$res='',$arr=''){
//获取**,初始化curl
$ch = curl_init();
//设置curl参数
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);//curopt_returntransfer
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER,FALSE);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST,FALSE);
curl_setopt($ch, CURLOPT_HEADER, FALSE);
if($type == 'post'){
curl_setopt($ch, CURLOPT_PORT, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $arr);
}
//采集(调用接口)
$output = curl_exec($ch);
//关闭
curl_close($ch);
if($res == 'json'){
if(curl_errno($ch)){
return curl_error($ch);
}else{
return json_decode($output,true);
}
}
//var_dump($output);
}
默认值错了?
protected function http_curl($url, $arr = '', $type = 'get', $res = 'json')
{
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
if ($type == 'post') {
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $arr);
}
$output = curl_exec($ch);
if ($res == 'json') {
if ($err = curl_errno($ch)) {
//要在关闭之前获得curl_errno
curl_close($ch);
return $err;
} else {
return json_decode($output, true);
}
}
}
估计url错了,导致 curl不成功
PHP微信公众平台开发高级篇—群发接口
18567 学习 · 12 问题
相似问题