标签:des http os io ar for 数据 2014 sp
这里的接口通过传递参数请求数据:
请求形式: xxx.php?data=20140101&page=1
参数说明:data表示请求数据的日期
page表示请求的页数
<?php header("Content-type: text/xml;charset=utf-8"); date_default_timezone_set(‘PRC‘); include dirname(__FILE__)."/../../../Inc/mysql.php"; $link = mysql_connect($f_serverName,$f_userName,$f_password); $d = mysql_select_db($f_htNewsDate,$link) or die("服务器内部故障,请联系客服!!!"); mysql_query(‘set names utf8‘); $data = $_GET[‘data‘]; $page = $_GET[‘page‘]; $list = 200; $time = strtotime($data); $top = array( ‘189‘ => ‘国家‘, ‘1854‘ => ‘安徽‘, ‘1831‘ => ‘北京‘, ‘1899‘ => ‘重庆‘, ‘1877‘ => ‘福建‘, //A-F ‘1882‘ => ‘甘肃‘, ‘1891‘ => ‘广东‘, ‘1843‘ => ‘广西‘, ‘1870‘ => ‘贵州‘, //G ‘1879‘ => ‘海南‘, ‘1858‘ => ‘河北‘, ‘1849‘ => ‘河南‘, ‘1890‘ => ‘湖北‘, ‘1866‘ => ‘湖南‘, ‘1864‘ => ‘黑龙江‘, //H ‘1857‘ => ‘吉林‘, ‘1855‘ => ‘江苏‘, ‘1893‘ => ‘江西‘, ‘1845‘ => ‘辽宁‘, ‘1897‘ => ‘宁夏‘, ‘1892‘ => ‘内蒙古‘, //J-N ‘1873‘ => ‘青海‘, ‘1883‘ => ‘上海‘, ‘1840‘ => ‘山东‘, ‘1862‘ => ‘山西‘, ‘1874‘ => ‘陕西‘, ‘1887‘ => ‘四川‘, //Q-S ‘1839‘ => ‘天津‘, ‘1884‘ => ‘西藏‘, ‘1868‘ => ‘新疆‘, ‘1865‘ => ‘云南‘, ‘1851‘ => ‘浙江‘, //T-Z ‘1993‘ => ‘资讯‘, ‘2043‘ => ‘新闻‘, ); foreach($top as $key=>$value){ $arr[]=$key; } $arr=implode(‘,‘,$arr); $limit = ($page-1) * $list; $sql ="select id,typeid,title,filename,senddate as pubdate from dede_archives WHERE arcrank=0 AND (flag like ‘%h%‘ OR flag like ‘%c%‘) AND senddate>=‘1388505600‘ AND pubdate>=‘$time‘ AND typeid in ($arr) ORDER BY pubdate DESC limit $limit,$list"; $result=mysql_query($sql); $data=array(); while($row=mysql_fetch_assoc($result)){ if($row[‘typeid‘]==189){ $categoryId=201; //国家 }else if($row[‘typeid‘]==2043){ $categoryId=203; //新闻 }else if($row[‘typeid‘]==1993){ $categoryId=299; //资讯 }else{ $categoryId=202; //地方 } //判断是否地址 $file ="http://".$_SERVER[‘HTTP_HOST‘]."/news/".date("Y",$row[‘pubdate‘]).date("md",$row[‘pubdate‘]); if($row[‘filename‘]){ $file = $file ."/".$row[‘filename‘].".html"; }else{ $file = $file ."/".$row[‘id‘].".html"; } $data[]=array( ‘id‘=>$row[‘id‘], ‘categoryId‘=>$categoryId, // ‘title‘ =>iconv(‘GBK‘,‘UTF-8//IGNORE‘,$row[‘title‘]), ‘title‘ =>$row[‘title‘], ‘url‘=>$file, ‘updateTime‘=>$row[‘pubdate‘], ); } $sql_num = "select count(id) as num from dede_archives WHERE arcrank=0 AND (flag like ‘%h%‘ OR flag like ‘%c%‘) AND senddate>=‘1388505600‘ AND pubdate>=‘$time‘ AND typeid in ($arr)"; $result_num=mysql_query($sql_num); $row1=mysql_fetch_assoc($result_num); $num = $row1[‘num‘]; $xml = ‘<?xml version="1.0" encoding="UTF-8"?>‘; $xml .= ‘<data>‘; $xml .= ‘<apiVersion>1.0</apiVersion>‘; $xml .= ‘<sourceId>102</sourceId>‘; $xml .= ‘<totalNum>‘.$num.‘</totalNum>‘; foreach($data as $key=>$val){ $xml .= ‘<item>‘; $xml .= ‘<id>‘.$val[‘id‘].‘</id>‘; $xml .= ‘<title><![CDATA[‘.$val[‘title‘].‘]]></title>‘; $xml .= ‘<url>‘.$val[‘url‘].‘</url>‘; $xml .= ‘<categoryId>‘.$val[‘categoryId‘].‘</categoryId>‘; $xml .= ‘<updateTime>‘.$val[‘updateTime‘].‘</updateTime>‘; $xml .= ‘</item>‘; } $xml .= ‘</data>‘; echo $xml; ?>
标签:des http os io ar for 数据 2014 sp
原文地址:http://my.oschina.net/u/1447974/blog/311419