UploadService.php 2.2 KB

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