Sms.php 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  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\sms;
  12. use crmeb\basic\BaseManager;
  13. use crmeb\services\AccessTokenServeService;
  14. use crmeb\services\sms\storage\Yunxin;
  15. use think\Container;
  16. use think\facade\Config;
  17. /**
  18. * Class Sms1
  19. * @package crmeb\services\sms
  20. * @mixin Yunxin
  21. */
  22. class Sms extends BaseManager
  23. {
  24. /**
  25. * 空间名
  26. * @var string
  27. */
  28. protected $namespace = '\\crmeb\\services\\sms\\storage\\';
  29. /**
  30. * 默认驱动
  31. * @return mixed
  32. */
  33. protected function getDefaultDriver()
  34. {
  35. return Config::get('sms.default', 'yunxin');
  36. }
  37. /**
  38. * 获取类的实例
  39. * @param $class
  40. * @return mixed|void
  41. */
  42. protected function invokeClass($class)
  43. {
  44. if (!class_exists($class)) {
  45. throw new \RuntimeException('class not exists: ' . $class);
  46. }
  47. $this->getConfigFile();
  48. if (!$this->config) {
  49. $this->config = Config::get($this->configFile . '.stores.' . $this->name, []);
  50. }
  51. $handleAccessToken = new AccessTokenServeService($this->config['account'] ?? '', $this->config['secret'] ?? '');
  52. $handle = Container::getInstance()->invokeClass($class, [$this->name, $handleAccessToken, $this->configFile]);
  53. $this->config = [];
  54. return $handle;
  55. }
  56. }