diff --git a/app/Http/Controllers/CronController.php b/app/Http/Controllers/CronController.php index 1bebeba..0cfbeef 100755 --- a/app/Http/Controllers/CronController.php +++ b/app/Http/Controllers/CronController.php @@ -29,6 +29,72 @@ class CronController private $sPull = "y"; + private function lifeToTg($h, $i, $s) + { + $oHttpTg = new TGHttp(); + + if ($h == "08" && $i == "00") { + $oArticle = Article::where("status", 1)->get(); + + $aMsg = []; + foreach ($oArticle as $oArticleRow) { + $sMsgR = $this->_lifeToTg($oArticleRow); + $aMsg[] = $sMsgR; + } + + $oHttpTg->send($aMsg); + } + } + + private function _lifeToTg($oArticle) + { + $oHttp = new Http(); + $oHttp->sToUrl = "https://api.github.com/repos/".$oArticle->user_name."/".$oArticle->project_name; + $oHttp->sMethod = "get"; + $r = $oHttp->send(); + + $sMsg = "?"; + + if (!$r) { + $oHttpTg = new TGHttp(); + $oHttpTg->send("请求github的api失败??"); + } + + $aGitHub = json_decode($r, true); + + if (isset($aGitHub["status"]) && $aGitHub["status"] == "404") { + $aMsg["msg"] = "嘎了~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"; + $aMsg["article"] = $oArticle; + $sMsg = json_encode($aMsg, JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT); + return $sMsg; + } + + $tmp = str_replace("T", " ", rtrim($aGitHub["updated_at"], "Z")); //updated_at, pushed_at + $tmp = strtotime($tmp); + $tmpDate = date("Y-m-d H:i:s", $tmp + (8 * 3600)); + $tmpTime = strtotime($tmpDate); + $tmpNowTime = time(); + $tmpDiff = $tmpNowTime - $tmpTime; + $iLastUpdate = ceil($tmpDiff / 60); + + $aGitHubNew = []; + $aGitHubNew["⭐️星星"] = $aGitHub["stargazers_count"]; + $aGitHubNew["♻️最后更新"] = $iLastUpdate."分钟前"; // 替换T为空格并去掉Z + $aGitHubNew["forks"] = $aGitHub["forks_count"]; + $aGitHubNew["watchers"] = $aGitHub["watchers_count"]; + $aGitHubNew["url"] = $this->urlFormat($aGitHub["html_url"]); + + $sMsg = json_encode($aGitHubNew, JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT); + + return $sMsg; + } + + public function urlFormat($sUrl) + { + $sUrlNew = str_replace('/', '$', $sUrl); + return $sUrlNew; + } + public function index() { try { @@ -41,7 +107,7 @@ class CronController // $bSendTg = true; // $isTest = 0; - //test + //// test $aGet = $_GET; if (isset($aGet['is_test']) && $aGet['is_test'] == 1) { $isTest = 1; @@ -57,6 +123,11 @@ class CronController $iTestId = $aGet["v"]; } } + //// test + $h = "08"; + $i = "00"; + + $this->lifeToTg($h, $i, $s); if (isset($aGet["sSendTg"])) { $this->sSendTg = $aGet["sSendTg"];