Sms.php 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. <?php
  2. /**
  3. * Created by PhpStorm.
  4. * User: xurongyao <763569752@qq.com>
  5. * Date: 2019/11/23 3:46 PM
  6. */
  7. namespace crmeb\services\sms;
  8. use crmeb\basic\BaseManager;
  9. use crmeb\services\AccessTokenServeService;
  10. use crmeb\services\sms\storage\Yunxin;
  11. use think\Container;
  12. use think\facade\Config;
  13. /**
  14. * Class Sms
  15. * @package crmeb\services\sms
  16. * @mixin Yunxin
  17. */
  18. class Sms extends BaseManager
  19. {
  20. /**
  21. * 空间名
  22. * @var string
  23. */
  24. protected $namespace = '\\crmeb\\services\\sms\\storage\\';
  25. /**
  26. * 默认驱动
  27. * @return mixed
  28. */
  29. protected function getDefaultDriver()
  30. {
  31. return Config::get('sms.default', 'sms');
  32. }
  33. /**
  34. * 获取类的实例
  35. * @param $class
  36. * @return mixed|void
  37. */
  38. protected function invokeClass($class)
  39. {
  40. if (!class_exists($class)) {
  41. throw new \RuntimeException('class not exists: ' . $class);
  42. }
  43. $this->getConfigFile();
  44. if (!$this->config) {
  45. $this->config = Config::get($this->configFile . '.stores.' . $this->name, []);
  46. }
  47. $handleAccessToken = new AccessTokenServeService($this->config['account'] ?? '', $this->config['secret'] ?? '');
  48. $handle = Container::getInstance()->invokeClass($class, [$this->name, $handleAccessToken, $this->configFile]);
  49. $this->config = [];
  50. return $handle;
  51. }
  52. }