SecretService.php 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. <?php
  2. namespace App\Services;
  3. use App\Constants\StepStatus;
  4. use Illuminate\Support\Facades\Cache;
  5. use Telegram\Bot\Api;
  6. use Telegram\Bot\Exceptions\TelegramSDKException;
  7. class SecretService
  8. {
  9. /**
  10. * @param Api $telegram
  11. * @param $data
  12. * @param $chatId
  13. * @param $firstName
  14. * @param $messageId
  15. * @throws TelegramSDKException
  16. */
  17. public static function init(Api $telegram, $data, $chatId, $firstName, $messageId): void
  18. {
  19. if ($data === "secret@@index") {
  20. $res = SecretService::index($chatId, $messageId);
  21. $telegram->editMessageText($res);
  22. }
  23. //找回账号
  24. if ($data === "secret@@retrieve") {
  25. $res = SecretService::retrieve($chatId, $messageId);
  26. $telegram->editMessageText($res);
  27. }
  28. }
  29. public static function onMessage($chatId, $text, $messageId, $stepStatus): null|array
  30. {
  31. return match ($stepStatus) {
  32. StepStatus::MY_INPUT_OLD_SECRET => SecretService::inputOldSecret($chatId, $text, $messageId),
  33. };
  34. }
  35. private static function inputOldSecret($chatId, $secret, $messageId): array
  36. {
  37. $text = "";
  38. return [
  39. 'chat_id' => $chatId,
  40. 'text' => $text,
  41. ];
  42. }
  43. private static function retrieve($chatId, $messageId): array
  44. {
  45. Cache::put(get_step_key($chatId), StepStatus::MY_INPUT_OLD_SECRET);
  46. return [
  47. 'chat_id' => $chatId,
  48. 'text' => '请输入原账号的秘钥',
  49. 'message_id' => $messageId,
  50. ];
  51. }
  52. private static function index($chatId, $messageId): array
  53. {
  54. $keyboard = [
  55. [
  56. ['text' => '查看秘钥', 'callback_data' => 'secret@@view'],
  57. ['text' => '找回账号', 'callback_data' => 'secret@@retrieve'],
  58. ],
  59. [
  60. ['text' => '返回', 'callback_data' => 'topUp@@home'],
  61. ]
  62. ];
  63. $text = "秘钥管理\n";
  64. $text .= "请选择业务类型";
  65. return [
  66. 'chat_id' => $chatId,
  67. 'text' => $text,
  68. 'message_id' => $messageId,
  69. 'reply_markup' => json_encode(['inline_keyboard' => $keyboard])
  70. ];
  71. }
  72. }