no message
This commit is contained in:
parent
f83b20b3ff
commit
cf9f9113b4
@ -50,7 +50,12 @@ return static function (Slim\App $app): void {
|
||||
})->add(new TgAdmin());
|
||||
|
||||
// test
|
||||
$app->get('/test', App\Controllers\TestController::class . ':index');
|
||||
$app->get('/test1', App\Controllers\TestController::class . ':test1');
|
||||
$app->get('/test2', App\Controllers\TestController::class . ':test2');
|
||||
$app->get('/test3', App\Controllers\TestController::class . ':test3');
|
||||
$app->get('/test4', App\Controllers\TestController::class . ':test4');
|
||||
$app->get('/test5', App\Controllers\TestController::class . ':test5');
|
||||
$app->get('/test6', App\Controllers\TestController::class . ':test6');
|
||||
|
||||
// doc
|
||||
$app->group('/doc', static function (RouteCollectorProxy $group): void {
|
||||
|
||||
@ -12,6 +12,7 @@ $oHttp = new App\Services\TomTool\Http();
|
||||
|
||||
$oHttp->sMethod = "post";
|
||||
$oHttp->sToUrl = $_ENV['baseUrl']."/api/tg/hook";
|
||||
//$oHttp->sToUrl = 'https://fuc.loc/test3';
|
||||
$oHttp->bIsJson = true;
|
||||
//$oHttp->aData[]
|
||||
$oHttp->aData = [
|
||||
@ -34,7 +35,7 @@ $oHttp->aData = [
|
||||
'type' => 'private'
|
||||
],
|
||||
'date' => 1610000000,
|
||||
'text' => '/reply 62 哈哈哈哈哈哈哈哈哈哈你麻痹'
|
||||
'text' => '222'
|
||||
]
|
||||
];
|
||||
|
||||
@ -47,6 +48,7 @@ exit;
|
||||
|
||||
|
||||
$url = 'https://fuc.loc/api/tg/hook';
|
||||
$url = 'https://fuc.loc/test3';
|
||||
$data = [
|
||||
'message' => [
|
||||
'chat' => [
|
||||
|
||||
@ -16,9 +16,73 @@ use App\Models\UserCoupon;
|
||||
use App\Services\Cron as CronService;
|
||||
use App\Services\Reward;
|
||||
|
||||
use App\Services\TomTool\Http;
|
||||
|
||||
|
||||
session_start();
|
||||
|
||||
final class TestController extends BaseController
|
||||
{
|
||||
public function index(ServerRequest $request, Response $response, array $args): ResponseInterface
|
||||
|
||||
public function test4 ()
|
||||
{
|
||||
// session_start();
|
||||
|
||||
$oHttp = new Http();
|
||||
|
||||
$oHttp->sMethod = "get";
|
||||
$oHttp->sToUrl = $_ENV['baseUrl']."/api/tg/hook";
|
||||
$oHttp->sToUrl = 'https://fuc.loc/test3';
|
||||
// $oHttp->bIsJson = true;
|
||||
//$oHttp->aData[]
|
||||
$oHttp->aData = [
|
||||
'update_id' => 123456789,
|
||||
'message' => [
|
||||
'message_id' => 1,
|
||||
'from' => [
|
||||
'id' => 987654321,
|
||||
'is_bot' => false,
|
||||
'first_name' => 'John',
|
||||
'last_name' => 'Doe',
|
||||
'username' => 'johndoe',
|
||||
'language_code' => 'en'
|
||||
],
|
||||
'chat' => [
|
||||
'id' => -4668400285,
|
||||
'first_name' => 'John',
|
||||
'last_name' => 'Doe',
|
||||
'username' => 'johndoe',
|
||||
'type' => 'private'
|
||||
],
|
||||
'date' => 1610000000,
|
||||
'text' => '22'
|
||||
]
|
||||
];
|
||||
|
||||
$r = $oHttp->send();
|
||||
|
||||
var_dump($r);
|
||||
exit;
|
||||
}
|
||||
|
||||
public function test2()
|
||||
{
|
||||
|
||||
$_SESSION['test'] = 333;
|
||||
var_dump($_SESSION);
|
||||
|
||||
http_response_code(200);exit;
|
||||
}
|
||||
|
||||
public function test3()
|
||||
{
|
||||
|
||||
var_dump($_SESSION);
|
||||
|
||||
http_response_code(200);exit;
|
||||
}
|
||||
|
||||
public function test1(ServerRequest $request, Response $response, array $args): ResponseInterface
|
||||
{
|
||||
|
||||
error_reporting(E_ALL); // 报告所有错误
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
//declare(strict_types=1);
|
||||
|
||||
namespace App\Controllers\TomApi\Tg;
|
||||
|
||||
@ -10,11 +10,12 @@ namespace App\Controllers\TomApi\Tg;
|
||||
//use Slim\Http\ServerRequest;
|
||||
|
||||
use App\Models\Config;
|
||||
use App\Models\TgStep;
|
||||
//use GuzzleHttp\Psr7\ServerRequest;
|
||||
//use GuzzleHttp\Psr7\Utils;
|
||||
//use Psr\Http\Message\ResponseInterface;
|
||||
//use Slim\Http\Response;
|
||||
use Exception;
|
||||
//use Exception;
|
||||
use GuzzleHttp\Exception\GuzzleException;
|
||||
use Psr\Http\Client\ClientExceptionInterface;
|
||||
use Psr\Http\Message\ResponseInterface;
|
||||
@ -31,6 +32,8 @@ final class HookController
|
||||
|
||||
public function cmd()
|
||||
{
|
||||
$oTgStep = new TgStep();
|
||||
|
||||
$this->sApiToken = Config::obtain('telegram_token');
|
||||
$this->sApiChatId = Config::obtain('telegram_chatid');
|
||||
|
||||
@ -38,9 +41,10 @@ final class HookController
|
||||
|
||||
$aUpdate = json_decode($sUpdate, true);
|
||||
|
||||
file_put_contents('/www/_tg/bot_log.txt', json_encode($aUpdate, JSON_PRETTY_PRINT));
|
||||
@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);
|
||||
@ -59,24 +63,43 @@ final class HookController
|
||||
http_response_code(200);exit;
|
||||
}
|
||||
|
||||
if ($sText === "/break") {
|
||||
|
||||
$this->sendMessage("ok");
|
||||
|
||||
http_response_code(200);exit;
|
||||
}
|
||||
|
||||
if (strpos($sText, '/reply') === 0) {
|
||||
// 去掉 /reply 字符串
|
||||
$responseText = str_replace('/reply', '', $sText); // 直接去掉 /reply
|
||||
$responseText = trim($responseText); // 去掉前后的空格
|
||||
|
||||
// 使用空格分割内容
|
||||
$responseParts = explode(' ', $responseText, 2); // 分割成两部分
|
||||
if (count($responseParts) == 2) {
|
||||
$oTgStep->clearByFromId($aData["fromId"]);
|
||||
|
||||
$number = $responseParts[0]; // 提取数字部分
|
||||
$variableText = $responseParts[1]; // 提取用户输入的文本
|
||||
$iTicketId = str_replace('/reply', '', $sText);
|
||||
$iTicketId = (int) trim($iTicketId);
|
||||
|
||||
$oTgStep->add($aData['fromId'], 'reply', 1, ["ticketId" => $iTicketId]);
|
||||
|
||||
$sMessage = "将回复工单【".$iTicketId."】,请输入回复内容。";
|
||||
|
||||
$this->sendMessage($sMessage);
|
||||
|
||||
Http::response(200, 'ok');
|
||||
|
||||
}
|
||||
|
||||
if ($oTgStep->fromIdHit($aData['fromId'])) {
|
||||
|
||||
$aTgStepFirst = $oTgStep->find($aData["fromId"]);
|
||||
|
||||
if ($aTgStepFirst["cmd"] == "reply") {
|
||||
|
||||
if ($aTgStepFirst['step'] == 1) {
|
||||
$oHttp = new Http();
|
||||
|
||||
$oHttp->sMethod = "put";
|
||||
$oHttp->sToUrl = $_ENV['baseUrl']."/api/tg/ticket/".$number;
|
||||
$oHttp->sToUrl = $_ENV['baseUrl']."/api/tg/ticket/".$aTgStepFirst['cache']['ticketId'];
|
||||
$oHttp->bIsJson = true;
|
||||
$aData['comment'] = $variableText;
|
||||
$aData['comment'] = $sText;
|
||||
$aData['admin_name'] = $aUpdate["message"]["from"]["first_name"];
|
||||
$oHttp->aData = $aData;
|
||||
|
||||
@ -86,20 +109,22 @@ final class HookController
|
||||
$sMessage = "成功";
|
||||
} else {
|
||||
$sMessage = "失败";
|
||||
Http::response(500, json_encode($aData));
|
||||
}
|
||||
|
||||
$this->sendMessage($sMessage);
|
||||
|
||||
Http::response(200, 'ok');
|
||||
}
|
||||
|
||||
http_response_code(200);exit;
|
||||
}
|
||||
|
||||
http_response_code(200);exit;
|
||||
|
||||
}
|
||||
|
||||
// 发送消息的函数
|
||||
}
|
||||
|
||||
Http::response(200, 'ok');
|
||||
|
||||
}
|
||||
|
||||
public function sendMessage($sText) {
|
||||
|
||||
if ($_ENV['is_loc'] === true) {
|
||||
|
||||
65
src/Models/TgStep.php
Executable file
65
src/Models/TgStep.php
Executable file
@ -0,0 +1,65 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Query\Builder;
|
||||
|
||||
final class TgStep extends Model
|
||||
{
|
||||
protected $connection = 'default';
|
||||
protected $table = 'tg_step';
|
||||
|
||||
public function add($iFromId, $sCmd, $iStep, $sCache = [])
|
||||
{
|
||||
|
||||
$oTgStep = new TgStep();
|
||||
|
||||
$oTgStep->from_id = $iFromId;
|
||||
$oTgStep->cmd = $sCmd;
|
||||
$oTgStep->step = $iStep;
|
||||
$oTgStep->cache = json_encode($sCache);
|
||||
|
||||
$oTgStep->save();
|
||||
|
||||
}
|
||||
|
||||
public function fromIdHit($iFromId)
|
||||
{
|
||||
return TgStep::where('from_id', $iFromId)->exists();
|
||||
}
|
||||
|
||||
public function find($iFromId, $iStep = false, $sCmd = false)
|
||||
{
|
||||
$oTgStep = new TgStep();
|
||||
|
||||
$oTgStep->where("from_id", $iFromId);
|
||||
|
||||
if ($iStep) {
|
||||
$oTgStep->where("step", $iStep);
|
||||
}
|
||||
|
||||
if ($sCmd) {
|
||||
$oTgStep->where("cmd", $sCmd);
|
||||
}
|
||||
|
||||
$aData = $oTgStep->orderBy("step", "desc")->first()->toArray();
|
||||
|
||||
$aData['cache'] = json_decode($aData['cache'], true);
|
||||
|
||||
return $aData;
|
||||
}
|
||||
|
||||
public function clearByFromId($iFromId)
|
||||
{
|
||||
$oTgStep = new TgStep();
|
||||
|
||||
return $oTgStep->where("from_id", $iFromId)->delete();
|
||||
}
|
||||
|
||||
public function clearAll()
|
||||
{
|
||||
return TgStep::delete();
|
||||
}
|
||||
}
|
||||
@ -5,7 +5,6 @@ declare(strict_types=1);
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Query\Builder;
|
||||
use function time;
|
||||
|
||||
final class Zhuanfas extends Model
|
||||
{
|
||||
|
||||
@ -73,4 +73,11 @@ class Http
|
||||
// 返回响应
|
||||
return $response;
|
||||
}
|
||||
|
||||
public static function response($iCode, $sMsg = '')
|
||||
{
|
||||
http_response_code($iCode);
|
||||
echo $sMsg;
|
||||
exit;
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user