自动获取天气预报,天气预报接口

本页面提供自动获取的当前及未来五天的天气信息,包括日期、天气状况、温度、风力等详细数据。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

http://webservice.36wu.com/weatherService.asmx

源码下载:点击打开链接

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <h1>
            自动获取当天当地天气</h1>
        <asp:Repeater ID="Repeater1" runat="server">
            <ItemTemplate>
                <div style="background-image: url('http://php.weather.sina.com.cn/images/weather_yc_01.jpg');
                    width: 505px; height: 280px">
                    <div style="padding: 15px; width: 100%; height: 100%; color: White; line-height: 25px">
                        <%#Eval("DateTime")%>
                        <br />
                        <%#Eval("City")%>
                        <br />
                        <%#Eval("Weather")%>
                        <br />
                        <%#string.Format("{0}~{1}", Eval("Temp1"), Eval("Temp2"))%>
                        <br />
                        <img src='<%# string.Format("PNG/{0}",Eval("Img1").ToString().Replace("gif","png")) %>' /><img
                            src='<%# string.Format("PNG/{0}",Eval("Img2").ToString().Replace("gif","png")) %>' />
                    </div>
                </div>
            </ItemTemplate>
        </asp:Repeater>
        <h1>
            自动获取未来五天天气</h1>
        <asp:Repeater ID="Repeater2" runat="server">
            <ItemTemplate>
                <div style="float: left; background: url('http://php.weather.sina.com.cn/images/weather_yc_01.jpg') -510px 0px no-repeat;
                    width: 168px; height: 253px;">
                    <div style="text-align: center; margin: 5px; width: 100%; height: 100%; color: White;
                        line-height: 25px">
                        <%#Eval("City")%>
                        <br />
                        <%#Eval("Date_1")%>
                        <br />
                        <%# Eval("Temp1")%>
                        <br />
                        <%#Eval("Weather1")%>
                        <br />
                        <%#Eval("Wind1")%>
                        <br />
                        <img src='<%# string.Format("PNG/{0}.png",Eval("Img1")) %>' /><img src='<%# string.Format("PNG/{0}.png",Eval("Img2")) %>' />
                    </div>
                </div>
                <div style="float: left; background: url('http://php.weather.sina.com.cn/images/weather_yc_01.jpg') -510px 0px no-repeat;
                    width: 168px; height: 253px;">
                    <div style="text-align: center; margin: 5px; width: 100%; height: 100%; color: White;
                        line-height: 25px">
                        <%#Eval("City")%>
                        <br />
                        <%#Eval("Date_2")%>
                        <br />
                        <%# Eval("Temp2")%>
                        <br />
                        <%#Eval("Weather2")%>
                        <br />
                        <%#Eval("Wind2")%>
                        <br />
                        <img src='<%# string.Format("PNG/{0}.png",Eval("Img3")) %>' /><img src='<%# string.Format("PNG/{0}.png",Eval("Img4")) %>' />
                        <br />
                    </div>
                </div>
                <div style="float: left; background: url('http://php.weather.sina.com.cn/images/weather_yc_01.jpg') -510px 0px no-repeat;
                    width: 168px; height: 253px;">
                    <div style="text-align: center; margin: 5px; width: 100%; height: 100%; color: White;
                        line-height: 25px">
                        <%#Eval("City")%>
                        <br />
                        <%#Eval("Date_3")%>
                        <br />
                        <%# Eval("Temp3")%>
                        <br />
                        <%#Eval("Weather3")%>
                        <br />
                        <%#Eval("Wind3")%>
                        <br />
                        <img src='<%# string.Format("PNG/{0}.png",Eval("Img5")) %>' /><img src='<%# string.Format("PNG/{0}.png",Eval("Img6")) %>' />
                        <br />
                    </div>
                </div>
                <div style="float: left; background: url('http://php.weather.sina.com.cn/images/weather_yc_01.jpg') -510px 0px no-repeat;
                    width: 168px; height: 253px;">
                    <div style="text-align: center; margin: 5px; width: 100%; height: 100%; color: White;
                        line-height: 25px">
                        <%#Eval("City")%>
                        <br />
                        <%#Eval("Date_4")%>
                        <br />
                        <%# Eval("Temp4")%>
                        <br />
                        <%#Eval("Weather4")%>
                        <br />
                        <%#Eval("Wind4")%>
                        <br />
                        <img src='<%# string.Format("PNG/{0}.png",Eval("Img7")) %>' /><img src='<%# string.Format("PNG/{0}.png",Eval("Img8")) %>' />
                        <br />
                    </div>
                </div>
                <div style="float: left; background: url('http://php.weather.sina.com.cn/images/weather_yc_01.jpg') -510px 0px no-repeat;
                    width: 168px; height: 253px;">
                    <div style="text-align: center; margin: 5px; width: 100%; height: 100%; color: White;
                        line-height: 25px">
                        <%#Eval("City")%>
                        <br />
                        <%#Eval("Date_5")%>
                        <br />
                        <%# Eval("Temp5")%>
                        <br />
                        <%#Eval("Weather5")%>
                        <br />
                        <%#Eval("Wind5")%>
                        <br />
                        <img src='<%# string.Format("PNG/{0}.png",Eval("Img9")) %>' /><img src='<%# string.Format("PNG/{0}.png",Eval("Img10")) %>' />
                        <br />
                    </div>
                </div>
                <div style="float: left; background: url('http://php.weather.sina.com.cn/images/weather_yc_01.jpg') -510px 0px no-repeat;
                    width: 168px; height: 253px;">
                    <div style="text-align: center; margin: 5px; width: 100%; height: 100%; color: White;
                        line-height: 25px">
                        <%#Eval("City")%>
                        <br />
                        <%#Eval("Date_6")%>
                        <br />
                        <%# Eval("Temp6")%>
                        <br />
                        <%#Eval("Weather6")%>
                        <br />
                        <%#Eval("Wind6")%>
                        <br />
                        <img src='<%# string.Format("PNG/{0}.png",Eval("Img11")) %>' /><img src='<%# string.Format("PNG/{0}.png",Eval("Img12")) %>' />
                        <br />
                    </div>
                </div>
            </ItemTemplate>
        </asp:Repeater>
    </div>
    </form>
</body>
</html>

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using ServiceReference;

public partial class _Default : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            //今天天气
            BindTodayWeather();
            //获取未来五天
            BindMoreWeather();
        }
    }

    private void BindTodayWeather()
    {
        WeatherServiceSoapClient client = new WeatherServiceSoapClient();
        //自动回去未来六天天气
        //client.getAutomaticMoreWeather()

        //自动回去今天天气
        //client.getAutomaticTodayWeather()

        //根据城市名或者区县名获取未来五天天气
        //client.getMoreWeatherByCityName("市名或者区县名");

        //根据ID获取未来五天天气
        //client.getMoreWeatherByCityId("城市ID")

        //内置实体TodayWeather
        TodayWeather todayWeather = client.getAutomaticTodayWeather();
  
        List<TodayWeather> list = new List<TodayWeather>();
        list.Add(todayWeather);

        //将接果绑定在Repeater上
        Repeater1.DataSource = list;
        Repeater1.DataBind();
    }
    private void BindMoreWeather()
    {
        WeatherServiceSoapClient client = new WeatherServiceSoapClient();
        //内置实体MoreWeather
        MoreWeather moreWeather = client.getAutomaticMoreWeather();
        List<MoreWeather> list = new List<MoreWeather>();
        Repeater2.DataSource = list;
        list.Add(moreWeather);
        Repeater2.DataBind();
    }
}


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值