36 lines
1.2 KiB
C#
36 lines
1.2 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.IO;
|
|
using System.Linq;
|
|
using System.Net;
|
|
using System.Text;
|
|
|
|
namespace Sin365AIProject_01.Function
|
|
{
|
|
public class Weather
|
|
{
|
|
public static int HaoYueAI_Class = 1;
|
|
|
|
//可添加任意自己的扩展方法
|
|
public static string HaoYueAI_FuncName_GetWeatherForCity = "查询天气,天气";
|
|
public void GetWeatherForCity(string cityMsg)
|
|
{
|
|
Console.WriteLine("天气查询中……");
|
|
|
|
//根据根据城市中文名获取天气
|
|
//string url = "http://apistore.baidu.com/microservice/weather?cityname=北京";
|
|
string url = "http://apistore.baidu.com/microservice/weather?cityname="+cityMsg;
|
|
WebRequest wRequest = WebRequest.Create(url);
|
|
wRequest.Method = "GET";
|
|
wRequest.ContentType = "text/html;charset=UTF-8";
|
|
WebResponse wResponse = wRequest.GetResponse();
|
|
Stream stream = wResponse.GetResponseStream();
|
|
StreamReader reader = new StreamReader(stream, System.Text.Encoding.Default);
|
|
string str = reader.ReadToEnd(); //url返回的值
|
|
reader.Close();
|
|
wResponse.Close();
|
|
|
|
}
|
|
}
|
|
}
|