no message
This commit is contained in:
parent
540b3af087
commit
335945a357
283
app/Http/Controllers/Api/TG/HookController 2.php
Executable file
283
app/Http/Controllers/Api/TG/HookController 2.php
Executable file
@ -0,0 +1,283 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace App\Http\Controllers\Api\Tg;
|
||||||
|
|
||||||
|
use App\Models\Article;
|
||||||
|
//use App\Models\TgStep;
|
||||||
|
//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;
|
||||||
|
|
||||||
|
final class HookController
|
||||||
|
{
|
||||||
|
|
||||||
|
public $sApiToken;
|
||||||
|
public $sApiChatId;
|
||||||
|
|
||||||
|
public function __construct()
|
||||||
|
{
|
||||||
|
// $this->middleware('csrf')->except(['cmd']);
|
||||||
|
// 或者 $this->middleware('csrf')->only(['specificMethod']);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public function cmd()
|
||||||
|
{
|
||||||
|
|
||||||
|
try {
|
||||||
|
|
||||||
|
$this->sApiToken = env('telegram_token');
|
||||||
|
$this->sApiChatId = env('telegram_chatid');
|
||||||
|
|
||||||
|
$sUpdate = file_get_contents("php://input");
|
||||||
|
|
||||||
|
$aUpdate = json_decode($sUpdate, true);
|
||||||
|
|
||||||
|
@file_put_contents('/www/_tg/bot_log.txt', json_encode($aUpdate, JSON_PRETTY_PRINT));
|
||||||
|
|
||||||
|
$aData['chatId'] = $aUpdate["message"]["chat"]["id"];
|
||||||
|
$aData['fromId'] = $aUpdate["message"]["from"]["id"];
|
||||||
|
|
||||||
|
if (!isset($aUpdate["message"]["text"])) {
|
||||||
|
http_response_code(200);
|
||||||
|
echo "not have text";
|
||||||
|
exit;
|
||||||
|
}
|
||||||
|
|
||||||
|
$sText = $aUpdate["message"]["text"];
|
||||||
|
|
||||||
|
|
||||||
|
// 打断
|
||||||
|
if ($sText === "/break") {
|
||||||
|
|
||||||
|
$oTgStep->clearByFromId($aData["fromId"]);
|
||||||
|
|
||||||
|
$this->sendMessage("ok");
|
||||||
|
|
||||||
|
Http::response(200, 'ok');
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
// 命令列表
|
||||||
|
// /cmdList
|
||||||
|
// if (strpos($sText, '/cmdList') === 0 || strpos($sText, '\/cmdList') === 0) {
|
||||||
|
//
|
||||||
|
// $aCmdList = [
|
||||||
|
// '优惠码list' => '/saleCodeList',
|
||||||
|
// '优惠码find' => '/saleCodeFind xxhh',
|
||||||
|
// '优惠码rate' => '/saleCodeSetRate__xxzz 6.7',
|
||||||
|
// // '优惠码add' => '/saleCodeAdd xxhh',
|
||||||
|
// // '优惠码del' => '/saleCodeDel__xxhh',
|
||||||
|
// // '优惠码set' => '/saleCodeSet__xxhh__field set',
|
||||||
|
// '文章list' => '/articleList',
|
||||||
|
// '文章like' => '/articleLike__field like',
|
||||||
|
// '文章add' => '/articleAdd__name',
|
||||||
|
// '文章del' => '/articleDel__id',
|
||||||
|
// '文章set' => '/articleSet__id__fild set',
|
||||||
|
// ];
|
||||||
|
//
|
||||||
|
// $this->sendMessage(json_encode($aCmdList, JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT));
|
||||||
|
//
|
||||||
|
// Http::response(200, 'ok');
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
// 优惠设置幅度(批量)
|
||||||
|
// if (strpos($sText, '/saleCodeSetRate') === 0 || strpos($sText, '\/saleCodeSetRate') === 0) {
|
||||||
|
//
|
||||||
|
// list($sCmd, $iRate) = explode(" ", $sText);
|
||||||
|
// list(, $sCode) = explode("__", $sCmd);
|
||||||
|
//
|
||||||
|
// $updatedRows = Article::where('sale_code', $sCode)
|
||||||
|
// ->update(['sale_rate' => $iRate]);
|
||||||
|
//
|
||||||
|
// $this->sendMessage(json_encode($updatedRows, JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT));
|
||||||
|
//
|
||||||
|
// Http::response(200, 'ok');
|
||||||
|
// }
|
||||||
|
|
||||||
|
// 优惠list
|
||||||
|
// if (strpos($sText, '/saleCodeList') === 0 || strpos($sText, '\/saleCodeList') === 0) {
|
||||||
|
//
|
||||||
|
// $aSaleCodeList = Article::select('sale_code', 'sale_rate')
|
||||||
|
// ->distinct()
|
||||||
|
// ->orderBy("sale_code")
|
||||||
|
// ->get()
|
||||||
|
// ->toArray();
|
||||||
|
//
|
||||||
|
// $this->sendMessage(json_encode($aSaleCodeList, JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT));
|
||||||
|
//
|
||||||
|
// Http::response(200, 'ok');
|
||||||
|
// }
|
||||||
|
|
||||||
|
// 优惠find
|
||||||
|
// if (strpos($sText, '/saleCodeFind') === 0 || strpos($sText, '\/saleCodeFind') === 0) {
|
||||||
|
//
|
||||||
|
// list(, $sSaleCode) = explode(" ", $sText);
|
||||||
|
//
|
||||||
|
// $aSaleCodeList = Article::select('sale_code', 'sale_rate')
|
||||||
|
// ->where("sale_code", $sSaleCode)
|
||||||
|
// ->distinct()
|
||||||
|
// ->orderBy("sale_code")
|
||||||
|
// ->get()
|
||||||
|
// ->toArray();
|
||||||
|
//
|
||||||
|
// $this->sendMessage(json_encode($aSaleCodeList, JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT));
|
||||||
|
//
|
||||||
|
// Http::response(200, 'ok');
|
||||||
|
//
|
||||||
|
// }
|
||||||
|
|
||||||
|
// 文章list
|
||||||
|
// if (strpos($sText, '/ArticleList') === 0 || strpos($sText, '\/ArticleList') === 0) {
|
||||||
|
//
|
||||||
|
// $aArticleList = Article::orderBy("user_name")->get()->toArray();
|
||||||
|
//
|
||||||
|
// foreach ($aArticleList as $row) {
|
||||||
|
// $this->sendMessage(json_encode($row, JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT));
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
// Http::response(200, 'ok');
|
||||||
|
// }
|
||||||
|
|
||||||
|
// 文章 like
|
||||||
|
// /ArticleLike__user_name xxx
|
||||||
|
// if (strpos($sText, '/ArticleLike') === 0 || strpos($sText, '\/ArticleLike') === 0) {
|
||||||
|
//
|
||||||
|
// list($sCmd, $sLike) = explode(" ", $sText);
|
||||||
|
// list(, $sField) = explode("__", $sCmd);
|
||||||
|
//
|
||||||
|
// $aArticleList = Article::where($sField, 'like', '%' . $sLike . '%')
|
||||||
|
// ->orderBy("user_name")
|
||||||
|
// ->get()
|
||||||
|
// ->toArray();
|
||||||
|
//
|
||||||
|
//
|
||||||
|
// foreach ($aArticleList as $row) {
|
||||||
|
// $this->sendMessage(json_encode($row, JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT));
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
// Http::response(200, 'ok');
|
||||||
|
// }
|
||||||
|
|
||||||
|
// 文章 add
|
||||||
|
// if (strpos($sText, '/articleAdd') === 0 || strpos($sText, '\/articleAdd') === 0) {
|
||||||
|
//
|
||||||
|
// list(, $sUserName) = explode(" ", $sText);
|
||||||
|
//
|
||||||
|
// $newArticle = new Article();
|
||||||
|
// $newArticle->user_name = $sUserName;
|
||||||
|
// $r = $newArticle->save();
|
||||||
|
//
|
||||||
|
// $this->sendMessage(json_encode($r, JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT));
|
||||||
|
//
|
||||||
|
// Http::response(200, 'ok');
|
||||||
|
//
|
||||||
|
// }
|
||||||
|
|
||||||
|
// 文章 del
|
||||||
|
// if (strpos($sText, '/articleDel') === 0 || strpos($sText, '\/articleDel') === 0) {
|
||||||
|
//
|
||||||
|
// list(, $iId) = explode(" ", $sText);
|
||||||
|
//
|
||||||
|
// $article = Article::find($iId);
|
||||||
|
//
|
||||||
|
// if ($article) {
|
||||||
|
// $r = $article->delete();
|
||||||
|
// } else {
|
||||||
|
// $r = false;
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
// $this->sendMessage(json_encode($r, JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT));
|
||||||
|
//
|
||||||
|
// Http::response(200, 'ok');
|
||||||
|
//
|
||||||
|
// }
|
||||||
|
|
||||||
|
// 文章 set
|
||||||
|
// /ArticleSet__id__user_name xxx
|
||||||
|
// if (strpos($sText, '/ArticleSet') === 0 || strpos($sText, '\/ArticleSet') === 0) {
|
||||||
|
//
|
||||||
|
// list($sCmd, $sSet) = explode(" ", $sText);
|
||||||
|
// list(, $iId, $sField) = explode("__", $sCmd, 3);
|
||||||
|
// $sField = $this->cmdGood($sField);
|
||||||
|
//
|
||||||
|
// $article = Article::find($iId);
|
||||||
|
//
|
||||||
|
// if ($article) {
|
||||||
|
// $article->$sField = $sSet;
|
||||||
|
//
|
||||||
|
// $r = $article->save();
|
||||||
|
// } else {
|
||||||
|
// // 处理未找到的情况
|
||||||
|
// throw new Exception("Article not found with ID: $iId");
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
// $this->sendMessage(json_encode($r, JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT));
|
||||||
|
//
|
||||||
|
// Http::response(200, 'ok');
|
||||||
|
// }
|
||||||
|
|
||||||
|
} catch (\Exception $e) {
|
||||||
|
// 处理异常
|
||||||
|
$errorMessage = $e->getMessage();
|
||||||
|
$this->sendMessage(json_encode(['error' => $errorMessage], JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT));
|
||||||
|
|
||||||
|
Http::response(200, '不对');
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
private function sendMessage($sText = '?') {
|
||||||
|
|
||||||
|
if (env('is_loc') === true) {
|
||||||
|
echo "<pre>";
|
||||||
|
var_dump($sText);
|
||||||
|
} else {
|
||||||
|
$url = "https://api.telegram.org/bot$this->sApiToken/sendMessage?chat_id=$this->sApiChatId&text=" . urlencode($sText);
|
||||||
|
file_get_contents($url);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
private function cmdGood($sCmd) {
|
||||||
|
|
||||||
|
$sCmdNew = "";
|
||||||
|
switch ($sCmd) {
|
||||||
|
case "user":
|
||||||
|
$sCmdNew = "user_name";
|
||||||
|
break;
|
||||||
|
case "project":
|
||||||
|
$sCmdNew = "project_name";
|
||||||
|
break;
|
||||||
|
case "code":
|
||||||
|
$sCmdNew = "sale_code";
|
||||||
|
break;
|
||||||
|
case "condition":
|
||||||
|
$sCmdNew = "cron_condition";
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
$sCmdNew = $sCmd;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
return $sCmdNew;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
100
app/Http/Controllers/Api/TG/HookController.php
Executable file
100
app/Http/Controllers/Api/TG/HookController.php
Executable file
@ -0,0 +1,100 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace App\Http\Controllers\Api\TG;
|
||||||
|
|
||||||
|
use App\Models\Article;
|
||||||
|
use App\Services\TomTool\Http;
|
||||||
|
use App\Services\TG\Http as TGHttp;
|
||||||
|
|
||||||
|
final class HookController
|
||||||
|
{
|
||||||
|
|
||||||
|
public function __construct()
|
||||||
|
{
|
||||||
|
// $this->middleware('csrf')->except(['cmd']);
|
||||||
|
// 或者 $this->middleware('csrf')->only(['specificMethod']);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public function cmd()
|
||||||
|
{
|
||||||
|
|
||||||
|
try {
|
||||||
|
|
||||||
|
$oTGHttp = new TGHttp();
|
||||||
|
$oTGHttp->sApiToken = env('telegram_token');
|
||||||
|
$oTGHttp->sApiChatId = env('telegram_chatid');
|
||||||
|
|
||||||
|
$sUpdate = file_get_contents("php://input");
|
||||||
|
|
||||||
|
$aUpdate = json_decode($sUpdate, true);
|
||||||
|
|
||||||
|
@file_put_contents('/www/_tg/bot_log.txt', json_encode($aUpdate, JSON_PRETTY_PRINT));
|
||||||
|
|
||||||
|
$aData['chatId'] = $aUpdate["message"]["chat"]["id"];
|
||||||
|
$aData['fromId'] = $aUpdate["message"]["from"]["id"];
|
||||||
|
|
||||||
|
if (!isset($aUpdate["message"]["text"])) {
|
||||||
|
Http::response(200, 'not have text');
|
||||||
|
}
|
||||||
|
|
||||||
|
$sText = $aUpdate["message"]["text"];
|
||||||
|
|
||||||
|
// test
|
||||||
|
$sText = "\\//Article#List ni__aaa__bbb 111 222";
|
||||||
|
$sText = "///\\\SaleCode#SetRate__zzxx 2";
|
||||||
|
$sText = "///\\\SaleCode#List";
|
||||||
|
$sText = "///\\\SaleCode#Find zzxx";
|
||||||
|
$sText = "/Article#Like__sale_code zzx";
|
||||||
|
$sText = "////Article#Add jxxjjjj";
|
||||||
|
// $sText = "//\\\//Article#Del 9";
|
||||||
|
// $sText = "/Article#Set__1__user_name xxx";
|
||||||
|
|
||||||
|
@$aArg = explode(" ", $sText);
|
||||||
|
@$aOption = explode("__", $aArg[0]);
|
||||||
|
|
||||||
|
$sCmd = $this->cleanCmd($aOption[0]);
|
||||||
|
|
||||||
|
list($sClass, $sFunc) = explode("#", $sCmd);
|
||||||
|
|
||||||
|
unset($aOption[0]);
|
||||||
|
unset($aArg[0]);
|
||||||
|
|
||||||
|
$aParams['aOption'] = $aOption;
|
||||||
|
$aParams['aArg'] = $aArg;
|
||||||
|
|
||||||
|
$sClassPath = "App\\Services\\TG\\Hook\\".$sClass;
|
||||||
|
|
||||||
|
if (method_exists($sClassPath, $sFunc)) {
|
||||||
|
|
||||||
|
$oInstans = new $sClassPath();
|
||||||
|
$r = $oInstans->$sFunc($aParams);
|
||||||
|
|
||||||
|
} else {
|
||||||
|
$this->sendMessage("没有这个方法");
|
||||||
|
}
|
||||||
|
|
||||||
|
} catch (\Exception $e) {
|
||||||
|
|
||||||
|
$sMessage = "错误: " . $e->getMessage();
|
||||||
|
|
||||||
|
$oTGHttp->sendToTG($sMessage);
|
||||||
|
|
||||||
|
Http::response(200, 'error');
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
private function cleanCmd($input) {
|
||||||
|
// 去掉所有的反斜杠
|
||||||
|
$input = str_replace('\\', '', $input);
|
||||||
|
// 去掉所有的正斜杠
|
||||||
|
$input = str_replace('/', '', $input);
|
||||||
|
|
||||||
|
return $input;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@ -1,230 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
declare(strict_types=1);
|
|
||||||
|
|
||||||
namespace App\Http\Controllers\Api\Tg;
|
|
||||||
|
|
||||||
use App\Models\Article;
|
|
||||||
//use App\Models\TgStep;
|
|
||||||
//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;
|
|
||||||
|
|
||||||
final class HookController
|
|
||||||
{
|
|
||||||
|
|
||||||
public $sApiToken;
|
|
||||||
public $sApiChatId;
|
|
||||||
|
|
||||||
public function __construct()
|
|
||||||
{
|
|
||||||
// $this->middleware('csrf')->except(['cmd']);
|
|
||||||
// 或者 $this->middleware('csrf')->only(['specificMethod']);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
public function cmd()
|
|
||||||
{
|
|
||||||
|
|
||||||
$this->sApiToken = env('telegram_token');
|
|
||||||
$this->sApiChatId = env('telegram_chatid');
|
|
||||||
|
|
||||||
$sUpdate = file_get_contents("php://input");
|
|
||||||
|
|
||||||
$aUpdate = json_decode($sUpdate, true);
|
|
||||||
|
|
||||||
@file_put_contents('/www/_tg/bot_log.txt', json_encode($aUpdate, JSON_PRETTY_PRINT));
|
|
||||||
|
|
||||||
$aData['chatId'] = $aUpdate["message"]["chat"]["id"];
|
|
||||||
$aData['fromId'] = $aUpdate["message"]["from"]["id"];
|
|
||||||
|
|
||||||
if (!isset($aUpdate["message"]["text"])) {
|
|
||||||
http_response_code(200);
|
|
||||||
echo "not have text";
|
|
||||||
exit;
|
|
||||||
}
|
|
||||||
|
|
||||||
$sText = $aUpdate["message"]["text"];
|
|
||||||
|
|
||||||
|
|
||||||
// 打断
|
|
||||||
if ($sText === "/break") {
|
|
||||||
|
|
||||||
$oTgStep->clearByFromId($aData["fromId"]);
|
|
||||||
|
|
||||||
$this->sendMessage("ok");
|
|
||||||
|
|
||||||
Http::response(200, 'ok');
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
// 命令列表
|
|
||||||
// /cmdList
|
|
||||||
if (strpos($sText, '/cmdList') === 0 || strpos($sText, '\/cmdList') === 0) {
|
|
||||||
|
|
||||||
$aCmdList = [
|
|
||||||
'优惠码list' => '/saleCodeList',
|
|
||||||
'优惠码find' => '/saleCodeFind xxhh',
|
|
||||||
// '优惠码add' => '/saleCodeAdd xxhh',
|
|
||||||
// '优惠码del' => '/saleCodeDel__xxhh',
|
|
||||||
// '优惠码set' => '/saleCodeSet__xxhh__field set',
|
|
||||||
'文章list' => '/articleList',
|
|
||||||
'文章like' => '/articleLike__field like',
|
|
||||||
'文章add' => '/articleAdd__name',
|
|
||||||
'文章del' => '/articleDel__id',
|
|
||||||
'文章set' => '/articleSet__id__fild set',
|
|
||||||
];
|
|
||||||
|
|
||||||
$this->sendMessage(json_encode($aCmdList, JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT));
|
|
||||||
|
|
||||||
Http::response(200, 'ok');
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
// 优惠list
|
|
||||||
if (strpos($sText, '/saleCodeList') === 0 || strpos($sText, '\/saleCodeList') === 0) {
|
|
||||||
|
|
||||||
$aSaleCodeList = Article::select('sale_code', 'sale_rate')
|
|
||||||
->distinct()
|
|
||||||
->orderBy("sale_code")
|
|
||||||
->get()
|
|
||||||
->toArray();
|
|
||||||
|
|
||||||
$this->sendMessage(json_encode($aSaleCodeList, JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT));
|
|
||||||
|
|
||||||
Http::response(200, 'ok');
|
|
||||||
}
|
|
||||||
|
|
||||||
// 优惠find
|
|
||||||
if (strpos($sText, '/saleCodeFind') === 0 || strpos($sText, '\/saleCodeFind') === 0) {
|
|
||||||
|
|
||||||
list(, $sSaleCode) = explode(" ", $sText);
|
|
||||||
|
|
||||||
$aSaleCodeList = Article::select('sale_code', 'sale_rate')
|
|
||||||
->where("sale_code", $sSaleCode)
|
|
||||||
->distinct()
|
|
||||||
->orderBy("sale_code")
|
|
||||||
->get()
|
|
||||||
->toArray();
|
|
||||||
|
|
||||||
$this->sendMessage(json_encode($aSaleCodeList, JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT));
|
|
||||||
|
|
||||||
Http::response(200, 'ok');
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
// 文章list
|
|
||||||
if (strpos($sText, '/ArticleList') === 0 || strpos($sText, '\/ArticleList') === 0) {
|
|
||||||
|
|
||||||
$aArticleList = Article::orderBy("user_name")->get()->toArray();
|
|
||||||
|
|
||||||
foreach ($aArticleList as $row) {
|
|
||||||
$this->sendMessage(json_encode($row, JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT));
|
|
||||||
}
|
|
||||||
|
|
||||||
Http::response(200, 'ok');
|
|
||||||
}
|
|
||||||
|
|
||||||
// 文章 like
|
|
||||||
// /ArticleLike__user_name xxx
|
|
||||||
if (strpos($sText, '/ArticleLike') === 0 || strpos($sText, '\/ArticleLike') === 0) {
|
|
||||||
|
|
||||||
list($sCmd, $sLike) = explode(" ", $sText);
|
|
||||||
list(, $sField) = explode("__", $sCmd);
|
|
||||||
|
|
||||||
$aArticleList = Article::where($sField, 'like', '%' . $sLike . '%')
|
|
||||||
->orderBy("user_name")
|
|
||||||
->get()
|
|
||||||
->toArray();
|
|
||||||
|
|
||||||
|
|
||||||
foreach ($aArticleList as $row) {
|
|
||||||
$this->sendMessage(json_encode($row, JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT));
|
|
||||||
}
|
|
||||||
|
|
||||||
Http::response(200, 'ok');
|
|
||||||
}
|
|
||||||
|
|
||||||
// 文章 add
|
|
||||||
if (strpos($sText, '/articleAdd') === 0 || strpos($sText, '\/articleAdd') === 0) {
|
|
||||||
|
|
||||||
list(, $sUserName) = explode(" ", $sText);
|
|
||||||
|
|
||||||
$newArticle = new Article();
|
|
||||||
$newArticle->user_name = $sUserName;
|
|
||||||
$r = $newArticle->save();
|
|
||||||
|
|
||||||
$this->sendMessage(json_encode($r, JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT));
|
|
||||||
|
|
||||||
Http::response(200, 'ok');
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
// 文章 del
|
|
||||||
if (strpos($sText, '/articleDel') === 0 || strpos($sText, '\/articleDel') === 0) {
|
|
||||||
|
|
||||||
list(, $iId) = explode(" ", $sText);
|
|
||||||
|
|
||||||
$article = Article::find($iId);
|
|
||||||
|
|
||||||
if ($article) {
|
|
||||||
$r = $article->delete();
|
|
||||||
} else {
|
|
||||||
$r = false;
|
|
||||||
}
|
|
||||||
|
|
||||||
$this->sendMessage(json_encode($r, JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT));
|
|
||||||
|
|
||||||
Http::response(200, 'ok');
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
// 文章 set
|
|
||||||
// /ArticleSet__id__user_name xxx
|
|
||||||
if (strpos($sText, '/ArticleSet') === 0 || strpos($sText, '\/ArticleSet') === 0) {
|
|
||||||
|
|
||||||
list($sCmd, $sSet) = explode(" ", $sText);
|
|
||||||
list(, $iId, $sField) = explode("__", $sCmd, 3);
|
|
||||||
|
|
||||||
$article = Article::find($iId);
|
|
||||||
|
|
||||||
if ($article) {
|
|
||||||
$article->$sField = $sSet;
|
|
||||||
|
|
||||||
$r = $article->save();
|
|
||||||
} else {
|
|
||||||
// 处理未找到的情况
|
|
||||||
}
|
|
||||||
|
|
||||||
$this->sendMessage(json_encode($r, JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT));
|
|
||||||
|
|
||||||
Http::response(200, 'ok');
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
private function sendMessage($sText = '?') {
|
|
||||||
|
|
||||||
if (env('is_loc') === true) {
|
|
||||||
echo "<pre>";
|
|
||||||
var_dump($sText);
|
|
||||||
} else {
|
|
||||||
$url = "https://api.telegram.org/bot$this->sApiToken/sendMessage?chat_id=$this->sApiChatId&text=" . urlencode($sText);
|
|
||||||
file_get_contents($url);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
@ -37,7 +37,7 @@ class TestsController
|
|||||||
'type' => 'private'
|
'type' => 'private'
|
||||||
],
|
],
|
||||||
'date' => 1610000000,
|
'date' => 1610000000,
|
||||||
"text" => "\/ArticleSet__7__user_name xxxzz",
|
"text" => "\/ArticleSet__5__sale_rate 1118.118",
|
||||||
]
|
]
|
||||||
];
|
];
|
||||||
|
|
||||||
|
|||||||
93
app/Services/TG/Hook/Article.php
Normal file
93
app/Services/TG/Hook/Article.php
Normal file
@ -0,0 +1,93 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Services\TG\Hook;
|
||||||
|
use App\Models\Article as ModelArticle;
|
||||||
|
//use App\Services\TomTool\Http;
|
||||||
|
|
||||||
|
class Article extends Base {
|
||||||
|
|
||||||
|
public function List()
|
||||||
|
{
|
||||||
|
$aArticleList = ModelArticle::orderBy("user_name")->get()->toArray();
|
||||||
|
|
||||||
|
foreach ($aArticleList as $row) {
|
||||||
|
$this->oTGHttp->sendToTG(json_encode($row, JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT));
|
||||||
|
}
|
||||||
|
|
||||||
|
$this->oHttp::response(200, 'ok');
|
||||||
|
}
|
||||||
|
|
||||||
|
public function Like($aParams)
|
||||||
|
{
|
||||||
|
|
||||||
|
$aArticleList = ModelArticle::where($this->cmdGood($aParams['aOption'][1]), 'like', '%' . $aParams['aArg'][1] . '%')
|
||||||
|
->orderBy("user_name")
|
||||||
|
->get()
|
||||||
|
->toArray();
|
||||||
|
|
||||||
|
if (empty($aArticleList)) {
|
||||||
|
$this->oTGHttp->sendToTG("没有");
|
||||||
|
}
|
||||||
|
|
||||||
|
foreach ($aArticleList as $row) {
|
||||||
|
$this->oTGHttp->sendToTG(json_encode($row, JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT));
|
||||||
|
}
|
||||||
|
|
||||||
|
$this->oHttp::response(200, 'ok');
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public function Add($aParams)
|
||||||
|
{
|
||||||
|
|
||||||
|
$newArticle = new ModelArticle();
|
||||||
|
$newArticle->user_name = $aParams['aArg'][1];
|
||||||
|
$r = $newArticle->save();
|
||||||
|
|
||||||
|
$this->oTGHttp->sendToTG(json_encode($r, JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT));
|
||||||
|
|
||||||
|
$this->oHttp::response(200, 'ok');
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public function Del($aParams)
|
||||||
|
{
|
||||||
|
|
||||||
|
$article = ModelArticle::find($aParams['aArg'][1]);
|
||||||
|
|
||||||
|
if ($article) {
|
||||||
|
$r = $article->delete();
|
||||||
|
} else {
|
||||||
|
$r = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
$this->oTGHttp->sendToTG(json_encode($r, JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT));
|
||||||
|
|
||||||
|
$this->oHttp::response(200, 'ok');
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
// /ArticleSet__id__user_name xxx
|
||||||
|
public function Set($aParams)
|
||||||
|
{
|
||||||
|
$sField = $this->cmdGood($aParams['aOption'][2]);
|
||||||
|
|
||||||
|
$article = ModelArticle::find($aParams['aOption'][1]);
|
||||||
|
|
||||||
|
$sSet = $aParams['aArg'][1];
|
||||||
|
|
||||||
|
if ($article) {
|
||||||
|
$article->$sField = $sSet;
|
||||||
|
|
||||||
|
$r = $article->save();
|
||||||
|
} else {
|
||||||
|
// 处理未找到的情况
|
||||||
|
throw new \Exception("Article not found");
|
||||||
|
}
|
||||||
|
|
||||||
|
$this->oTGHttp->sendToTG(json_encode($r, JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT));
|
||||||
|
|
||||||
|
$this->oHttp::response(200, 'ok');
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
53
app/Services/TG/Hook/Base.php
Normal file
53
app/Services/TG/Hook/Base.php
Normal file
@ -0,0 +1,53 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Services\TG\Hook;
|
||||||
|
//use App\Services\TomTool\Http;
|
||||||
|
//use App\Models\Article as ModelArticle;
|
||||||
|
use App\Services\TomTool\Http;
|
||||||
|
use App\Services\TG\Http as TGHttp;
|
||||||
|
|
||||||
|
class Base {
|
||||||
|
|
||||||
|
public function __construct() {
|
||||||
|
$this->oHttp = new Http();
|
||||||
|
$this->oTGHttp = new TGHttp();
|
||||||
|
}
|
||||||
|
|
||||||
|
// protected function sendMessage($sText = '?') {
|
||||||
|
//
|
||||||
|
// if (env('is_loc') === true) {
|
||||||
|
// echo "<pre>";
|
||||||
|
// var_dump($sText);
|
||||||
|
// } else {
|
||||||
|
// $url = "https://api.telegram.org/bot$this->sApiToken/sendMessage?chat_id=$this->sApiChatId&text=" . urlencode($sText);
|
||||||
|
// file_get_contents($url);
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
// }
|
||||||
|
|
||||||
|
protected function cmdGood($sCmd) {
|
||||||
|
|
||||||
|
$sCmdNew = "";
|
||||||
|
switch ($sCmd) {
|
||||||
|
case "user":
|
||||||
|
$sCmdNew = "user_name";
|
||||||
|
break;
|
||||||
|
case "project":
|
||||||
|
$sCmdNew = "project_name";
|
||||||
|
break;
|
||||||
|
case "code":
|
||||||
|
$sCmdNew = "sale_code";
|
||||||
|
break;
|
||||||
|
case "condition":
|
||||||
|
$sCmdNew = "cron_condition";
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
$sCmdNew = $sCmd;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
return $sCmdNew;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
28
app/Services/TG/Hook/Cmd.php
Normal file
28
app/Services/TG/Hook/Cmd.php
Normal file
@ -0,0 +1,28 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Services\TG\Hook;
|
||||||
|
use App\Models\Article as ModelArticle;
|
||||||
|
|
||||||
|
class Cmd extends Base {
|
||||||
|
|
||||||
|
public function List()
|
||||||
|
{
|
||||||
|
|
||||||
|
$aCmdList = [
|
||||||
|
'优惠码list' => '/SaleCode#List',
|
||||||
|
'优惠码find' => '/SaleCode#Find xxhh',
|
||||||
|
'优惠码rate' => '/SaleCode#SetRate__xxzz 6.7',
|
||||||
|
'文章list' => '/Article#List',
|
||||||
|
'文章like' => '/Article#Like__field like',
|
||||||
|
'文章add' => '/Article#Add__name',
|
||||||
|
'文章del' => '/Article#Del__id',
|
||||||
|
'文章set' => '/Article#Set__id__fild set',
|
||||||
|
];
|
||||||
|
|
||||||
|
$this->oTGHttp->sendToTG(json_encode($aCmdList, JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT));
|
||||||
|
|
||||||
|
$this->oHttp::response(200, 'ok');
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
48
app/Services/TG/Hook/SaleCode.php
Normal file
48
app/Services/TG/Hook/SaleCode.php
Normal file
@ -0,0 +1,48 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Services\TG\Hook;
|
||||||
|
use App\Models\Article as ModelArticle;
|
||||||
|
|
||||||
|
class SaleCode extends Base {
|
||||||
|
|
||||||
|
public function SetRate($aParams)
|
||||||
|
{
|
||||||
|
$updatedRows = ModelArticle::where('sale_code', $aParams['aOption'][1])
|
||||||
|
->update(['sale_rate' => $aParams['aArg'][1]]);
|
||||||
|
|
||||||
|
$this->oTGHttp->sendToTG(json_encode($updatedRows, JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT));
|
||||||
|
|
||||||
|
$this->oHttp::response(200, 'ok');
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public function List()
|
||||||
|
{
|
||||||
|
$aSaleCodeList = ModelArticle::select('sale_code', 'sale_rate')
|
||||||
|
->distinct()
|
||||||
|
->orderBy("sale_code")
|
||||||
|
->get()
|
||||||
|
->toArray();
|
||||||
|
|
||||||
|
$this->oTGHttp->sendToTG(json_encode($aSaleCodeList, JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT));
|
||||||
|
|
||||||
|
$this->oHttp::response(200, 'ok');
|
||||||
|
}
|
||||||
|
|
||||||
|
public function Find($aParams)
|
||||||
|
{
|
||||||
|
|
||||||
|
$aSaleCodeList = ModelArticle::select('sale_code', 'sale_rate')
|
||||||
|
->where("sale_code", $aParams['aArg'][1])
|
||||||
|
->distinct()
|
||||||
|
->orderBy("sale_code")
|
||||||
|
->get()
|
||||||
|
->toArray();
|
||||||
|
|
||||||
|
$this->oTGHttp->sendToTG(json_encode($aSaleCodeList, JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT));
|
||||||
|
|
||||||
|
$this->oHttp::response(200, 'ok');
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
23
app/Services/TG/Http.php
Normal file
23
app/Services/TG/Http.php
Normal file
@ -0,0 +1,23 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Services\TG;
|
||||||
|
|
||||||
|
class Http {
|
||||||
|
|
||||||
|
public $sApiToken;
|
||||||
|
public $sApiChatId;
|
||||||
|
|
||||||
|
public function sendToTG($sMsg)
|
||||||
|
{
|
||||||
|
|
||||||
|
if (env('is_loc') === true) {
|
||||||
|
echo "<pre>";
|
||||||
|
var_dump($sMsg);
|
||||||
|
} else {
|
||||||
|
$url = "https://api.telegram.org/bot$this->sApiToken/sendMessage?chat_id=$this->sApiChatId&text=" . urlencode($sText);
|
||||||
|
file_get_contents($url);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@ -4,6 +4,16 @@ use Illuminate\Http\Request;
|
|||||||
|
|
||||||
define('LARAVEL_START', microtime(true));
|
define('LARAVEL_START', microtime(true));
|
||||||
|
|
||||||
|
function tomd($d, $type)
|
||||||
|
{
|
||||||
|
echo "<pre>";
|
||||||
|
var_dump($d);
|
||||||
|
|
||||||
|
if ($type) {
|
||||||
|
exit;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Determine if the application is in maintenance mode...
|
// Determine if the application is in maintenance mode...
|
||||||
if (file_exists($maintenance = __DIR__.'/../storage/framework/maintenance.php')) {
|
if (file_exists($maintenance = __DIR__.'/../storage/framework/maintenance.php')) {
|
||||||
require $maintenance;
|
require $maintenance;
|
||||||
|
|||||||
@ -3,7 +3,7 @@
|
|||||||
use Illuminate\Support\Facades\Route;
|
use Illuminate\Support\Facades\Route;
|
||||||
use App\Http\Controllers\CronController;
|
use App\Http\Controllers\CronController;
|
||||||
use App\Http\Controllers\TestsController;
|
use App\Http\Controllers\TestsController;
|
||||||
use App\Http\Controllers\Api\Tg\HookController;
|
use App\Http\Controllers\Api\TG\HookController;
|
||||||
|
|
||||||
//Route::get('/', [ArticleListController::class, 'fn'])->middleware('test');
|
//Route::get('/', [ArticleListController::class, 'fn'])->middleware('test');
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user