UploadService.php 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  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. * @var array
  17. */
  18. protected static $upload = [];
  19. /**
  20. * @param $type
  21. * @return Upload
  22. */
  23. public static function init($type = null, $mer_id = '')
  24. {
  25. if (is_null($type)) {
  26. $type = (int)sys_config('upload_type', 1, $mer_id);
  27. }
  28. if (isset(self::$upload['upload_' . $type])) {
  29. return self::$upload['upload_' . $type];
  30. }
  31. $type = (int)$type;
  32. $config = [];
  33. switch ($type) {
  34. case 2://七牛
  35. $config = [
  36. 'accessKey' => sys_config('qiniu_accessKey', '', $mer_id),
  37. 'secretKey' => sys_config('qiniu_secretKey', '', $mer_id),
  38. 'uploadUrl' => sys_config('qiniu_uploadUrl', '', $mer_id),
  39. 'storageName' => sys_config('qiniu_storage_name', '', $mer_id),
  40. 'storageRegion' => sys_config('qiniu_storage_region', '', $mer_id),
  41. ];
  42. break;
  43. case 3:// oss 阿里云
  44. $config = [
  45. 'accessKey' => sys_config('accessKey', '', $mer_id),
  46. 'secretKey' => sys_config('secretKey', '', $mer_id),
  47. 'uploadUrl' => sys_config('uploadUrl', '', $mer_id),
  48. 'storageName' => sys_config('storage_name', '', $mer_id),
  49. 'storageRegion' => sys_config('storage_region', '', $mer_id),
  50. ];
  51. break;
  52. case 4:// cos 腾讯云
  53. $config = [
  54. 'accessKey' => sys_config('tengxun_accessKey', '', $mer_id),
  55. 'secretKey' => sys_config('tengxun_secretKey', '', $mer_id),
  56. 'uploadUrl' => sys_config('tengxun_uploadUrl', '', $mer_id),
  57. 'storageName' => sys_config('tengxun_storage_name', '', $mer_id),
  58. 'storageRegion' => sys_config('tengxun_storage_region', '', $mer_id),
  59. ];
  60. break;
  61. }
  62. return self::$upload['upload_' . $type] = new Upload($type, $config);
  63. }
  64. }