no message
This commit is contained in:
1 parent
f83b20b3ff
commit
cf9f9113b4
7 files changed
+208
-41
No files matched your search
@@ -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,47 +63,68 @@ final class HookController
|
||||
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) {
|
||||
|
||||
$number = $responseParts[0]; // 提取数字部分
|
||||
$variableText = $responseParts[1]; // 提取用户输入的文本
|
||||
|
||||
$oHttp = new Http();
|
||||
|
||||
$oHttp->sMethod = "put";
|
||||
$oHttp->sToUrl = $_ENV['baseUrl']."/api/tg/ticket/".$number;
|
||||
$oHttp->bIsJson = true;
|
||||
$aData['comment'] = $variableText;
|
||||
$aData['admin_name'] = $aUpdate["message"]["from"]["first_name"];
|
||||
$oHttp->aData = $aData;
|
||||
|
||||
$r = @json_decode($oHttp->send(), true);
|
||||
|
||||
if ($r["ret"] == 1) {
|
||||
$sMessage = "成功";
|
||||
} else {
|
||||
$sMessage = "失败";
|
||||
}
|
||||
|
||||
$this->sendMessage($sMessage);
|
||||
|
||||
}
|
||||
if ($sText === "/break") {
|
||||
|
||||
$this->sendMessage("ok");
|
||||
|
||||
http_response_code(200);exit;
|
||||
}
|
||||
|
||||
http_response_code(200);exit;
|
||||
if (strpos($sText, '/reply') === 0) {
|
||||
|
||||
$oTgStep->clearByFromId($aData["fromId"]);
|
||||
|
||||
$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/".$aTgStepFirst['cache']['ticketId'];
|
||||
$oHttp->bIsJson = true;
|
||||
$aData['comment'] = $sText;
|
||||
$aData['admin_name'] = $aUpdate["message"]["from"]["first_name"];
|
||||
$oHttp->aData = $aData;
|
||||
|
||||
$r = @json_decode($oHttp->send(), true);
|
||||
|
||||
if ($r["ret"] == 1) {
|
||||
$sMessage = "成功";
|
||||
} else {
|
||||
$sMessage = "失败";
|
||||
Http::response(500, json_encode($aData));
|
||||
}
|
||||
|
||||
$this->sendMessage($sMessage);
|
||||
|
||||
Http::response(200, 'ok');
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Http::response(200, 'ok');
|
||||
|
||||
}
|
||||
|
||||
// 发送消息的函数
|
||||
public function sendMessage($sText) {
|
||||
|
||||
if ($_ENV['is_loc'] === true) {
|
||||
|
||||
Reference in new issue
Block a user