webhook = $webhook; return $this; } protected function getDefaultDriver() { return Config::get('bot.default', 'dingTalk'); } protected function invokeClass($class) { if (!class_exists($class)) { throw new \RuntimeException('class not exists: ' . $class); } $this->getConfigFile(); $handle = Container::getInstance()->invokeClass($class); if ($this->webhook) { $handle->setWebhook($this->webhook); } return $handle; } protected function resolveClass(string $type): string { $studly = Str::studly($type); $class = $this->namespace . $studly . '\\Driver'; if (class_exists($class)) { return $class; } $class = $this->namespace . $studly; if (class_exists($class)) { return $class; } throw new \InvalidArgumentException("Bot driver [{$type}] not supported."); } public static function sendText(string $driver, string $webhook, string $content): bool { $instance = new static($driver); $instance->setWebhook($webhook); return $instance->sendText($content); } public static function sendMarkdown(string $driver, string $webhook, string $title, string $content): bool { $instance = new static($driver); $instance->setWebhook($webhook); return $instance->sendMarkdown($title, $content); } public static function sendCard(string $driver, string $webhook, array $card): bool { $instance = new static($driver); $instance->setWebhook($webhook); return $instance->sendCard($card); } public static function send(string $driver, string $webhook, string $content, string $type = 'text', string $title = ''): bool { $instance = new static($driver); $instance->setWebhook($webhook); return match ($type) { 'markdown' => $instance->sendMarkdown($title ?: '通知', $content), 'card' => $instance->sendCard(['content' => $content]), default => $instance->sendText($content), }; } }