DESKTOP-9JTA2JJ\HP 5 лет назад
Родитель
Сommit
c7c7cbfd72
1 измененных файлов с 22 добавлено и 0 удалено
  1. 22 0
      api/application/controllers/Home.php

+ 22 - 0
api/application/controllers/Home.php

@@ -800,4 +800,26 @@ class Home extends Base_Controller {
 
         exit(json_result('0000',$this->response['0000'],$data));
     }
+
+    public function weather_info(){
+        $areaId = intval($this->input->post('areaId',true));
+        if (empty($areaId)) exit(json_result('0007',$this->response['0007']));
+
+        $res1 = $this->Global_location_model->get_one(['id'=>$areaId],'level,pid,chinese_name,longitude,latitude,english_name');
+
+        $url = 'https://free-api.heweather.net/s6/weather/forecast?location='.$res1['longitude'].','.$res1['latitude'].'&key=63dbc994630941fab269ad3c3af4d5d2';
+        // $url = 'https://way.jd.com/he/freeweather?city='.$res2['chinese_name'].'&appkey=a44fc7f907194098c69bb8e90003bca6';
+        $resData = request_post($url);
+        $arr = json_decode($resData,true);
+        if ($arr['HeWeather6'][0]['status'] == 'ok') {
+            $now = $arr['HeWeather6'][0]['daily_forecast'][0];
+            $daily_forecast = $arr['HeWeather6'][0]['daily_forecast'];
+            $data = ['weatherType'=>$now['cond_txt_d'],'code'=>$now['cond_code_d'],'tmp'=>intval(($now['tmp_min'] + $now['tmp_max'])/2)];
+
+        }else{
+            $data = ['weatherType'=>'','code'=>'','tmp'=>''];
+        }
+
+        exit(json_result('0000',$this->response['0000'],$data));
+    }
 }