
发现历史上的今天api接口-继续薅百度羊毛,是百度的接口,兄弟们造起来
百度的接口如下:
百度原生态接口 : https://baike.baidu.com/cms/home/eventsOnHistory/06.json
于是自己封装下
<?php
$month = date('m',time());
$day = date('d',time());
$url="https://baike.baidu.com/cms/home/eventsOnHistory/".$month.'.json';
$data = file_get_contents($url);
$data2 = json_decode($data,true);
$array = [];
foreach($data2[$month][$month.$day] as $data){
$array[] = [
'year'=>$data['year'],
'title'=>$data['title']
];
}
$json_output = [
$month.$day => $array
];
//输出
header('Content-type:text/json');
echo json_encode($json_output,true);