💎一站式轻松地调用各大LLM模型接口,支持GPT4、智谱、豆包、星火、月之暗面及文生图、文生视频 广告
#### 应用场景 例如 `手机短信服务` 我们经常在很多地方需要调用这个模块,我们应该怎么做才好呢?推荐将该模块提升为系统级别的服务: > 1 在AppServiceProvider.php的文件底部,添加以下代码: ~~~ /** * 短信服务 */ private function registerSMS() { $this->app->singleton('sms', function($app) { $config = config('sms'); $accountsid = array_get($config, 'account_sid'); $token = array_get($config, 'token'); return new SMS(compact('accountsid', 'token'), array_get($config, 'app_id')); }); } ~~~ > 2 在AppServiceProvider.php的register()函数中,添加以下代码: ~~~ public function register() { ... $this->registerSMS(); ... } ~~~ > 3 创建 app/Services/SMS.php ~~~ <?php namespace App\Services; class SMS { public function send() { return ...; } } ~~~ 使用方式: ~~~ app('sms')->send(); ~~~