<?php

/**
 *      [Discuz!] (C)2001-2099 Comsenz Inc.
 *      This is NOT a freeware, use is subject to license terms
 *
 *      $Id: home.php 16805 2010-09-15 03:56:11Z zhangguosheng $
 */
if(!defined('IN_DISCUZ')) {
	exit('Access Denied');
}
function dayORnight(){
	$daystart=6;
	$dayend=18;
	$time=date('H');
	if($time<18 && $time>=6) return true;
	else return false;
}
function dayORnight1($time1){
	list($time)=explode(':',$time1);
	if($time<18 && $time>=6) return true;
	else return false;
}
set_time_limit(0);
$data_url='http://m.weather.com.cn/data/'.$_GET['id'].'.html';
$current_url='http://www.weather.com.cn/data/sk/'.$_GET['id'].'.html';



$data=array();
$msg='success';

if(!$content=@file_get_contents($data_url)){
	$msg='error';
}
$data1=json_decode($content,true);
if(!$content_current=@file_get_contents($current_url)){
	$msg='error';
}

$data0=json_decode($content_current,true);
$current=$data0['weatherinfo'];
if(!$current) $msg='error';
$isday=dayORnight();
$value=$data1['weatherinfo'];
$j=0;
for($i=1;$i<4;$i++){
	$j++;
	$day=gmdate('d',time()+(dayORnight1($current['time'])?($j-1):$j)*60*60*24);
	$data[$day]=array(
					'temp'=>$value['temp'.($i)],
					'weather'=>$value['weather'.($i)],
					'img_day'=>'d'.$value['img'.($i*2-1)],
					'img_night'=>'n'.($value['img'.($i*2)]>=99?$value['img'.($i*2-1)]:$value['img'.($i*2)]),
					'img_title_day'=>$value['img_title'.($i*2-1)],
					'img_title_night'=>$value['img_title'.($i*2)],
					'wind'=>$value['wind'.($i)],
					'fl'=>$value['fl'.($i)],
					);
	$data[$day]['img']=$isday?$data[$day]['img_day']:$data[$day]['img_night'];
	$data[$day]['img_title']=$isday?$data[$day]['img_title_day']:$data[$day]['img_title_night'];
	
}
if(!$data) $msg='error';
//print_r($data);

$current['img']=$isday?('d'.$value['img1']):'n'.($value['img2']>=99?$value['img1']:$value['img2']);
$current['index']=$value['index'];//穿衣指数；
$current['index_d']=$value['index_d'];//穿衣指数详细；
$current['index_co']=$value['index_co'];//舒适度指数；
$current['index_xc']=$value['index_xc'];//洗车指数；
$current['index_tr']=$value['index_tr'];//旅游指数；
$current['index_cl']=$value['index_cl'];//晨练指数；
$current['index_ls']=$value['index_ls'];//晾晒指数；
$current['index_uv']=$value['index_uv'];//紫外线指数；

//print_r($current);
echo json_encode(array('msg'=>$msg,'current'=>$current,'more'=>$data));

?>
