dd/app/Services/Cron/ShadowRocketPublish.php
2026-07-29 15:40:37 +08:00

96 lines
3.8 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\Models\SiteMap;
use App\Models\Blade;
use App\Models\ShadowRocketIds;
use App\Services\TomTool\HttpV2;
use App\Services\TomTool\Telegram\Slave as TeleSlave;
use App\Services\Ship\ServiceShipHtml;
final class ShadowRocketPublish
{
public static function run()
{
$cSiteFnb = SiteMap::byGroupCode("fn_b");
$sBlade = Blade::where("code", "shadowRocketIds_a")->first()?->content;
$sShadowRocketIds = ShadowRocketIds::whereDate('created_at', date("Y-m-d"))->first()?->arr;
$aShadowRocketIds = json_decode($sShadowRocketIds, true);
$iShadowRocketIdsCount = count($aShadowRocketIds);
foreach ($cSiteFnb as $oSiteFnb) {
$sArticle = $sBlade;
$aSiteConfig = json_decode($oSiteFnb->config, true);
$sShip = ServiceShipHtml::byShipCode($aSiteConfig['ship_code']);
$aShadowRocketIdsHtml = [];
foreach ($aShadowRocketIds as $a) {
$s = "";
$s .= "<p>";
$s .= '账号:<a href="javascript:;" data-clipboard-text="'.$a['sEmail'].'" class="copy-permalink"><span class="subCopy"><i class="iconfont icon-link"></i> '.$a['sEmail'].'</span></a>';
$s .= '密码:<a href="javascript:;" data-clipboard-text="'.$a['sPassword'].'" class="copy-permalink"><span class="subCopy"><i class="iconfont icon-link"></i> '.$a['sPassword'].'</span></a>';
$s .= "地区:".$a['sRegion'].",检测时间:<span style='color:lightseagreen;'>".$a['sCheckTime'].'</span>';
$s .= "</p>";
$aShadowRocketIdsHtml[] = $s;
}
$sShadowRocketIdsHtml = implode("\n\n", $aShadowRocketIdsHtml);
$aFilter = [
'{$sContent}' => $sShadowRocketIdsHtml,
'{$sShip}' => $sShip,
'{$sTgHref}' => $aSiteConfig['telegram'],
'{$sGithubHref}' => $aSiteConfig['github'] ?? ''
];
$sArticle = self::nl2p(str_replace(array_keys($aFilter), array_values($aFilter), $sArticle));
$aResult = [
"content" => $sArticle,
"title" => '「'.date("n月j日").'」'.date("Y").'年最新免费苹果账号小火箭账号、shadowrocket id',
"title_sub" => "本次更新共{$iShadowRocketIdsCount}个免费苹果账号可用于使用小火箭shadowrocket",
"tags" => ["ios", "shadowrocket", "小火箭", "小火箭账号", "shadowrocket id", "免费苹果账号"],
"7like" => 9
];
$aApiPath = json_decode($oSiteFnb->api_path, true);
$sArticleReceiveShadowrocketids = "https://".$oSiteFnb->url."/".$aApiPath["article_receive_shadowrocketids"];
$sFlow = HttpV2::make($sArticleReceiveShadowrocketids, "post")->setDataA($aResult)->send();
$aFlow = json_decode($sFlow, true);
if (!isset($aFlow["isDone"]) || !$aFlow["isDone"]) {
echo $sFlow;
TeleSlave::warn()->send('ShadowRocketPublish::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);
}
}