import axios from "axios";

const key = "0864bb5b46011f3add9235ac7c5fcd71";

// 获取天气请求
export const getWeatherInfo = async () => {
  // 获取当前位置城市编码
  const res = await axios.get(`https://restapi.amap.com/v3/ip?key=${key}`);

  // 城市编码
  let { adcode } = res.data;

  // 获取天气信息
  const info = await axios.get(
    `https://restapi.amap.com/v3/weather/weatherInfo?key=${key}&city=${adcode}&extensions=all`
  );
  // 今日天气信息
  const dayInfo = info.data.forecasts[0].casts[0];

  return dayInfo;
};
