Clock.BLL/Service/WebApiHelper.cs

(开头部分) 7KB

这里只显示每个文件的开头 60 行。登录后可以解锁完整代码。

using Model;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Net;
using System.Net.Sockets;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading.Tasks;

namespace AlarmClock.BLL
{
    public class WebApiHelper
    {

        #region 向用户公布的接口

        /// <summary>
        /// 向用户公布的天气接口:查询所有天气信息
        /// </summary>
        /// <returns></returns>
        public static Root GetAllWeather(string City = "")
        {
            string jsonStr = "";
            if (string.IsNullOrEmpty(City))
            {
                if(Location!=null) jsonStr = GetBaiduWeather(Location["区"]);
                else jsonStr = GetBaiduWeather("番禺");
            }
                
            else 
                jsonStr = GetBaiduWeather(City);

            if(jsonStr==""||jsonStr==null) return null;

            return JsonConvert.DeserializeObject<Root>(jsonStr);           
        }

        /// <summary>
        /// 向用户公布的天气接口:查询主要天气信息
        /// </summary>
        /// <param name="City"></param>
        /// <returns></returns>
        public static string GetMainWeather(string City = "")
        {
            Root AllWeatherInfo=new Root();
            if (string.IsNullOrEmpty(City)) 
                AllWeatherInfo=GetAllWeather();
            else
                AllWeatherInfo = GetAllWeather(City);
            
            if(AllWeatherInfo==null) return "没有百度地图ak,不提供此服务";
            if (AllWeatherInfo.result == null) return AllWeatherInfo.message;

            string CityName = AllWeatherInfo.result.location.name;
            string Tempprate = AllWeatherInfo.result.now.temp.ToString();
            return string.Format("{0}  {1}℃", CityName, Tempprate);
后面还有 157 行代码,解锁后查看完整代码

24 小时内免费解锁 3 个项目,之后 1 积分/个。 规则说明

AI 解读 AI

登录后可用,每次 10 积分,解读结果公开显示在下面。

还没有人解读过这个文件。