Sms.php 1.3 KB

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