|
|
@@ -16,8 +16,8 @@ use App\Services\TopUpService;
|
|
|
use App\Services\TutorialService;
|
|
|
use App\Services\UserService;
|
|
|
use App\Services\WalletService;
|
|
|
-use App\Services\WithdrawService;
|
|
|
-use App\Services\BalanceLogService;
|
|
|
+use App\Services\WithdrawService;
|
|
|
+use App\Services\BalanceLogService;
|
|
|
use Illuminate\Http\Request;
|
|
|
use Illuminate\Support\Facades\Cache;
|
|
|
use Illuminate\Support\Facades\DB;
|
|
|
@@ -44,10 +44,10 @@ class TelegramWebHook extends Controller
|
|
|
{
|
|
|
Log::error('Telegram 日志写入测试: ' . json_encode([$request->ip()], JSON_UNESCAPED_UNICODE));
|
|
|
// try {
|
|
|
- $m = new Message();
|
|
|
- $m->json = $request->ip();
|
|
|
- $m->save();
|
|
|
- $telegram = new Api(config('services.telegram.token'));
|
|
|
+ $m = new Message();
|
|
|
+ $m->json = $request->ip();
|
|
|
+ $m->save();
|
|
|
+ $telegram = new Api(config('services.telegram.token'));
|
|
|
// } catch (TelegramSDKException $e) {
|
|
|
// return response()->json(['status' => 'ok']);
|
|
|
// }
|
|
|
@@ -67,7 +67,7 @@ class TelegramWebHook extends Controller
|
|
|
Util::delCache($message->chat->id);
|
|
|
Log::error('Telegram 回调数据(JSON): ' . json_encode($update, JSON_UNESCAPED_UNICODE));
|
|
|
|
|
|
- DB::beginTransaction();
|
|
|
+ DB::beginTransaction();
|
|
|
try {
|
|
|
$chatId = $message->chat->id;
|
|
|
$firstName = $message->chat->firstName;
|
|
|
@@ -87,21 +87,21 @@ class TelegramWebHook extends Controller
|
|
|
//给每个用户生成一个专属的USDT钱包
|
|
|
WalletService::getUserWallet($chatId);
|
|
|
|
|
|
-
|
|
|
+
|
|
|
// 查看余额弹窗
|
|
|
- if($data === 'balanceAlert'){
|
|
|
+ if ($data === 'balanceAlert') {
|
|
|
$alertText = WalletService::getBalance($chatId)['text'];
|
|
|
- WalletService::alertNotice($callbackId , $alertText);
|
|
|
+ WalletService::alertNotice($callbackId, $alertText);
|
|
|
}
|
|
|
// 今日流水弹窗
|
|
|
- if($data === 'todayFlowAlert'){
|
|
|
+ if ($data === 'todayFlowAlert') {
|
|
|
$alertText = BalanceLogService::getTodayFlowing($chatId)['text'];
|
|
|
- BalanceLogService::alertNotice($callbackId , $alertText);
|
|
|
+ BalanceLogService::alertNotice($callbackId, $alertText);
|
|
|
}
|
|
|
// 近期注单弹窗
|
|
|
- if($data === 'betsAlert'){
|
|
|
+ if ($data === 'betsAlert') {
|
|
|
$alertText = BetService::recentlyRecord($chatId);
|
|
|
- BetService::alertNotice($callbackId , $alertText);
|
|
|
+ BetService::alertNotice($callbackId, $alertText);
|
|
|
}
|
|
|
|
|
|
//点击充值按钮
|
|
|
@@ -131,7 +131,7 @@ class TelegramWebHook extends Controller
|
|
|
// ]);
|
|
|
}
|
|
|
|
|
|
- //点击我已付款按钮
|
|
|
+ //点击我已付款按钮
|
|
|
//手动充值(后台审核后到账)
|
|
|
if ($data === 'topUp@@pay2') {
|
|
|
$telegram->deleteMessage([
|
|
|
@@ -160,7 +160,7 @@ class TelegramWebHook extends Controller
|
|
|
'message_id' => $messageId
|
|
|
]);
|
|
|
$returnMsg = WalletService::getBalance($chatId);
|
|
|
- if($returnMsg){
|
|
|
+ if ($returnMsg) {
|
|
|
$this->telegram->sendMessage($returnMsg);
|
|
|
}
|
|
|
// if ($data === "topUp@@home1") {
|
|
|
@@ -188,7 +188,6 @@ class TelegramWebHook extends Controller
|
|
|
}
|
|
|
|
|
|
|
|
|
-
|
|
|
//关闭本条消息
|
|
|
if ($data === 'message@@close') {
|
|
|
$telegram->deleteMessage([
|
|
|
@@ -211,7 +210,7 @@ class TelegramWebHook extends Controller
|
|
|
'message_id' => $messageId
|
|
|
]);
|
|
|
$returnMsg = WalletService::getBalance($chatId);
|
|
|
- if($returnMsg){
|
|
|
+ if ($returnMsg) {
|
|
|
$this->telegram->sendMessage($returnMsg);
|
|
|
}
|
|
|
}
|
|
|
@@ -268,7 +267,6 @@ class TelegramWebHook extends Controller
|
|
|
$telegram->editMessageText($res);
|
|
|
}
|
|
|
|
|
|
-
|
|
|
|
|
|
//提现账单,下一页
|
|
|
$pattern = "/^withdrawBillNextPage@@\d+$/";
|
|
|
@@ -284,10 +282,10 @@ class TelegramWebHook extends Controller
|
|
|
if (preg_match($pattern, $data)) {
|
|
|
$page = preg_replace('/^betRecordNextPage@@/', '', $data);
|
|
|
$page = intval($page);
|
|
|
- $res = BetService::record($chatId ,$messageId ,$page );
|
|
|
+ $res = BetService::record($chatId, $messageId, $page);
|
|
|
$telegram->editMessageText($res);
|
|
|
}
|
|
|
- DB::commit();
|
|
|
+ DB::commit();
|
|
|
} //
|
|
|
catch (MessageException $e) {
|
|
|
DB::rollBack();
|
|
|
@@ -319,7 +317,7 @@ class TelegramWebHook extends Controller
|
|
|
]);
|
|
|
}
|
|
|
|
|
|
- }else {
|
|
|
+ } else {
|
|
|
$update = $request->all();
|
|
|
Log::error('Telegram 文字消息回复: ' . json_encode($update, JSON_UNESCAPED_UNICODE));
|
|
|
if (isset($update['message'])) {
|
|
|
@@ -333,12 +331,11 @@ class TelegramWebHook extends Controller
|
|
|
$m->save();
|
|
|
|
|
|
$returnMsg = $this->processChatMessage($chatId, $messageId, $message, $message['from']);
|
|
|
- if($returnMsg){
|
|
|
+ if ($returnMsg) {
|
|
|
$this->telegram->sendMessage($returnMsg);
|
|
|
}
|
|
|
DB::commit();
|
|
|
- }
|
|
|
- catch (MessageException $e) {
|
|
|
+ } catch (MessageException $e) {
|
|
|
DB::rollBack();
|
|
|
$msg = $e->getMessage();
|
|
|
$msg = json_decode($msg, true);
|
|
|
@@ -381,7 +378,7 @@ class TelegramWebHook extends Controller
|
|
|
* @param {*} $message
|
|
|
* @param {*} $from
|
|
|
* @return {*}
|
|
|
- */
|
|
|
+ */
|
|
|
public function processChatMessage($chatId, $messageId, $message, $from)
|
|
|
{
|
|
|
$returnMsg = [];
|
|
|
@@ -411,12 +408,7 @@ class TelegramWebHook extends Controller
|
|
|
if ($message['chat']['type'] === 'private') {
|
|
|
switch ($text) {
|
|
|
case "/start":
|
|
|
- $telegram = new Api(config('services.telegram.token'));
|
|
|
- $telegram->sendMessage([
|
|
|
- 'chat_id' => $chatId,
|
|
|
- 'text' =>json_encode($message),
|
|
|
- ]);
|
|
|
-return;
|
|
|
+
|
|
|
|
|
|
Util::delCache($chatId);
|
|
|
$user = User::where('member_id', $chatId)->first();
|
|
|
@@ -425,6 +417,11 @@ return;
|
|
|
$user->member_id = $chatId;
|
|
|
}
|
|
|
$user->first_name = $message['chat']['first_name'];
|
|
|
+ if (isset($message['chat']['username'])) {
|
|
|
+ $user->username = $message['chat']['username'];
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
$user->save();
|
|
|
//给每个用户生成一个专属的USDT钱包
|
|
|
WalletService::getUserWallet($chatId);
|
|
|
@@ -515,10 +512,10 @@ return;
|
|
|
$res = WithdrawService::inputAlias($chatId, $text, $messageId);
|
|
|
return $res;
|
|
|
break;
|
|
|
-
|
|
|
+
|
|
|
}
|
|
|
- $returnMsg = BetService::bet($chatId,$text,$messageId);
|
|
|
- // $this->telegram->sendMessage($returnMsg);
|
|
|
+ $returnMsg = BetService::bet($chatId, $text, $messageId);
|
|
|
+ // $this->telegram->sendMessage($returnMsg);
|
|
|
}
|
|
|
|
|
|
return $returnMsg;
|
|
|
@@ -530,7 +527,7 @@ return;
|
|
|
* @description: 设置 start 回复菜单
|
|
|
* @param {*} $chatId
|
|
|
* @return {*}
|
|
|
- */
|
|
|
+ */
|
|
|
public function setReplyKeyboard($chatId)
|
|
|
{
|
|
|
$replyInfo = KeyboardService::findOne(['button' => '开始使用']);
|
|
|
@@ -551,32 +548,32 @@ return;
|
|
|
];
|
|
|
$botMsg['reply_markup'] = json_encode($replyMarkup);
|
|
|
|
|
|
- if($replyInfo){
|
|
|
+ if ($replyInfo) {
|
|
|
$image = '';
|
|
|
- if($replyInfo->image){
|
|
|
+ if ($replyInfo->image) {
|
|
|
$image = url($replyInfo->image);
|
|
|
|
|
|
}
|
|
|
-
|
|
|
- if($image != ''){
|
|
|
+
|
|
|
+ if ($image != '') {
|
|
|
$botMsg['photo'] = InputFile::create($image);
|
|
|
$botMsg['caption'] = $replyInfo->reply;
|
|
|
$botMsg['protect_content'] = true; // 防止转发
|
|
|
KeyboardService::telegram()->sendPhoto($botMsg);
|
|
|
- }else{
|
|
|
+ } else {
|
|
|
$botMsg['text'] = $replyInfo->reply;
|
|
|
-
|
|
|
+
|
|
|
KeyboardService::telegram()->sendMessage($botMsg);
|
|
|
}
|
|
|
- }else{
|
|
|
- $telegram->sendMessage([
|
|
|
+ } else {
|
|
|
+ $telegram->sendMessage([
|
|
|
'chat_id' => $chatId,
|
|
|
'text' => '你好,请选择功能菜单',
|
|
|
'reply_markup' => json_encode($replyMarkup),
|
|
|
]);
|
|
|
}
|
|
|
|
|
|
-
|
|
|
+
|
|
|
}
|
|
|
|
|
|
|
|
|
@@ -620,10 +617,10 @@ return;
|
|
|
WalletService::getUserWallet($chatId);
|
|
|
|
|
|
// 查看余额弹窗
|
|
|
- if($data === 'balanceAlert'){
|
|
|
+ if ($data === 'balanceAlert') {
|
|
|
Log::error('查看余额弹窗 balanceAlert: ' . $callbackId);
|
|
|
// $alertText = WalletService::getBalance($chatId)['text'];
|
|
|
- WalletService::alertNotice($callbackId , '您好,您的余额为:');
|
|
|
+ WalletService::alertNotice($callbackId, '您好,您的余额为:');
|
|
|
}
|
|
|
|
|
|
//取消创建游戏
|
|
|
@@ -880,7 +877,6 @@ return;
|
|
|
$telegram->editMessageText($res);
|
|
|
}
|
|
|
|
|
|
-
|
|
|
|
|
|
//提现账单,下一页
|
|
|
$pattern = "/^withdrawBillNextPage@@\d+$/";
|