no message

This commit is contained in:
hellcat committed 2025-04-03 18:51:05 +08:00
1 parent 96190ea437
commit 8b88da3ccd
6 files changed
+440 -8

No files matched your search

+3 -1
View File
@@ -29,7 +29,9 @@ final class TestController extends BaseController
{
$jobs = new CronService();
$jobs->userCount();
$jobs->mergeBandWidth();
$jobs->reportBandWidth();
exit;
}
+291 -1
View File
@@ -10,12 +10,15 @@ use App\Models\Ticket;
use App\Models\Node;
use App\Models\User;
use App\Models\Order;
use App\Models\Ducks;
use App\Models\Zhuanfas;
use App\Services\Tg\ReportUser as ServiceTgReportUser;
use GuzzleHttp\Exception\GuzzleException;
use Psr\Http\Client\ClientExceptionInterface;
use Psr\Http\Message\ResponseInterface;
use Slim\Http\Response;
use Slim\Http\ServerRequest;
use App\Utils\Tools;
use App\Services\TomTool\Http;
@@ -227,6 +230,292 @@ final class HookController
}
// 添加duck
// /duckAdd jp01
if (strpos($sText, '/duckAdd') === 0 || strpos($sText, '\/duckAdd') === 0) {
list($sCmd, $sCode) = explode(" ", $sText, 2);
try {
$oDucks = new Ducks();
$oDucks->code = $sCode;
if ($oDucks->save()) {
$sMsg = "成功";
} else {
$sMsg = "失败";
}
} catch (\Exception $e) {
$sMsg = json_encode($e->getMessage());
}
$this->sendMessage($sMsg);
Http::response(200, 'ok');
}
// 添加zhuanfa
// /zhuanfaAdd jp01
if (strpos($sText, '/zhuanfaAdd') === 0 || strpos($sText, '\/zhuanfaAdd') === 0) {
list($sCmd, $sCode) = explode(" ", $sText, 2);
try {
$oZhuanfas = new Zhuanfas();
$oZhuanfas->code = $sCode;
if ($oZhuanfas->save()) {
$sMsg = "成功";
} else {
$sMsg = "失败";
}
} catch (\Exception $e) {
$sMsg = json_encode($e->getMessage());
}
$this->sendMessage($sMsg);
Http::response(200, 'ok');
}
// 删除duck
// /duckDel jp01
if (strpos($sText, '/duckDel') === 0 || strpos($sText, '\/duckDel') === 0) {
list($sCmd, $sCode) = explode(" ", $sText, 2);
try {
$oDucks = Ducks::where("code", $sCode)->first();
if ($oDucks) {
// 尝试删除记录
$deleted = $oDucks->delete();
if ($deleted) {
// 删除成功
$sMsg = "成功";
} else {
// 删除失败
$sMsg = "失败";
}
} else {
// 找不到记录
$sMsg = "找不到记录";
}
} catch (\Exception $e) {
// 捕获异常并返回错误信息
$sMsg = json_encode($e->getMessage());
}
$this->sendMessage($sMsg);
Http::response(200, 'ok');
}
// 删除zhuanfa
// /zhuanfaDel jp01
if (strpos($sText, '/zhuanfaDel') === 0 || strpos($sText, '\/zhuanfaDel') === 0) {
list($sCmd, $sCode) = explode(" ", $sText, 2);
try {
$oZhuanfas = Zhuanfas::where("code", $sCode)->first();
if ($oZhuanfas) {
// 尝试删除记录
$deleted = $oZhuanfas->delete();
if ($deleted) {
// 删除成功
$sMsg = "成功";
} else {
// 删除失败
$sMsg = "失败";
}
} else {
// 找不到记录
$sMsg = "找不到记录";
}
} catch (\Exception $e) {
// 捕获异常并返回错误信息
$sMsg = json_encode($e->getMessage());
}
$this->sendMessage($sMsg);
Http::response(200, 'ok');
}
// 修改duck
// /duckOption-end_date-jp01 2025_02_02
// /duckOption-max_width-jp01 1.66#tb
if (strpos($sText, '/duckOption') === 0 || strpos($sText, '\/duckOption') === 0) {
list($sCmd, $sSet) = explode(" ", $sText, 2);
list(, $sField, $sCode) = explode("-", $sCmd, 3);
@list($iWidth, $sWidthType) = explode("#", $sSet, 2);
if ($sWidthType == 'tb') {
$sSet = Tools::tomTbToB($iWidth);
}
if ($sWidthType == 'gb') {
$sSet = Tools::tomGbToB($iWidth);
}
$sMsg = '?';
try {
$oDuck = Ducks::where('code', $sCode)->first();
if (!$oDuck) {
$sMsg = "没有这个code";
} else {
$oDuck->$sField = $sSet;
if ($oDuck->save()) {
$sMsg = "成功"; // 保存成功
} else {
$sMsg = "失败"; // 保存失败
}
}
} catch (\Illuminate\Database\QueryException $e) {
$sMsg = json_encode($e->getMessage());
}
$this->sendMessage($sMsg);
Http::response(200, 'ok');
}
// 修改zhuanfa
// /zhuanfaOption-end_date-jp01 2025_02_02
// /zhuanfaOption-max_width-jp01 1.66#tb
if (strpos($sText, '/zhuanfaOption') === 0 || strpos($sText, '\/zhuanfaOption') === 0) {
list($sCmd, $sSet) = explode(" ", $sText, 2);
list(, $sField, $sCode) = explode("-", $sCmd, 3);
@list($iWidth, $sWidthType) = explode("#", $sSet, 2);
if ($sWidthType == 'tb') {
$sSet = Tools::tomTbToB($iWidth);
}
if ($sWidthType == 'gb') {
$sSet = Tools::tomGbToB($iWidth);
}
$sMsg = '?';
try {
$oZhuanfas = Zhuanfas::where('code', $sCode)->first();
if (!$oZhuanfas) {
$sMsg = "没有这个code";
} else {
$oZhuanfas->$sField = $sSet;
if ($oZhuanfas->save()) {
$sMsg = "成功"; // 保存成功
} else {
$sMsg = "失败"; // 保存失败
}
}
} catch (\Illuminate\Database\QueryException $e) {
$sMsg = json_encode($e->getMessage());
}
$this->sendMessage($sMsg);
Http::response(200, 'ok');
}
// 转发重置
// /zhuanfaReset-youshi 2025-02-02
if (strpos($sText, '/zhuanfaReset') === 0 || strpos($sText, '\/zhuanfaReset') === 0) {
list($sCmd, $sDate) = explode(" ", $sText, 2);
list(, $sCode) = explode("-", $sCmd, 2);
$sMsg = '?';
try {
$oZhuanfas = Zhuanfas::where('code', $sCode)->first();
if (!$oZhuanfas) {
$sMsg = "没有这个code";
} else {
$oZhuanfas->use_width = 0;
$oZhuanfas->end_date = $sDate;
if ($oZhuanfas->save()) {
$sMsg = "成功"; // 保存成功
} else {
$sMsg = "失败"; // 保存失败
}
}
} catch (\Illuminate\Database\QueryException $e) {
$sMsg = json_encode($e->getMessage());
}
$this->sendMessage($sMsg);
Http::response(200, 'ok');
}
// duck list
// /duckList
if (strpos($sText, '/duckList') === 0 || strpos($sText, '\/duckList') === 0) {
$aDuckList = Ducks::all()->toArray();
$aMsgData = [];
foreach ($aDuckList as $k => $v) {
$v['use_width'] = Tools::flowToTB($v['use_width']).'t';
$v['max_width'] = Tools::flowToTB($v['max_width']).'t';
$v['today_width'] = Tools::flowToGB($v['today_width']).'g';
$aMsgData[] = $v;
}
$this->sendMessage(json_encode($aMsgData, JSON_PRETTY_PRINT));
Http::response(200, 'ok');
}
// zhuanfa list
// /zhuanfaList
if (strpos($sText, '/zhuanfaList') === 0 || strpos($sText, '\/zhuanfaList') === 0) {
$aZhuanfaList = Zhuanfas::all()->toArray();
$aMsgData = [];
foreach ($aZhuanfaList as $k => $v) {
$v['use_width'] = Tools::flowToTB($v['use_width'])."t";
$v['max_width'] = Tools::flowToTB($v['max_width']).'t';
$v['today_width'] = Tools::flowToGB($v['today_width']).'g';
$aMsgData[] = $v;
}
$this->sendMessage(json_encode($aMsgData, JSON_PRETTY_PRINT));
Http::response(200, 'ok');
}
// 节点设置变更
// /nodeOption_name_1 haha
if (strpos($sText, '/nodeOption_') === 0 || strpos($sText, '\/nodeOption_') === 0) {
@@ -391,7 +680,8 @@ final class HookController
private function sendMessage($sText) {
if ($_ENV['is_loc'] === true) {
var_dump($sText);
echo "<pre>";
echo($sText);
} else {
$url = "https://api.telegram.org/bot$this->sApiToken/sendMessage?chat_id=$this->sApiChatId&text=" . urlencode($sText);
file_get_contents($url);