Pārlūkot izejas kodu

保存微信图片到本地

huwhois 3 gadi atpakaļ
vecāks
revīzija
465ae159c6
1 mainītis faili ar 21 papildinājumiem un 2 dzēšanām
  1. 21 2
      app/common/service/FileService.php

+ 21 - 2
app/common/service/FileService.php

@@ -47,15 +47,19 @@ class FileService
         $ch = curl_init($url);
         curl_setopt($ch, CURLOPT_HEADER, 0);
         curl_setopt($ch, CURLOPT_NOBODY, 0); // 只取body头
+        curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
+        curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE);
+        curl_setopt($ch, CURLOPT_NOSIGNAL, 1);
         curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
+ 
         $package = curl_exec($ch);
         $httpinfo = curl_getinfo($ch);
-
+        
         curl_close($ch);
+
         $imageAll = array_merge(array(
             'imgBody' => $package
         ), $httpinfo);
-
         if ($httpinfo['download_content_length'] > 4 * 1024 * 1024) {
             throw new Exception("文件太大", 1);
         }
@@ -80,6 +84,21 @@ class FileService
                 break;
         }
 
+        // 腾讯公众号图片
+        if(strpos($url,'qpic.cn') !== false){
+            $urls = parse_url($url);
+        
+            if (isset($urls['query'])) {
+                $query_arr = [];
+                
+                parse_str($urls['query'], $query_arr);
+        
+                $type = isset($query_arr['wx_fmt']) ? $query_arr['wx_fmt'] : null;
+        
+                $type = $type == 'jpeg' ? 'jpg' : $type;
+            }
+        }
+
         if (!$type) {
             throw new Exception("不支持的文件后缀", 1);
         }