UploadService.php 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
  4. // +----------------------------------------------------------------------
  5. // | Copyright (c) 2016~2020 https://www.crmeb.com All rights reserved.
  6. // +----------------------------------------------------------------------
  7. // | Licensed CRMEB并不是自由软件,未经许可不能去掉CRMEB相关版权
  8. // +----------------------------------------------------------------------
  9. // | Author: CRMEB Team <admin@crmeb.com>
  10. // +----------------------------------------------------------------------
  11. namespace crmeb\services;
  12. use crmeb\services\upload\Upload;
  13. /**
  14. * Class UploadService
  15. * @package crmeb\services
  16. */
  17. class UploadService
  18. {
  19. /**
  20. * @param $type
  21. * @return Upload
  22. */
  23. public static function create($type = null)
  24. {
  25. if (is_null($type)) {
  26. $type = (int)systemConfig('upload_type') ?: 1;
  27. }
  28. $type = (int)$type;
  29. $config = [];
  30. switch ($type) {
  31. case 2://七牛
  32. $data = systemConfig(['qiniu_accessKey', 'qiniu_secretKey', 'qiniu_uploadUrl', 'qiniu_storage_name', 'qiniu_storage_region']);
  33. $config = [
  34. 'accessKey' => $data['qiniu_accessKey'],
  35. 'secretKey' => $data['qiniu_secretKey'],
  36. 'uploadUrl' => $data['qiniu_uploadUrl'],
  37. 'storageName' => $data['qiniu_storage_name'],
  38. 'storageRegion' => $data['qiniu_storage_region'],
  39. ];
  40. break;
  41. case 3:// oss 阿里云
  42. $data = systemConfig(['accessKey', 'secretKey', 'uploadUrl', 'storage_name', 'storage_region']);
  43. $config = [
  44. 'accessKey' => $data['accessKey'],
  45. 'secretKey' => $data['secretKey'],
  46. 'uploadUrl' => $data['uploadUrl'],
  47. 'storageName' => $data['storage_name'],
  48. 'storageRegion' => $data['storage_region'],
  49. ];
  50. break;
  51. case 4:// cos 腾讯云
  52. $data = systemConfig(['tengxun_accessKey', 'tengxun_secretKey', 'tengxun_uploadUrl', 'tengxun_storage_name', 'tengxun_storage_region']);
  53. $config = [
  54. 'accessKey' => $data['tengxun_accessKey'],
  55. 'secretKey' => $data['tengxun_secretKey'],
  56. 'uploadUrl' => $data['tengxun_uploadUrl'],
  57. 'storageName' => $data['tengxun_storage_name'],
  58. 'storageRegion' => $data['tengxun_storage_region'],
  59. ];
  60. break;
  61. }
  62. return new Upload($type, $config);
  63. }
  64. }