public function send($to, $message) { $result = null; $message = Config::get('sms.prefix') . $message . Config::get('sms.suffix'); if (false == SenderFactory::validate($to)) { throwException(new InvalidMobileNumberException("非法的手机号码:{$to}")); } else { $result = $this->doSend($to, $message); $this->log->info("发送短信", array('to' => $to, 'message' => $message, 'result' => $result)); } return $result; }
public function register() { $this->app->singleton(['sms.sender' => SenderContract::class], function ($app) { $config = $app['config']['sms']; if (!$config || !is_array($config) || !array_key_exists('sender', $config)) { throw new Exception("SMS服务未进行配置"); } $sender = $config['sender']; return SenderFactory::make($sender, $config, $app['httpClient'], $app['cache.store'], $app['log']); }); $this->publishes(array(__DIR__ . '/config/' => config_path(''))); }