欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

PHP实现新型冠状病毒疫情实时图的实例

程序员文章站 2022-06-08 23:18:32
我们先来看一下运行图下面我们来看源代码:

我们先来看一下运行图

PHP实现新型冠状病毒疫情实时图的实例

下面我们来看源代码:

<?php
//抓取抖音的接口数据
global $ncov_data;
$ncov_data['data']=get_ncov_douyin_news();
$ncov_data['total']=get_ncov_douyin_total();
function get_ncov_douyin_news(){
 $content=@file_get_contents('https://i.snssdk.com/api/feed/forum_flow/v1/?forum_id=1656388947394568&is_web_refresh=1&channel=local_test&query_id=1656388947394568&tab_id=1656388947394584&is_preview=1&stream_api_version=82&aid=13&forum_id=1656388947394568&is_preview=0');
 $c=count(json_decode($content)->data)-1;
 $getinfos=@json_decode(json_decode($content)->data[$c]->content)->sub_raw_datas;
 if ($getinfos){
  foreach ($getinfos as $k=>$info){
   $data[$k]=[
    'showtime'=>$info->raw_data->showtime_string,//展示时间
    'desc'=>$info->raw_data->desc,//简讯
    'event_time'=>$info->raw_data->event_time//真实播报时间
   ];
  }
  return $data;
 }else{
  return false;
 }

}
function get_ncov_douyin_total(){
 $content=@file_get_contents('https://i.snssdk.com/forum/home/v1/info/?forum_id=1656388947394568&is_web_refresh=1');
 $getinfos=@json_decode(json_decode($content)->forum->extra->ncov_string_list);
 $data['desc']=@json_decode($content)->forum->rich_content;
 $data['img']=@json_decode($content)->forum->extra->ncov_image_url;
 if ($getinfos){
  foreach ($getinfos as $k=>$info){
   $data['provinces'][$k]=$info;
  }
  return $data;
 }else{
  return false;
 }
}
?>
<!doctype html>
<html lang="zh">
<head>
 <meta charset="utf-8">
 <meta name="viewport"
   content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
 <meta http-equiv="x-ua-compatible" content="ie=edge">
 <meta author="__mark_cheng__qq72817">
 <link rel="stylesheet" href="css/index.css" rel="external nofollow" >
 <title>实时更新:新型冠状病毒肺炎疫情</title>
</head>
<body>
 <div class="view">
  <div class="header">
   <div class="title">新型冠状病毒肺炎</div>
   <div class="to-title">疫情通报</div>
  </div>
  <div class="show">
   <div class="total">
    <p class="title"><span>实时疫情状况</span><span>数据抓取时间:<?php echo date('y.m.d h:i');?></span></p>
    <p class="desc"><?php echo $ncov_data['total']['desc'];?></p>
   </div>
   <div class="map">
    <img src="<?php echo $ncov_data['total']['img'];?>" alt="实时地图" width="100%">
   </div>
   <div class="list">
    <ul>
     <?php
     foreach ($ncov_data['total']['provinces'] as $key=>$val){
      echo '<li><span>'.$val.'</span></li>';
     }
     ?>
    </ul>
   </div>
   <div class="timeline">
    <div class="title">疫情追踪</div>
    <div class="c">
     <?php
      foreach ($ncov_data['data'] as $key=>$val){
     ?>
     <div class="content">
      <div class="i"></div>
      <div class="c">
       <div class="show_time">
        <?php echo date('m月d日 h:i',$val['event_time']);?>
       </div>
       <div class="desc">
        <?php echo $val['desc'];?>
       </div>
      </div>
     </div>
     <?php
     }
     ?>
    </div>
   </div>
   <div class="tip">
    <img src="https://mat1.gtimg.com/news/images/inews/2020/feiyan/18/img/prevent.png" alt="温馨提示" width="100%">
   </div>
  </div>
 </div>
</body>
</html>

分析:其中php代码中的图片路径可以自己保存到本地进行修改。

感谢大家的学习和对的支持。