request->all(); if ($params['file_path']) { $info = finfo_open(FILEINFO_MIME_TYPE); $type = finfo_file($info, $params['file_path']); if (!in_array($type, ['video/mp4','image/png','image/jpg','image/jpeg','image/gif']) || !$params['dir']) { return response('文件类型错误'.$type.'或目录不存在', 400); } finfo_close($info); $data['file_name'] = $params['file_name']; $data['file_size'] = $params['file_size']; if ($type != 'video/mp4') { $data['file_path'] = make(SiteService::class) ->encryptImage($params['file_path'], $params['dir']); } else { $data['file_path'] = make(SiteService::class) ->moveVideo($params['file_path'], $params['dir']); } $res = [ 'result' => $data, 'code' => 0, 'message' => '上传成功' ]; return response()->json($res); } else { return response()->json('fail', 400); } } public function auth() { $params = $this->request->all(); if ($params['platform'] == 'I') { $secret = 'pb5pe0MXChXsic0N'; } if ($params['platform'] == 'A') { $secret = '4rKFwocMESIp4Anf'; } if ($params['platform'] == 'P') { $secret = 'Z6Kbz8hpT9VtGmcu'; } if (!$params['platform'] || !$params['timestamp'] || !$params['sign'] || !isset($secret)) { logger('sign:参数缺失', $params); return response('参数缺失', 403); } if (abs(time() - $params['timestamp']) > 3600) { logger('sign:时间验签失败' . time(), $params); return response('时间验签失败', 403); } $sign = strtoupper(md5($params['platform'] . $params['timestamp'] . $secret)); if ($sign != $params['sign']) { logger('sign:时间验签失败' . $sign, $params); return response('签名验签失败', 403); } return json_success('ok'); } public function move() { $params = $this->request->all(); logger('开始移动文件:', $params); if (!isset($params['filepath']) || !isset($params['pathname'])) { logger('move', ['filepath/pathname不能为空']); return false; } if (!in_array($params['pathname'], ['vu','va','vd'])) { logger('move', ['mp4下载二级目录地址错误']); return false; } $path = '/var/www/resource/wp/mp/' . $params['pathname'] . '/' . date('mdH', time()); $newname = $path . '/' . md5(microtime()) . mt_rand(1000, 9999) . '.mp4'; make(SiteService::class)->mkDirs($path); if (rename($params['filepath'], $newname)) { logger('rename', [$newname . '->文件移动成功!']); return true; } else { logger('rename', ['文件移动失败']); return false; } } public function shift() { $params = $this->request->all(); if (!$params['path'] || !$params['table'] || !$params['id'] || !$params['update']) { return json_fail('error'); } $result = make(SiteService::class) ->videoShift($params['path'], $params['table'], $params['id'], $params['update']); return json_success($result); } public function pushCrashLog( ValidatorFactoryInterface $validatorFactory ) { $inputData = $this->getJsonData(); // Demo 这是在控制器内校验器的写法. $rules = [ 'ua' => 'required', 'user_id' => 'nullable', 'message' => 'required', 'version' => 'required', 'device_no' => 'required', 'device_type' => 'required|in:A,I,H', ]; $validator = $validatorFactory->make($inputData, $rules); if ($validator->fails()) { // 如果有错误(可能是多个信息),这里只取第一个错误信息返回. return json_fail($validator->errors()->first()); } $result = make(QueueService::class)->crashLogPush( [ 'ua' => $inputData['ua'], 'user_id' => $inputData['user_id'] ?? '', 'message' => $inputData['message'], 'version' => $inputData['version'], 'device_no' => $inputData['device_no'], 'device_type' => $inputData['device_type'] ] ); return json_success($result); } public function getVersion( Request $request, ValidatorFactoryInterface $validatorFactory ) { $inputData = $request->all(); // Demo 这是在控制器内校验器的写法. $rules = [ 'device_type' => 'required|in:A,I,H', 'version_code' => 'nullable|string', ]; $validator = $validatorFactory->make($inputData, $rules); if ($validator->fails()) { // 如果有错误(可能是多个信息),这里只取第一个错误信息返回. return json_fail($validator->errors()->first()); } $hVersionCode = data_get($inputData, 'version_code', ''); $cacheKey = 'version:' . $inputData['device_type']; if (!empty($hVersionCode)) { $arrTmp = explode('.', $hVersionCode); if (count($arrTmp) != 3) { return json_fail('版本错误'); } if (intval($arrTmp[0]) > 99 || intval($arrTmp[1]) > 99 || intval($arrTmp[2]) > 99) { return json_fail('版本溢出错误'); } $cacheKey .= ':v'. $hVersionCode; } $result = make(CacheInterface::class)->remember( $cacheKey, 60 * 60, function () use ($inputData, $hVersionCode) { $conditions = [ 'status' => 1, 'device_type' => $inputData['device_type'], 'version_type' => 'free' ]; if (!empty($hVersionCode)) { $conditions['version_code'] = $hVersionCode; } $item = VersionModel::query()->where($conditions)->orderByDesc('version_code')->first(); if (!empty($item)) { $item = $item->toArray(); $item['app_url'] = make(ConfigRepoistory::class) ->get('share_url', 'sys'); $conditions = [ 'status' => 1, 'device_type' => $inputData['device_type'], 'version_type' => 'merge', 'version_code' => $item['version_code'], ]; $item2 = VersionModel::query()->where($conditions)->orderByDesc('version_code')->first(); $item['merge_path'] = ''; // 分割下载url if (!empty($item2)) { $item['merge_path'] = $item2['package_path']; } return $item; } else { return null; } } ); $res = [ 'code' => 200, 'message' => '', 'data' => $result, 'handshake' => '', ]; return response()->json($res); } /** * 提供给H5-获取最新版本下载地址 */ public function getVersionH5(Request $request, ValidatorFactoryInterface $validatorFactory) { $android_info = VersionModel::query() ->where( [ 'status' => 1, 'device_type' => 'A', 'version_type' => 'free', ] ) ->orderByDesc('version_code') ->first(); $ios_free_info = VersionModel::query() ->where( [ 'status' => 1, 'device_type' => 'I', 'version_type' => 'free', ] ) ->orderByDesc('version_code') ->first(); $ios_shop_info = VersionModel::query() ->where( [ 'status' => 1, 'device_type' => 'I', 'version_type' => 'shop', ] ) ->orderByDesc('version_code') ->first(); $ios_testflight_info = VersionModel::query() ->where( [ 'status' => 1, 'device_type' => 'I', 'version_type' => 'testflight', ] ) ->orderByDesc('version_code') ->first(); $ios_enterprise_info = VersionModel::query() ->where( [ 'status' => 1, 'device_type' => 'I', 'version_type' => 'enterprise', ] ) ->orderByDesc('version_code') ->first(); $ios_super_info = VersionModel::query() ->where( [ 'status' => 1, 'device_type' => 'I', 'version_type' => 'super', ] ) ->orderByDesc('version_code') ->first(); $ios_ipa_info = VersionModel::query() ->where( [ 'status' => 1, 'device_type' => 'I', 'version_type' => 'ipa', ] ) ->orderByDesc('version_code') ->first(); $ios_ipa_gbox = VersionModel::query() ->where( [ 'status' => 1, 'device_type' => 'I', 'version_type' => 'gbox', ] ) ->orderByDesc('version_code') ->first(); $androidMergeInfo = VersionModel::query() ->where( [ 'status' => 1, 'device_type' => 'A', 'version_type' => 'merge', ] ) ->orderByDesc('version_code') ->first(); $potato_info = ConfigModel::query() ->where('skey', 'potoato_url') ->first(); $data = [ 'url_android' => $android_info ? $android_info->package_path : '', 'url_android_merge' => $androidMergeInfo ? $androidMergeInfo->package_path : '', 'url_ios_free' => $ios_free_info ? $ios_free_info->package_path : '', 'url_ios_shop' => $ios_shop_info ? $ios_shop_info->package_path : '', 'url_ios_testflight' => $ios_testflight_info ? $ios_testflight_info->package_path : '', 'url_ios_super' => $ios_super_info ? $ios_super_info->package_path : '', 'url_ios_enterprise' => $ios_enterprise_info ? $ios_enterprise_info->package_path : '', 'url_ios_ipa' => $ios_ipa_info ? $ios_ipa_info->package_path : '', 'url_ios_gbox' => $ios_ipa_gbox ? $ios_ipa_gbox->package_path : '', 'url_potato' => $potato_info ? $potato_info->svalue : '', ]; $res = [ 'code' => 200, 'message' => '', 'data' => $data, 'handshake' => '', ]; return response()->json($res); } public function test123() { $filePath = base_path('storage/cache/m3u8_url/ff19/3e65/ff193e657aeaeb971d072becae6061df.url'); if (file_exists($filePath)) { $mtime = filemtime($filePath); $phpDate = date('Y-m-d H:i:s', $mtime); $diffSeconds = Carbon::now()->diffInSeconds(Carbon::parse($mtime)); $expiredSeconds = 2 * 60 * 60; // 原始文件保存2小时. $diffSeconds2 = abs($diffSeconds); $isExpired = $diffSeconds > $expiredSeconds; var_dump($mtime, $phpDate, $diffSeconds, $expiredSeconds, $diffSeconds2, $isExpired); } return json_success(['a1' => 'ok']); } }