apache php 开发微信公众号, curl 下载语音,图片,视频 是https 开头的。遇到curl_init() 返回 bool(false)。就是这个问题。
PHP通过cURL访问https时出现SSL certificate problem: unable to get local issuer certificate的解决方法:只要设置以下两个属性就可以解决。
将 CURLOPT_SSL_VERIFYPEER 设置为 false,
将 CURLOPT_SSL_VERIFYHOST 设置为 false.
代码如下:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25
| function saveImg($url) { $ch = curl_init($url); curl_setopt($ch,CURLOPT_SSL_VERIFYPEER, 0); curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0); curl_setopt($ch, CURLOPT_HEADER, 0); curl_setopt($ch, CURLOPT_NOBODY, 0); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); $package = curl_exec($ch); $httpinfo = curl_getinfo($ch);
curl_close($ch); $media = array_merge(array('mediaBody' => $package), $httpinfo);
preg_match('/\w\/(\w+)/i', $media["content_type"], $extmatches); $fileExt = $extmatches[1]; $filename = $this->com_create_guid() . $this->get_total_millisecond() . ".{$fileExt}"; $dirname = public_path() .DIRECTORY_SEPARATOR. "uploads".DIRECTORY_SEPARATOR."img".DIRECTORY_SEPARATOR; if (!file_exists($dirname)) { mkdir($dirname, 0777, true); } file_put_contents($dirname . $filename, $media['mediaBody']); return $filename; }
|