|
|
@@ -61,20 +61,11 @@ class TelegramWebHook extends BaseController
|
|
|
// Log::error('Telegram 回调数据(JSON): ' . json_encode($update, JSON_UNESCAPED_UNICODE));
|
|
|
DB::beginTransaction();
|
|
|
try {
|
|
|
- $chatId = $message->chat->id;
|
|
|
- $firstName = $message->chat->firstName;
|
|
|
- $username = '';
|
|
|
$messageId = $message->messageId;
|
|
|
- if (!$from->isBot) {
|
|
|
- $chatId = $from->id;
|
|
|
- $firstName = $from->firstName;
|
|
|
- $username = $from->username;
|
|
|
- }
|
|
|
-
|
|
|
+ list($chatId, $firstName, $username) = PublicService::getChatInfo($message, $from);
|
|
|
//用户注册和初始化用户钱包
|
|
|
$user = PublicService::index($chatId, $username, $firstName);
|
|
|
App::setLocale($user->language);
|
|
|
-
|
|
|
PublicService::init($telegram, $data, $chatId, $firstName, $messageId);
|
|
|
WalletService::init($telegram, $data, $chatId, $firstName, $messageId, $callbackId);
|
|
|
TopUpService::init($telegram, $data, $chatId, $firstName, $messageId);
|
|
|
@@ -86,8 +77,6 @@ class TelegramWebHook extends BaseController
|
|
|
BetService::init($telegram, $data, $chatId, $firstName, $messageId, $callbackId);
|
|
|
BalanceLogService::init($telegram, $data, $chatId, $firstName, $messageId, $callbackId);
|
|
|
IssueService::init($telegram, $data, $chatId, $firstName, $messageId);
|
|
|
-
|
|
|
-
|
|
|
DB::commit();
|
|
|
} //
|
|
|
catch (MessageException $e) {
|
|
|
@@ -204,7 +193,7 @@ class TelegramWebHook extends BaseController
|
|
|
*/
|
|
|
public function processChatMessage($chatId, $messageId, $message, $from)
|
|
|
{
|
|
|
- $returnMsg = [];
|
|
|
+
|
|
|
//用户发送图片,结算截图
|
|
|
if (isset($message['photo'])) {
|
|
|
$stepStatus = Cache::get(get_step_key($chatId), -1);
|
|
|
@@ -225,64 +214,44 @@ class TelegramWebHook extends BaseController
|
|
|
} //用户发送了消息
|
|
|
else if (isset($message['text'])) {
|
|
|
$text = $message['text'];
|
|
|
- $user = PublicSerVICE::index($chatId, $message['chat']['username'], $message['chat']['first_name']);
|
|
|
+ $user = PublicService::index($chatId, $message['chat']['username'], $message['chat']['first_name']);
|
|
|
App::setLocale($user->language);
|
|
|
if ($message['chat']['type'] === 'private') {
|
|
|
// 校验开始菜单事件
|
|
|
$returnMsg = KeyboardService::checkStart($chatId, $text);
|
|
|
- if ($returnMsg) {
|
|
|
- return $returnMsg;
|
|
|
- }
|
|
|
+ if ($returnMsg) return $returnMsg;
|
|
|
switch ($text) {
|
|
|
case "/start":
|
|
|
Util::delCache($chatId);
|
|
|
- //给每个用户生成一个专属的USDT钱包
|
|
|
- WalletService::getUserWallet($chatId);
|
|
|
self::setReplyKeyboard($chatId, $user->language);
|
|
|
break;
|
|
|
default:
|
|
|
- // 关键字回复
|
|
|
- $keyboardText = KeyboardService::findOne(['button' => $text]);
|
|
|
- if ($keyboardText) {
|
|
|
- $keyboard = [];
|
|
|
- if ($keyboardText['buttons']) {
|
|
|
- $keyboard = json_decode($keyboardText['buttons'], true);
|
|
|
- }
|
|
|
- Util::delCache($chatId);
|
|
|
- $res = [
|
|
|
- 'chat_id' => $chatId,
|
|
|
- 'text' => $keyboardText['reply'],
|
|
|
- // 'reply_to_message_id' => $messageId
|
|
|
- ];
|
|
|
- if ($keyboard) {
|
|
|
- $res['reply_markup'] = json_encode(['inline_keyboard' => $keyboard]);
|
|
|
- }
|
|
|
- if ($keyboardText['image']) {
|
|
|
- $res['photo'] = InputFile::create(url($keyboardText['image']));
|
|
|
- unset($res['text']);
|
|
|
- $res['caption'] = $text;
|
|
|
- $res['protect_content'] = true; // 防止转发
|
|
|
- }
|
|
|
- return $res;
|
|
|
- }
|
|
|
- $stepStatus = Cache::get(get_step_key($chatId), -1);
|
|
|
- $stepStatus = intval($stepStatus);
|
|
|
+ //关键字回复
|
|
|
+ $res = KeyboardService::getKeyWordReply($chatId, $text);
|
|
|
+ if (!empty($res)) return $res;
|
|
|
+
|
|
|
+ $stepStatus = intval(Cache::get(get_step_key($chatId), -1));
|
|
|
+
|
|
|
$res = QianBaoWithdrawService::onMessage($chatId, $text, $messageId, $stepStatus);
|
|
|
if (empty($res)) $res = SanJinRechargeService::onMessage($chatId, $text, $messageId, $stepStatus);
|
|
|
if (empty($res)) $res = SecretService::onMessage($chatId, $text, $messageId, $stepStatus);
|
|
|
if (!empty($res)) return $res;
|
|
|
+
|
|
|
+
|
|
|
switch ($stepStatus) {
|
|
|
case StepStatus::INPUT_TOP_UP_MONEY:
|
|
|
return TopUpService::inputAmount($chatId, $text, $messageId);
|
|
|
case StepStatus::INPUT_WITHDRAW_MONEY:
|
|
|
- $res = (new WithdrawService())->inputAmount($chatId, $text, $messageId);
|
|
|
- return $res[0];
|
|
|
+ return (new WithdrawService())->inputAmount($chatId, $text, $messageId)[0];
|
|
|
case StepStatus::INPUT_ADDRESS_TRC20:
|
|
|
return WithdrawService::inputAddress($chatId, $text, $messageId);
|
|
|
case StepStatus::INPUT_ADDRESS_ALIAS:
|
|
|
return WithdrawService::inputAlias($chatId, $text, $messageId);
|
|
|
+ default:
|
|
|
+ $returnMsg = BetService::bet($chatId, $text, $messageId);
|
|
|
+ break;
|
|
|
}
|
|
|
- $returnMsg = BetService::bet($chatId, $text, $messageId);
|
|
|
+
|
|
|
}
|
|
|
|
|
|
return $returnMsg;
|