公众号新增临时素材返回结果空?
公众号新增临时素材返回空
$url = "https://api.weixin.qq.com/cgi-bin/media/upload?access_token=".$token."&type=image";
if(class_exists('CURLFile')){
$bodys = array('media' => new \CURLFile(realpath($img_url)));
}else{
$bodys = array('media' => '@'.$img_url);
}
$res = self::curl_post($url, $bodys);
var_dump($res); //此处返回了一个空的字符串
public static function curl_post($url, $postdata ) {
//初始化
$curl = curl_init();
if(class_exists('CURLFile')){
curl_setopt($curl, CURLOPT_SAFE_UPLOAD, true);
}else{
if(defined('CURLOPT_SAFE_UPLOAD')){
curl_setopt($curl, CURLOPT_SAFE_UPLOAD, false);
}
}
//设置抓取的url
curl_setopt($curl, CURLOPT_URL, $url);
//设置头文件的信息作为数据流输出
curl_setopt($curl, CURLOPT_HEADER, 0);
//设置获取的信息以文件流的形式返回,而不是直接输出。
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
// 超时设置
curl_setopt($curl, CURLOPT_TIMEOUT, 10);
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, FALSE );
curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, FALSE );
//设置post方式提交
curl_setopt($curl, CURLOPT_POST, 1);
curl_setopt($curl, CURLOPT_POSTFIELDS, $postdata);
//执行命令
$data = curl_exec($curl);
// 显示错误信息
if (curl_error($curl)) {
return curl_error($curl);
} else {
curl_close($curl);
return $data;
}
}