curlPost

pigcms 中微信群发报错可能由于PHP版本导致的。以下中文注释那里可做参考
function curlPost($url, $data,$showError=1){
$ch = curl_init();
$header = "Accept-Charset: utf-8";
curl_setopt ($ch, CURLOPT_SAFE_UPLOAD, false);  //by zhyj 在php5.6之前的版本上以上面的代码上传文件是没有问题的,但从php5.6.0开始,需要加上curl_setopt ( $ch, CURLOPT_SAFE_UPLOAD, false);这行代码方可上传,否则取不到文件。
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE);
curl_setopt($curl, CURLOPT_HTTPHEADER, $header);
curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/5.0 (compatible; MSIE 5.01; Windows NT 5.0)');
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($ch, CURLOPT_AUTOREFERER, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$tmpInfo = curl_exec($ch);
$errorno=curl_errno($ch);
if ($errorno) {
return array('rt'=>false,'errorno'=>$errorno);
}else{
$js=json_decode($tmpInfo,1);
if (intval($js['errcode']==0)){
return array('rt'=>true,'errorno'=>0,'media_id'=>$js['media_id'],'msg_id'=>$js['msg_id']);
}else {
if ($showError){
if($js['errcode'] == '40130'){
$this->error('抱歉,群发消息至少要选择两个人以上。');
}else{
$this->error('发生了Post错误:错误代码'.$js['errcode'].',微信返回错误信息:'.$js['errmsg']);
}
}
}
}
}
function curlGet($url){
$ch = curl_init();
$header = "Accept-Charset: utf-8";
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "GET");
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE);
curl_setopt($curl, CURLOPT_HTTPHEADER, $header);
curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/5.0 (compatible; MSIE 5.01; Windows NT 5.0)');
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($ch, CURLOPT_AUTOREFERER, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$temp = curl_exec($ch);
return $temp;
}
}

你可能感兴趣的:(curlPost)