dd/app/Services/Cron/FnSitePublish.php
2026-07-28 18:23:02 +08:00

131 lines
4.5 KiB
PHP
Executable File

<?php
declare(strict_types=1);
namespace App\Services\Cron;
use App\Services\TomTool\Telegram\Slave as TeleSlave;
use App\Models\SiteMap as ModelSiteMap;
use App\Services\TomTool\HttpV2;
use App\Models\ArticleTemplateFreenode;
use Illuminate\Support\Carbon;
use App\Services\CountrySpeedService;
use App\Models\Ship;
use App\Services\FreenodeHelperService;
use App\Services\Ship\ServiceShipHtml;
final class FnSitePublish
{
public static function fn_b()
{
echo "\n\nFnSitePublish::fn_b()";
$oSites = ModelSiteMap::where("group_code", "fn_b")->get();
$oDate = Carbon::now();
$sDateCN = $oDate->format('n月j日');
$sYear = date("Y");
$sCountrySpeed = CountrySpeedService::fn_b();
$sToken = FreenodeHelperService::tokenToday();
$aTags = [
"Shadowrocket",
"Quantumult",
"Clash",
"Hiddify",
"SingBox",
"SSR",
"节点",
"订阅链接",
"免费节点",
"V2ray",
"SSR",
];
$aResult = [];
$aResult["site_code_short"] = '';
$aResult["article"] = [
"title" => "",
"title_sub" => "",
"content" => "",
"tags" => $aTags,
"7like" => rand(5, 55),
];
foreach ($oSites as $oSite) {
$aResult["site_code_short"] = $oSite->code_short;
$oArticleTemplate = ArticleTemplateFreenode::where("group_code", $oSite->group_code)->first();
$aSiteConfig = json_decode($oSite->config, true);
$sTelegramLink = $aSiteConfig["telegram"];
$aShipCode = $aSiteConfig["ship_code"];
$aSiteFnClient = $aSiteConfig["freenode_client"];
$aDylj = [];
foreach ($aSiteFnClient as $sSiteFnClient) {
$sFeedLink = "https://".FreenodeHelperService::urlFeedToday($oSite->code_short, $sSiteFnClient);
$str = "";
$str .= "<b>".$sSiteFnClient."订阅链接:</b>\n\n";
$str .= "<a href='javascript:;' data-clipboard-text='".$sFeedLink."' class='copy-permalink'>
<span class='subCopy'><i class='iconfont icon-link'></i> ".$sFeedLink."</span></a>";
$aDylj[$sSiteFnClient] = $str;
}
$sDylj = implode("\n\n", $aDylj);
$sJctj = ServiceShipHtml::byShipCode($aSiteConfig['ship_code']);
$aFilter = [
// '$sShipWww' => $oShip->www,
// '$sShipName' => $oShip->name,
'$sDateCN' => $sDateCN,
'$sYear' => $sYear,
'$sTitleSub' => $sCountrySpeed,
'$sTelegramLink'=> $sTelegramLink,
'$sCountrySpeed'=> $sCountrySpeed,
'$sJctj' => $sJctj,
'$sDylj' => $sDylj,
'$sGithubLink' => $aSiteConfig['github'] ?? '',
'$sSiteUrl' => $oSite->url
];
$aResult["article"]["content"] = self::nl2p(str_replace(array_keys($aFilter), array_values($aFilter), $oArticleTemplate->content));
$aResult["article"]["title"] = str_replace(array_keys($aFilter), array_values($aFilter), $oArticleTemplate->title);
$aResult["article"]["title_sub"] = $sCountrySpeed;
// todo 发送文章
$aApiPath = json_decode($oSite->api_path, true);
$sArticleReceiveFreenode = "https://".$oSite->url."/".$aApiPath["article_receive_freenode"];
$sFlow = HttpV2::make($sArticleReceiveFreenode, "post")->setDataA($aResult)->send();
$aFlow = json_decode($sFlow, true);
if (!isset($aFlow["isDone"]) || !$aFlow["isDone"]) {
echo $sFlow;
TeleSlave::warn()->send('FnSitePublish::fn_b()的发送文章失败');
continue;
}
}
echo "/n - ok";
}
public static function nl2p($text) {
// 将文本按换行符拆分成数组
$paragraphs = explode("\n", $text);
// 将每一段用 <p> 标签包裹
$paragraphs = array_map(function($paragraph) {
return '<p>' . trim($paragraph) . '</p>';
}, $paragraphs);
// 使用 implode 拼接成一个字符串
return implode('', $paragraphs);
}
}