Video.php 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. <?php
  2. /**
  3. * Created by PhpStorm.
  4. * User: wuhaotian
  5. * Date: 2020-02-24
  6. * Time: 17:57
  7. */
  8. namespace app\admin\controller\widget;
  9. use app\admin\controller\AuthController;
  10. use crmeb\services\JsonService;
  11. use crmeb\services\upload\Upload;
  12. use think\facade\Config;
  13. class Video extends AuthController
  14. {
  15. /**
  16. * 上传类型
  17. * @var int
  18. */
  19. protected $uploadInfo;
  20. /**
  21. * 获取配置信息
  22. * Video constructor.
  23. */
  24. public function initialize()
  25. {
  26. parent::initialize();
  27. $this->uploadInfo['accessKey'] = sys_config('accessKey');
  28. $this->uploadInfo['secretKey'] = sys_config('secretKey');
  29. $this->uploadInfo['uploadUrl'] = sys_config('uploadUrl');
  30. $this->uploadInfo['storageName'] = sys_config('storage_name');
  31. $this->uploadInfo['storageRegion'] = sys_config('storage_region');
  32. $this->uploadInfo['uploadType'] = sys_config('upload_type');
  33. }
  34. /**
  35. * 获取密钥签名
  36. */
  37. public function get_signature()
  38. {
  39. if ($this->uploadInfo['uploadType'] == 1) {
  40. if (!$this->uploadInfo['accessKey'] || !$this->uploadInfo['secretKey']) {
  41. return JsonService::fail('视频上传需要上传到云端,默认使用阿里云OSS上传请配置!');
  42. } else {
  43. $this->uploadInfo['uploadType'] = 3;
  44. }
  45. }
  46. if ($this->uploadInfo['uploadType'] == 2) {
  47. $upload = new Upload('Qiniu', $this->uploadInfo);
  48. $res = $upload->getSystem();
  49. $this->uploadInfo['uploadToken'] = $res['token'];
  50. $this->uploadInfo['domain'] = $res['domain'];
  51. $this->uploadInfo['uploadType'] = 'QINIU';
  52. } elseif ($this->uploadInfo['uploadType'] == 3) {
  53. $this->uploadInfo['uploadType'] = 'OSS';
  54. if (($leng = strpos($this->uploadInfo['storageRegion'], 'aliyuncs.com')) !== false) {
  55. $this->uploadInfo['storageRegion'] = substr($this->uploadInfo['storageRegion'], 0, $leng - 1);
  56. }
  57. } elseif ($this->uploadInfo['uploadType'] == 4) {
  58. $this->uploadInfo['uploadType'] = 'COS';
  59. }
  60. return JsonService::successful($this->uploadInfo);
  61. }
  62. public function index($fodder = '')
  63. {
  64. $this->assign(compact('fodder'));
  65. return $this->fetch();
  66. }
  67. }