|
@@ -658,7 +658,7 @@ class PublicRpcService implements PublicRpcServiceInterface
|
|
|
return Result::success($ip_info);
|
|
|
} else {
|
|
|
$data['ip'] = '101.254.114.212';
|
|
|
- $this->getIpinfo($data['ip']);
|
|
|
+ $this->getIpinfo(["ip"=>$data['ip']]);
|
|
|
}
|
|
|
}
|
|
|
|
|
@@ -669,6 +669,17 @@ class PublicRpcService implements PublicRpcServiceInterface
|
|
|
*/
|
|
|
public function getWeatherInfo(array $data) :array
|
|
|
{
|
|
|
+ $month = $data['month'] ?? date('m');
|
|
|
+ $day = $data['day'] ?? date('d');
|
|
|
+ // 使用缓存键
|
|
|
+ $cacheKey = "tsbb_data_weather_{$month}_{$day}";
|
|
|
+
|
|
|
+ // 尝试从缓存获取数据
|
|
|
+ $container = \Hyperf\Context\ApplicationContext::getContainer();
|
|
|
+ $cache = $container->get(\Psr\SimpleCache\CacheInterface::class);
|
|
|
+ if ($cachedData = $cache->get($cacheKey)) {
|
|
|
+ return Result::success(unserialize($cachedData));
|
|
|
+ }
|
|
|
$location = $data['latitude'].":".$data['longitude'];
|
|
|
$api_url = "https://api.seniverse.com/v3/weather/now.json?key=".\Hyperf\Support\env('WEATHER_KEY')."&location=".$location."&language=zh-Hans&unit=c";
|
|
|
$ch = curl_init($api_url);
|
|
@@ -677,6 +688,8 @@ class PublicRpcService implements PublicRpcServiceInterface
|
|
|
curl_close($ch);
|
|
|
// 解析 JSON 响应
|
|
|
$WeatherInfo = json_decode($response, true);
|
|
|
+ // 缓存结果,设置1小时过期
|
|
|
+ $cache->set($cacheKey, serialize($WeatherInfo), 3600);
|
|
|
if($WeatherInfo){
|
|
|
return Result::success($WeatherInfo);
|
|
|
}else{
|