首先贴出项目地址:http://git.oschina.net/xiongchuan86/xweather
XWeather 项目是一个天气预报程序,集合了数据抓取 和 API
=================================================
一、系统要求
1.Linux
2.安装php5,php5-curl
3.网站开启rewrite
二、Clone代码
git clone http://git.oschina.net/xiongchuan86/xweather.git
三、系统配置
1.命令行下:> echo 127.0.0.1 dbserver_weather_write >> /etc/hosts #127.0.0.1 需要修改为你数据主库真实地址
2.命令行下:> echo 127.0.0.1 dbserver_weather_read >> /etc/hosts #127.0.0.1 需要修改为你数据从库真实地址
3.用熟悉的方式 把xweather里面的x_weather.sql导入数据库
4.用熟悉的方式 在数据库 创建一个用户dbuser_weather,密码123456,并增加对x_weather库的权限
5.创建一个网站 apache或nginx的配置,这里例如http://127.0.0.1:8090/ 指向xweather/www/ 目录
四、运行
1.后台抓取
cd 到 xweather/www/protected
chmod +x yiic
./yiic GetChina 初始化全国城市数据
./yiic GetWeather 抓取天气数据 #可以自行设定 把这个程序进行定时抓取
2.API接口
城市名访问
http://127.0.0.1:8090/api_1_0/default/weather/_token/698cabb9ab27e19912a759b8c1e74378/id/%E5%8C%97%E4%BA%AC
城市ID访问
http://127.0.0.1:8090/api_1_0/default/weather/_token/698cabb9ab27e19912a759b8c1e74378/id/101010100
PS:_token 是 配置的密匙protected/components/ApiBaseController.php 里面进行修改,或是去掉权限验证
这里做的很简单,如果需要复杂检验,请重写这部分