2025年04月16日 13:56:44

 siteurl . '/api/greader.php/accounts/ClientLogin?' . 

 http_build_query([

 'Email' => $this->user,

 'Passwd' => $this->password

 ]);



 $response = file_get_contents($loginUrl);

 if ($response === false) {

 throw new Exception('Login failed');

 }



 if (preg_match('/Auth=(.*)/', $response, $matches)) {

 $this->authToken = $matches[1];

 return true;

 }

 return false;

 }



 // 获取文章列表

 public function fetchArticles() {

 $articlesUrl = $this->siteurl . '/api/greader.php/reader/api/0/stream/contents/reading-list?&n=1000';

 $context = stream_context_create([

 'http' => [

 'method' => 'GET',

 'header' => "Authorization: GoogleLogin auth=" . $this->authToken

 ]

 ]);



 $response = file_get_contents($articlesUrl, false, $context);

 if ($response === false) {

 throw new Exception('Failed to fetch articles');

 }



 $data = json_decode($response, true);

 return $data['items'] ?? [];

 }



 // 获取订阅列表

 public function fetchSubscriptions() {

 $subscriptionsUrl = $this->siteurl . '/api/greader.php/reader/api/0/subscription/list?output=json';

 $context = stream_context_create([

 'http' => [

 'method' => 'GET',

 'header' => "Authorization: GoogleLogin auth=" . $this->authToken

 ]

 ]);



 $response = file_get_contents($subscriptionsUrl, false, $context);

 if ($response === false) {

 throw new Exception('Failed to fetch subscriptions');

 }



 $data = json_decode($response, true);

 return $data['subscriptions'] ?? [];

 }



 // 格式化文章数据

 private function formatArticles($articles, $subscriptions) {

 $subscriptionMap = [];

 foreach ($subscriptions as $subscription) {

 $subscriptionMap[$subscription['id']] = $subscription;

 }



 $formattedArticles = [];

 foreach ($articles as $article) {

 $strippedContent = strip_tags($article['summary']['content']);

 $short_desc = (strlen($strippedContent) > 99) 

 ? substr($strippedContent, 0, 99) . '...' 

 : $strippedContent;



 $subscriptionId = $article['origin']['streamId'];

 $subscription = $subscriptionMap[$subscriptionId] ?? null;



 $formattedArticles[] = [

 'site_name' => $article['origin']['title'],

 'title' => $article['title'],

 'link' => $article['alternate'][0]['href'],

 'time' => date('c', $article['published']),

 'description' => $short_desc,

 'icon' => $subscription 

 ? $this->siteurl . '/' . basename($subscription['iconUrl'])

 : ''

 ];

 }



 return $formattedArticles;

 }



 // 获取并处理所有数据

 public function getAllArticles() {

 try {

 if (!$this->login()) {

 throw new Exception('Login failed');

 }



 $articles = $this->fetchArticles();

 $subscriptions = $this->fetchSubscriptions();

 return $this->formatArticles($articles, $subscriptions);

 } catch (Exception $e) {

 error_log($e->getMessage());

 return [];

 }

 }

}



// 使用类获取数据并显示

try {

 $api = new FreshRSSAPI();

 $articles = $api->getAllArticles();



 // 对文章按时间排序

 usort($articles, function ($a, $b) {

 return strtotime($b['time']) - strtotime($a['time']);

 });



 // 设置每页显示的文章数量

 $itemsPerPage = 30;



 // 输出HTML

 echo '

朋友文章

通过Freshrss获取

'; foreach (array_slice($articles, 0, $itemsPerPage) as $article) { // 格式化发布时间 $date = new DateTime($article['time']); $date->setTimezone(new DateTimeZone('Asia/Shanghai')); $formattedDate = $date->format('Y年m月d日 H:i:s'); echo ''; } echo '
'; } catch (Exception $e) { echo '
获取文章失败:' . htmlspecialchars($e->getMessage()) . '
'; } ?>

2025年04月16日 13:55:47

今天热议的话题是订婚之后强行发生性关系算强奸,那结婚之后不同意依旧发生性关系那也算强奸,但凡女性不同意就不能发生性关系,那高价彩礼只会成为仙人跳的最终目的.一不注意就人财两空啊 结婚真是个高风险低收益的事情...

2025年04月11日 13:54:59

买了个 cc 的 44 刀的 vps 国内线路也不怎么滴,无所谓了。能用就行。

2025年04月10日 11:13:25

搬瓦工 37 刀的 vps 到期了不知道要不要续费。感觉 virtono 的速度也还行。主要是还便宜

2025年04月08日 16:12:22

memos 客户端 好像会有缓存

2025年04月07日 09:56:39

千股跌停。笑死

2025年04月05日 00:32:30

香港之旅结束了。刚到家。暴走两万多步脚底板巨痛。

2025年04月04日 14:25:55

人山人海

2025年04月04日 11:43:17

香港一日游走起

2025年04月03日 15:28:02

vscode 配合 Roo code插件 使用 deepseek 实现自动化 也不是不可以