<?php namespace app\mobile\model; use think\Model; class CourseCatalog extends Model { // 表名 protected $name = 'mobile_course_catalog'; // 开启自动写入时间戳字段 protected $autoWriteTimestamp = 'int'; // 定义时间戳字段名 protected $createTime = 'createtime'; protected $updateTime = 'updatetime'; // 获取视频解析封面和地址 public function getVideoAttr($value,$data){ if(empty($value)){ return []; } // 获取网络视频信息 if(preg_match("/^http(s)?:\\/\\/.+/",$value)){ return [ 'cover' => request()->domain().'/assets/img/bg-middle.jpg', 'video' => $value ]; } // 获取七牛云视频信息 $video = cdnurl($value,true); try { $client = new \GuzzleHttp\Client(); $client->request('GET', $video); //成功不做任何操作 } catch (\GuzzleHttp\Exception\ClientException $e) { return []; } $video_info = json_decode(file_get_contents($video.'?avinfo'),true); return [ 'cover' => $this->getCoverImagesQiniu($video,$video_info), 'video' => $video ]; } // 获取七牛云视频的封面图 public function getCoverImagesQiniu($video_url,$video_info){ if(empty($video_info['streams'][0]['width'])) { $width = $video_info['streams'][1]['width']; $height = $video_info['streams'][1]['height']; } else { $width = $video_info['streams'][0]['width']; $height = $video_info['streams'][0]['height']; } return $video_url.'?vframe/jpg/offset/1/w/'.$width.'/h/'.$height; } }