UploadService.php 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. <?php
  2. namespace ln\services;
  3. use ln\services\upload\Upload;
  4. /**
  5. * Class UploadService
  6. * @package ln\services
  7. */
  8. class UploadService
  9. {
  10. /**
  11. * @param $type
  12. * @return Upload
  13. */
  14. public static function create($type = null)
  15. {
  16. if (is_null($type)) {
  17. $type = (int)systemConfig('upload_type') ?: 1;
  18. }
  19. $type = (int)$type;
  20. $config = [];
  21. switch ($type) {
  22. case 2://七牛
  23. $data = systemConfig(['qiniu_accessKey', 'qiniu_secretKey', 'qiniu_uploadUrl', 'qiniu_storage_name', 'qiniu_storage_region']);
  24. $config = [
  25. 'accessKey' => $data['qiniu_accessKey'],
  26. 'secretKey' => $data['qiniu_secretKey'],
  27. 'uploadUrl' => $data['qiniu_uploadUrl'],
  28. 'storageName' => $data['qiniu_storage_name'],
  29. 'storageRegion' => $data['qiniu_storage_region'],
  30. ];
  31. break;
  32. case 3:// oss 阿里云
  33. $data = systemConfig(['accessKey', 'secretKey', 'uploadUrl', 'storage_name', 'storage_region']);
  34. $config = [
  35. 'accessKey' => $data['accessKey'],
  36. 'secretKey' => $data['secretKey'],
  37. 'uploadUrl' => $data['uploadUrl'],
  38. 'storageName' => $data['storage_name'],
  39. 'storageRegion' => $data['storage_region'],
  40. ];
  41. break;
  42. case 4:// cos 腾讯云
  43. $data = systemConfig(['tengxun_accessKey', 'tengxun_secretKey', 'tengxun_uploadUrl', 'tengxun_storage_name', 'tengxun_storage_region']);
  44. $config = [
  45. 'accessKey' => $data['tengxun_accessKey'],
  46. 'secretKey' => $data['tengxun_secretKey'],
  47. 'uploadUrl' => $data['tengxun_uploadUrl'],
  48. 'storageName' => $data['tengxun_storage_name'],
  49. 'storageRegion' => $data['tengxun_storage_region'],
  50. ];
  51. break;
  52. }
  53. return new Upload($type, $config);
  54. }
  55. }