dd/app/Services/Cron/HttpQueue.php
2026-01-02 19:10:22 +08:00

92 lines
3.1 KiB
PHP
Executable File
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<?php
declare(strict_types=1);
namespace App\Services\Cron;
//use App\Services\Cron;
use App\Models\HttpQueue as ModelHttpQueue;
use App\Services\TomTool\Telegram\Master as TelegramMaster;
use App\Services\TomTool\Telegram\Slave as TelegramSlave;
use App\Services\TomTool\HttpV2;
use Telegram\Bot\Api;
//use Telegram\Bot\Exceptions\TelegramSDKException;
use Telegram\Bot\Exceptions\TelegramSDKException;
use Telegram\Bot\Exceptions\TelegramResponse;
final class HttpQueue
{
public static function pop()
{
echo "\nhttpQueue::pop - 开始\n";
$oHttpQueue = ModelHttpQueue::where("status", 1)->get();
foreach ($oHttpQueue as $oHttpQueueRow) {
$aArg = json_decode($oHttpQueueRow->arg, true);
$sBotCode = $aArg["sBotCode"] ?? '';
$sChatCode = $aArg["sChatCode"] ?? '';
$sBotToken = $aArg["sBotToken"] ?? '';
$iChatId = $aArg["iChatId"] ?? 0;
$sMsg = $aArg["sMsg"] ?? '';
$sPhotoUrl = $aArg["sPhotoUrl"] ?? '';
$iPhotoWidth = $aArg["iPhotoWidth"] ?? 0;
$iPhotoHeight = $aArg["iPhotoHeight"] ?? 0;
$enableMaster = $aArg["enableMaster"] ?? null;
$sType = $aArg["sType"] ?? '';
if ($enableMaster) {
$oTgSlave = TelegramSlave::start()
->enableDetail(false)
->enableMaster(true)
->enableAsync(false)
->enableSlaveQueue(false)
->setBotCode($sBotCode)
->setChatCode($sChatCode)
->setBotToken($sBotToken)
->setChatId($iChatId)
->setMsgS($sMsg)
->setPhotoUrl($sPhotoUrl, $iPhotoWidth, $iPhotoHeight)
->setType($sType)
->send();
if ($oTgSlave->isFail()) {
echo "失败从telegram_local发送到master失败\n";
var_dump($oTgSlave->getResult());
continue;
}
echo "发送到master成功\n";
} else { // 直接发送到tg必须有token和id
$oTgSlave = TelegramSlave::start()
->enableDetail(false)
->enableMaster(false)
->setBotCode($sBotCode)
->setChatCode($sChatCode)
->setBotToken($sBotToken)
->setChatId($iChatId)
->setMsgS($sMsg)
->setPhotoUrl($sPhotoUrl, $iPhotoWidth, $iPhotoHeight)
->setType($sType)
->send();
if ($oTgSlave->isFail()) {
echo "失败从telegram_local发送到tg失败\n";
var_dump($oTgSlave->getResult());
continue;
}
echo "发送到tg成功\n";
}
$oHttpQueueRow->delete();
}
echo "ok\n";
}
}