| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788 |
- <?php
- namespace App\Services;
- use App\Constants\StepStatus;
- use Illuminate\Support\Facades\Cache;
- use Telegram\Bot\Api;
- use Telegram\Bot\Exceptions\TelegramSDKException;
- class SecretService
- {
- /**
- * @param Api $telegram
- * @param $data
- * @param $chatId
- * @param $firstName
- * @param $messageId
- * @throws TelegramSDKException
- */
- public static function init(Api $telegram, $data, $chatId, $firstName, $messageId): void
- {
- if ($data === "secret@@index") {
- $res = SecretService::index($chatId, $messageId);
- $telegram->editMessageText($res);
- }
- //找回账号
- if ($data === "secret@@retrieve") {
- $res = SecretService::retrieve($chatId, $messageId);
- $telegram->editMessageText($res);
- }
- }
- public static function onMessage($chatId, $text, $messageId, $stepStatus): null|array
- {
- return match ($stepStatus) {
- StepStatus::MY_INPUT_OLD_SECRET => SecretService::inputOldSecret($chatId, $text, $messageId),
- };
- }
- private static function inputOldSecret($chatId, $secret, $messageId): array
- {
- $text = "";
- return [
- 'chat_id' => $chatId,
- 'text' => $text,
- ];
- }
- private static function retrieve($chatId, $messageId): array
- {
- Cache::put(get_step_key($chatId), StepStatus::MY_INPUT_OLD_SECRET);
- return [
- 'chat_id' => $chatId,
- 'text' => '请输入原账号的秘钥',
- 'message_id' => $messageId,
- ];
- }
- private static function index($chatId, $messageId): array
- {
- $keyboard = [
- [
- ['text' => '查看秘钥', 'callback_data' => 'secret@@view'],
- ['text' => '找回账号', 'callback_data' => 'secret@@retrieve'],
- ],
- [
- ['text' => '返回', 'callback_data' => 'topUp@@home'],
- ]
- ];
- $text = "秘钥管理\n";
- $text .= "请选择业务类型";
- return [
- 'chat_id' => $chatId,
- 'text' => $text,
- 'message_id' => $messageId,
- 'reply_markup' => json_encode(['inline_keyboard' => $keyboard])
- ];
- }
- }
|