Explorar el Código

宁煤首帧图片

任敬轩 hace 2 años
padre
commit
b2157218a1

+ 27 - 1
Modules/Camera/Http/Controllers/Api/HaiKangController.php

@@ -708,12 +708,38 @@ class HaiKangController extends BaseController
         $cover_picture = CameraList::where('id', Input::get('camera_id'))->value('cover_picture');
 
         if (!$cover_picture) {
-            register_shutdown_function(array($this, "getFirstPicture"),$path,$ffmpeg_rtmp);
+//            register_shutdown_function(array($this, "getFirstPicture"),$path,$ffmpeg_rtmp);
+            $this->getPictureByHk($query);
         }
 
         return $result;
     }
 
+    //宁煤通过海康接口获取首桢图片
+    public function getPictureByHk($query){
+        $url = $this->artemis.'/apiideo1/manualCapture';
+        $params['cameraIndexCode'] = $query->index_code;
+        $this->sign = $this->get_sign($url);
+        $picture = $this->curlPost($this->pre_url . $url, json_encode($params));
+        $picture = json_decode($picture, true);
+        if($picture['data']['picUrl']){
+            if (!is_dir('/www/wwwrootideo.nxjiewei.com/public/' . CameraEnum::M3U8_FILE_PATH.'/img/'  )) {
+                mkdir('/www/wwwrootideo.nxjiewei.com/public/' . CameraEnum::M3U8_FILE_PATH.'/img/', 0777, true);
+            }
+            $path = '/www/wwwrootideo.nxjiewei.com/public/' . CameraEnum::M3U8_FILE_PATH.'/img/';
+            $cms = new CameraServices();
+            $file_name = $cms->downloadFile($picture['data']['picUrl'],$path);
+            //判断图片是否存在
+            $picture_exists = file_exists($path  . '/' . $file_name);
+            if ($picture_exists) {
+                //上传图片到oss并更新数据库
+                $picture_path = $cms->uploadOssFile($file_name, $path);
+                CameraList::where('id',$query->id)->update(['cover_picture' => $picture_path]);
+            }
+        }
+
+    }
+
     //宁煤集团获取rtsp流后获取首帧图片
     public function getFirstPicture($path,$ffmpeg_rtsp){
         if (!is_dir('/www/wwwroot/video.nxjiewei.com/public/' . CameraEnum::M3U8_FILE_PATH . '/' . $path)) {

+ 22 - 0
Modules/Camera/Services/CameraServices.php

@@ -2241,6 +2241,28 @@ class CameraServices
         return $fileName;
     }
 
+    //海康抓图接口图片下载到本地
+    public function downloadFile($file_path, $local_path){
+        $rename = rand(0000,9999).'.png';
+        set_time_limit(0);
+        $ch = curl_init($file_path);
+        curl_setopt($ch, CURLOPT_USERAGENT,'Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.17 (KHTML, like Gecko) Chrome/24.0.1312.52 Safari/537.17');
+        curl_setopt($ch, CURLOPT_AUTOREFERER, true);
+        curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
+        curl_setopt($ch, CURLOPT_VERBOSE, 1);
+        curl_setopt($ch, CURLOPT_HEADER, 0);
+        curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
+        curl_setopt($ch, CURLOPT_BINARYTRANSFER,1);
+        curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE); //表示不检查证书
+        curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE); //信任任何证书
+        $rawdata = curl_exec ($ch);
+        curl_close ($ch);
+        $fp = fopen($local_path . $rename, 'w');
+        fwrite($fp, $rawdata);
+        fclose($fp);
+        return $rename;
+    }
+
     //oss上传文件
     public static function uploadOssFile($file_name, $file_path)
     {