DeliverySevices.php 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  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\interfaces\DeliveryInterface;
  13. use crmeb\services\delivery\Delivery;
  14. use crmeb\services\delivery\storage\Dada;
  15. use crmeb\services\delivery\store\Uupt;
  16. /**
  17. * Class BaseExpress
  18. * @package crmeb\basic
  19. */
  20. class DeliverySevices
  21. {
  22. protected static $delivery = [];
  23. const DELIVERY_TYPE_DADA = 1;
  24. const DELIVERY_TYPE_UU = 2;
  25. /**
  26. * @param int $type
  27. * @param bool $is_cache
  28. * @return Delivery|mixed
  29. */
  30. public static function init(int $type = self::DELIVERY_TYPE_DADA, bool $is_cache = false)
  31. {
  32. $type = (int)$type;
  33. if ($is_cache && isset(self::$delivery['delivery_' . $type]) && self::$delivery['delivery_' . $type]) {
  34. return self::$delivery['delivery_' . $type];
  35. }
  36. $config = [];
  37. switch ($type) {
  38. case 1:
  39. $config = [
  40. 'app_key' => sys_config('dada_app_key'),
  41. 'app_secret' => sys_config('dada_app_sercret'),
  42. 'source_id' => sys_config('dada_source_id'),
  43. ];
  44. break;
  45. case 2:
  46. $config = [
  47. 'app_key' => sys_config('uupt_appkey'),
  48. 'app_id' => sys_config('uupt_app_id'),
  49. 'open_id' => sys_config('uupt_open_id'),
  50. ];
  51. break;
  52. }
  53. return self::$delivery['delivery_' . $type] = new Delivery($type, $config);
  54. }
  55. }