Question.php
1.4 KB
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
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
<?php
namespace app\mobile\model;
use think\Model;
class Question extends Model
{
// 表名
protected $name = 'mobile_question';
// 开启自动写入时间戳字段
protected $autoWriteTimestamp = 'int';
// 定义时间戳字段名
protected $createTime = 'createtime';
protected $updateTime = 'updatetime';
// 获取视频解析封面和地址
public function getAnalysisVideoAttr($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);
$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;
}
}