mirror of
https://github.com/v2board/v2board.git
synced 2025-04-15 14:12:36 +08:00
update telegram
This commit is contained in:
parent
108d54f3cb
commit
1ed5a278da
@ -2,6 +2,7 @@
|
|||||||
|
|
||||||
namespace App\Http\Controllers\Guest;
|
namespace App\Http\Controllers\Guest;
|
||||||
|
|
||||||
|
use App\Services\TelegramService;
|
||||||
use App\Services\UserService;
|
use App\Services\UserService;
|
||||||
use Illuminate\Http\Request;
|
use Illuminate\Http\Request;
|
||||||
use App\Http\Controllers\Controller;
|
use App\Http\Controllers\Controller;
|
||||||
@ -19,9 +20,14 @@ class TelegramController extends Controller
|
|||||||
{
|
{
|
||||||
$msg = $this->getMessage($request->input());
|
$msg = $this->getMessage($request->input());
|
||||||
if (!$msg) return;
|
if (!$msg) return;
|
||||||
switch($msg->command) {
|
try {
|
||||||
case '/bind': $this->bind($msg);
|
switch($msg->command) {
|
||||||
break;
|
case '/bind': $this->bind($msg);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
} catch (\Exception $e) {
|
||||||
|
$telegramService = new TelegramService();
|
||||||
|
$telegramService->sendMessage($msg->chat_id, $e->getMessage());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -40,9 +46,19 @@ class TelegramController extends Controller
|
|||||||
private function bind(object $msg)
|
private function bind(object $msg)
|
||||||
{
|
{
|
||||||
if (!$msg->is_private) return;
|
if (!$msg->is_private) return;
|
||||||
$userService = new UserService();
|
|
||||||
$subscribeUrl = $msg->args[0];
|
$subscribeUrl = $msg->args[0];
|
||||||
$subscribeUrl = parse_url($subscribeUrl);
|
$subscribeUrl = parse_url($subscribeUrl);
|
||||||
info($subscribeUrl);
|
$token = parse_str($subscribeUrl['query'])['token'];
|
||||||
|
if (!$token) {
|
||||||
|
abort(500, '订阅地址无效');
|
||||||
|
}
|
||||||
|
$user = User::where('token', $token)->first();
|
||||||
|
if (!$user) {
|
||||||
|
abort(500, '用户不存在');
|
||||||
|
}
|
||||||
|
$user->telegram_id = $msg->chat_id;
|
||||||
|
if (!$user->save()) {
|
||||||
|
abort(500, '设置失败');
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -90,30 +90,4 @@ class UserService
|
|||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function setTelegramId(int $userId, int $telegramId):bool
|
|
||||||
{
|
|
||||||
$user = User::find($userId);
|
|
||||||
if (!$user) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
$user->telegram_id = $telegramId;
|
|
||||||
if (!$user->save()) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function delTelegramId(int $userId):bool
|
|
||||||
{
|
|
||||||
$user = User::find($userId);
|
|
||||||
if (!$user) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
$user->telegram_id = NULL;
|
|
||||||
if (!$user->save()) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user