2020-12-30 21:30:02 +03:00
|
|
|
<?php
|
|
|
|
|
|
|
|
class GenshinImpactBridge extends BridgeAbstract
|
2022-07-01 16:10:30 +03:00
|
|
|
{
|
2020-12-30 21:30:02 +03:00
|
|
|
const MAINTAINER = 'corenting';
|
|
|
|
const NAME = 'Genshin Impact';
|
|
|
|
const URI = 'https://genshin.mihoyo.com/en/news';
|
|
|
|
const CACHE_TIMEOUT = 7200; // 2h
|
|
|
|
const DESCRIPTION = 'News from the Genshin Impact website';
|
|
|
|
const PARAMETERS = [
|
2022-07-01 16:10:30 +03:00
|
|
|
[
|
2020-12-30 21:30:02 +03:00
|
|
|
'category' => [
|
|
|
|
'name' => 'Category',
|
|
|
|
'type' => 'list',
|
|
|
|
'values' => [
|
|
|
|
'Latest' => 10,
|
|
|
|
'Info' => 11,
|
|
|
|
'Updates' => 12,
|
|
|
|
'Events' => 13
|
|
|
|
],
|
|
|
|
'defaultValue' => 10
|
2022-07-01 16:10:30 +03:00
|
|
|
]
|
|
|
|
]
|
2020-12-30 21:30:02 +03:00
|
|
|
];
|
|
|
|
|
|
|
|
public function collectData()
|
|
|
|
{
|
|
|
|
$category = $this->getInput('category');
|
|
|
|
|
|
|
|
$url = 'https://genshin.mihoyo.com/content/yuanshen/getContentList';
|
2022-10-01 09:42:02 +03:00
|
|
|
$url = $url . '?pageSize=5&pageNum=1&channelId=' . $category;
|
2022-01-02 12:36:09 +03:00
|
|
|
$api_response = getContents($url);
|
2020-12-30 21:30:02 +03:00
|
|
|
$json_list = json_decode($api_response, true);
|
|
|
|
|
|
|
|
foreach ($json_list['data']['list'] as $json_item) {
|
|
|
|
$article_url = 'https://genshin.mihoyo.com/content/yuanshen/getContent';
|
|
|
|
$article_url = $article_url . '?contentId=' . $json_item['contentId'];
|
2022-01-02 12:36:09 +03:00
|
|
|
$article_res = getContents($article_url);
|
2020-12-30 21:30:02 +03:00
|
|
|
$article_json = json_decode($article_res, true);
|
2021-04-10 11:35:34 +03:00
|
|
|
$article_time = $article_json['data']['start_time'];
|
|
|
|
$timezone = 'Asia/Shanghai';
|
|
|
|
$article_timestamp = new DateTime($article_time, new DateTimeZone($timezone));
|
2020-12-30 21:30:02 +03:00
|
|
|
|
|
|
|
$item = [];
|
|
|
|
|
|
|
|
$item['title'] = $article_json['data']['title'];
|
2021-04-10 11:35:34 +03:00
|
|
|
$item['timestamp'] = $article_timestamp->format('U');
|
2020-12-30 21:30:02 +03:00
|
|
|
$item['content'] = $article_json['data']['content'];
|
|
|
|
$item['uri'] = $this->getArticleUri($json_item);
|
|
|
|
$item['id'] = $json_item['contentId'];
|
|
|
|
|
|
|
|
// Picture
|
|
|
|
foreach ($article_json['data']['ext'] as $ext) {
|
|
|
|
if ($ext['arrtName'] == 'banner' && count($ext['value']) == 1) {
|
|
|
|
$item['enclosures'] = [$ext['value'][0]['url']];
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
$this->items[] = $item;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public function getIcon()
|
|
|
|
{
|
|
|
|
return 'https://genshin.mihoyo.com/favicon.ico';
|
|
|
|
}
|
|
|
|
|
|
|
|
private function getArticleUri($json_item)
|
|
|
|
{
|
|
|
|
return 'https://genshin.mihoyo.com/en/news/detail/' . $json_item['contentId'];
|
|
|
|
}
|
|
|
|
}
|