128 lines
3.9 KiB
PHP
128 lines
3.9 KiB
PHP
<?php
|
||
|
||
namespace App\Services\Github;
|
||
use App\Services\TomTool\Http;
|
||
|
||
class Github {
|
||
|
||
public static function GetReadMe($aArticle)
|
||
{
|
||
list($sClassDir, $sClass) = explode('#', $aArticle['mod']);
|
||
|
||
// $sClass = "App\\Services\\Github\\Mod\\".$sClass;
|
||
$sClass = "App\\Services\\Github\\Mod\\".$sClassDir."\\".$sClass;
|
||
|
||
$sFunc = "Get";
|
||
|
||
if (method_exists($sClass, $sFunc)) {
|
||
// tomd($sClass, 1);
|
||
$oInstans = new $sClass();
|
||
// $oInstans->aHuodong = self::GetHuodong($aArticle);
|
||
|
||
$aShip = self::GetShip($aArticle);
|
||
|
||
$oInstans->aShip = $aShip; // 之前脑残了,这个思路傻逼,直接补充$aArticle就行了
|
||
|
||
$aArticle = self::ArticleEx($aArticle, $aShip); // 难看就难看吧,兼容一下
|
||
|
||
$sReadMe = $oInstans->$sFunc($aArticle);
|
||
|
||
return $sReadMe;
|
||
|
||
} else {
|
||
// 模版里可以返回false,但不能没有模版
|
||
throw new \Exception("没找到这个模版:".$sClass."\\".$sFunc);
|
||
}
|
||
|
||
}
|
||
|
||
|
||
// 扩展都往里这里来
|
||
public static function ArticleEx($aArticle, $aShip)
|
||
{
|
||
$aArticle["ex_feed_v2ray_url"] = "https://".$aArticle["fn_www"]."/feed/v2ray-".date("Ymd").".txt";
|
||
$aArticle["ex_feed_clash_url"] = "https://".$aArticle["fn_www"]."/clash/v2ray-".date("Ymd").".yaml";
|
||
|
||
$aArticle["ex_ship"] = $aShip;
|
||
$aArticle["ex_ship_name"] = $aShip["name"];
|
||
$aArticle["ex_ship_www"] = $aShip["www"];
|
||
|
||
return $aArticle;
|
||
}
|
||
|
||
public static function GetShip($aArticle)
|
||
{
|
||
$oHttp = new Http();
|
||
|
||
$sDateNow = date("Y-m-d");
|
||
|
||
$sMasterUrl = "https://".env("www_master")."/api/ship/get/".$aArticle["ship_code"]."/github/".$aArticle["user_name"]."-".$aArticle["project_name"];
|
||
|
||
$sShip = $oHttp->send($sMasterUrl);
|
||
$aShip = json_decode($sShip, true);
|
||
|
||
$aGood = json_decode($aShip["good"], true);
|
||
// tomd($aShip, 1);
|
||
$sGoodStr = "";
|
||
$i = 0;
|
||
foreach ($aGood as $row) {
|
||
if ($i !== 0) {
|
||
$sGoodStr .= "
|
||
|
||
";
|
||
}
|
||
$sGoodStr .= $row;
|
||
$i++;
|
||
}
|
||
|
||
$aShip["good_str"] = $sGoodStr;
|
||
|
||
$aShip["youhui_str"] = "购买套餐时输入【".$aArticle['sale_code']."】优惠码,可享".$aArticle['sale_rate']."折优惠,折后低至8元/月。";
|
||
|
||
if (isset($aShip["huodong"]["str"]) && !empty($aShip["huodong"]["str"])) {
|
||
$aShip["youhui_str"] .= "
|
||
|
||
".$aShip["huodong"]["str"];
|
||
}
|
||
|
||
return $aShip;
|
||
}
|
||
|
||
// public static GetFeedV2ray($aArticle)
|
||
// {
|
||
//
|
||
// }
|
||
|
||
|
||
// public static function GetHuodong($aArticle)
|
||
// {
|
||
//
|
||
// $oHttp = new Http();
|
||
//
|
||
// $sDateNow = date("Y-m-d");
|
||
//// $sDateNow = "2025-05-03";
|
||
//
|
||
// $sHuodongUrl = env('api_url_jichang_base').'/'.'api/huodong/findbydate/'.$sDateNow;
|
||
// $sHuodong = $oHttp->send($sHuodongUrl);
|
||
// $oHuodong = json_decode($sHuodong, 1);
|
||
//
|
||
// $sHuodongStr = "购买套餐时输入【".$aArticle['sale_code']."】优惠码,可享".$aArticle['sale_rate']."折优惠,折后低至8元/月。";
|
||
//
|
||
// if ($oHuodong) {
|
||
// $sStartDateStr = date("n月j日", strtotime($oHuodong['start_date']));
|
||
// $sEndDateStr = date("n月j日", strtotime($oHuodong['end_date']));
|
||
//
|
||
// $sHuodongStr .= "
|
||
//
|
||
//🎁 ".$oHuodong['title'].":".$sStartDateStr."至".$sEndDateStr."期间,".$oHuodong['content'];
|
||
//
|
||
// }
|
||
//
|
||
// $oHuodong['str'] = $sHuodongStr;
|
||
//
|
||
// return $oHuodong;
|
||
//
|
||
// }
|
||
|
||
}
|