sBotCode = $sBotCode; $oInstance->sChatCode = $sChatCode; return $oInstance; } public function setBotCode(string $sBotCode): self { $this->sBotCode = $sBotCode; return $this; } public function setChatCode(string $sChatCode): self { $this->sChatCode = $sChatCode; return $this; } public function setBotToken(string $sBotToken): self { $this->sBotToken = $sBotToken; return $this; } public function setChatId(int $iChatId): self { $this->iChatId = $iChatId; return $this; } public function setMsgS(string $sMsg): self { $this->sMsg = $sMsg; return $this; } public function send($sMsg = ''): Flow { if ($sMsg) { $this->sMsg = $sMsg; } if (!$this->sMsg) { throw new \Exception("未设置msg"); } $this->keyBegin(); if ($this->enableQueue) { $aData = $this->buildDataTom(); $oFlow = ServiceHttpQueue::start("telegram_local")->arg($aData)->save(); } else { $oFlow = ServiceTelegramSdk::start() ->setBotToken($this->sBotToken) ->setChatId($this->iChatId) ->setMsgS($this->sMsg) ->send(); } return $oFlow; } private function keyBegin() { if (!$this->bKeyBegin) { if (!$this->sBotToken) { $this->sBotToken = ModelTelegramKey::botTokenByCode($this->sBotCode); } if (!$this->iChatId) { $this->iChatId = ModelTelegramKey::chatIdByCode($this->sChatCode); } if (!$this->sBotToken || !$this->iChatId) { throw new \RuntimeException("botToken或chatId没找到,botCode={$this->sBotCode},chatCode={$this->sChatCode}"); } $this->bKeyBegin = true; } } private function buildDataTom(): array { return [ "sBotCode" => $this->sBotCode ?? '', "sChatCode" => $this->sChatCode ?? '', "sBotToken" => $this->sBotToken ?? '', "iChatId" => $this->iChatId ?? '', "sMsg" => $this->sMsg ?? '', ]; } }