CURL获取公众号临时素材并保存到本地的方法
发表时间:2020-9-26
发布人:葵宇科技
浏览次数:68
public function getImage($token,$media_id)
{
$url = "https://api.weixin.qq.com/cgi-bin/media/get?access_token=".$token."&media_id=".$media_id;
$filename = './pic/test.jpg';
$curl = curl_init($url);
curl_setopt($curl, CURLOPT_HEADER, 0);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl, CURLOPT_TIMEOUT, 500);
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, 0);
$content = curl_exec($curl);
$curlinfo = curl_getinfo($curl);
curl_close($curl);
$res = file_put_contents($filename, $content);
return true;
}