protected function getDailyWeatherCurrent() { $weather_array = array(); $weather_array = Yii::app()->cache->get("C_WEATHER_" . bin2hex($this->cityId)); //有缓存则返回 if (is_array($weather_array)) { return $weather_array; } $time = time(); $params = array('type' => 'forecast3d', 'date' => $time, 'sys_version' => Yii::app()->core->version, 'token' => urlencode(TUtil::authcode($time, 'ENCODE', 'tdweatherservices')), 'api_ver' => '2.0', 'city_name' => $this->cityId, 'stype' => 'goa'); $weather_url = self::WEATHER_API_OFFICAL . "?" . http_build_query($params); $html = @file_get_contents($weather_url); if ($html === false) { return "下载实时天气数据失败(01)"; } $arr_html = json_decode($html, true); if (!is_array($arr_html)) { return "解析实时天气数据失败(02)"; } $key_array = array('cache_time', 'cache_expire_time', 'city', 'temp', 'sd', 'ws', 'wd', 'time', 'day'); while (list($key, $value) = each($arr_html)) { if (!in_array($key, $key_array)) { continue; } $weather_array[$key] = $value; } if (count($weather_array) == 0) { return "该城市天气实时信息为空(03)"; } Yii::app()->cache->set("C_WEATHER_" . bin2hex($this->cityId), $weather_array, $weather_array['cache_expire_time']); return $weather_array; }