javascript 腾讯天气预报接口

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了javascript 腾讯天气预报接口相关的知识,希望对你有一定的参考价值。

//全国城市代码列表(“新编码”)https://www.cnblogs.com/oucbl/p/6155096.html

var city_id = "0101140701";

        get_weather(city_id, "潜江");

        //天气预报
        function get_weather(city_id, city_name) {
            var weather_b = {
                weatherCityIcon: {
                    "default": {
                        big: "http://mat1.gtimg.com/weather/weatherIco/midImg/",
                        mid: "http://mat1.gtimg.com/www/images/qq2012/weather/icon35/",
                        small: "http://mat1.gtimg.com/www/images/qq2012/weather/"
                    },
                    "00": {
                        icon: "m0.png",
                        weatherTxt: "晴"
                    },
                    "01": {
                        icon: "m1.png",
                        weatherTxt: "多云"
                    },
                    "02": {
                        icon: "m2.png",
                        weatherTxt: "阴"
                    },
                    "03": {
                        icon: "m3.png",
                        weatherTxt: "阵雨"
                    },
                    "04": {
                        icon: "m4.png",
                        weatherTxt: "雷阵雨"
                    },
                    "05": {
                        icon: "m4.png",
                        weatherTxt: "雷阵雨并伴有冰雹"
                    },
                    "06": {
                        icon: "m6.png",
                        weatherTxt: "雨夹雪"
                    },
                    "07": {
                        icon: "m7.png",
                        weatherTxt: "小雨"
                    },
                    "08": {
                        icon: "m8.png",
                        weatherTxt: "中雨"
                    },
                    "09": {
                        icon: "m9.png",
                        weatherTxt: "大雨"
                    },
                    "10": {
                        icon: "m10.png",
                        weatherTxt: "暴雨"
                    },
                    "11": {
                        icon: "m17.png",
                        weatherTxt: "大暴雪"
                    },
                    "12": {
                        icon: "m17.png",
                        weatherTxt: "特大暴雪"
                    },
                    "13": {
                        icon: "m14.png",
                        weatherTxt: "阵雪"
                    },
                    "14": {
                        icon: "m14.png",
                        weatherTxt: "小雪"
                    },
                    "15": {
                        icon: "m16.png",
                        weatherTxt: "中雪"
                    },
                    "16": {
                        icon: "m16.png",
                        weatherTxt: "大雪"
                    },
                    "17": {
                        icon: "m17.png",
                        weatherTxt: "暴雪"
                    },
                    "18": {
                        icon: "m18.png",
                        weatherTxt: "雾"
                    },
                    "19": {
                        icon: "m6.png",
                        weatherTxt: "冻雨"
                    },
                    "20": {
                        icon: "m20.png",
                        weatherTxt: "沙尘暴"
                    },
                    "21": {
                        icon: "m8.png",
                        weatherTxt: "小雨-中雨"
                    },
                    "22": {
                        icon: "m9.png",
                        weatherTxt: "中雨-大雨"
                    },
                    "23": {
                        icon: "m10.png",
                        weatherTxt: "大雨-暴雨"
                    },
                    "24": {
                        icon: "m10.png",
                        weatherTxt: "暴雨-大暴雨"
                    },
                    "25": {
                        icon: "m10.png",
                        weatherTxt: "大暴雨-特大暴雨"
                    },
                    "26": {
                        icon: "m16.png",
                        weatherTxt: "小雪-中雪"
                    },
                    "27": {
                        icon: "m16.png",
                        weatherTxt: "中雪-大雪"
                    },
                    "28": {
                        icon: "m17.png",
                        weatherTxt: "大雪-暴雪"
                    },
                    "29": {
                        icon: "m29.png",
                        weatherTxt: "浮尘"
                    },
                    "30": {
                        icon: "m29.png",
                        weatherTxt: "扬沙"
                    },
                    "31": {
                        icon: "m20.png",
                        weatherTxt: "强沙尘暴"
                    },
                    "32": {
                        icon: "m9.png",
                        weatherTxt: "飑"
                    },
                    "33": {
                        icon: "m33.png",
                        weatherTxt: "龙卷风"
                    },
                    "34": {
                        icon: "m14.png",
                        weatherTxt: "弱高吹雪"
                    },
                    "35": {
                        icon: "m18.png",
                        weatherTxt: "轻雾"
                    },
                    "53": {
                        icon: "m29.png",
                        weatherTxt: "霾"
                    }

                }

            };
            $.ajax({
                url: 'http://weather.gtimg.cn/city/' + city_id + '.js',
                charset: 'utf-8',
                dataType: 'script',
                success: function () {

                    var weather_city = __weather_city.bi_name; //武汉

                    var area_wt = new Array(), area_wt = [];
                    var area_tmax = new Array(), area_tmax = [];
                    var area_tmin = new Array(), area_tmin = [];
                    var area_array1 = __weather_city.wk[0];
                    $.each(area_array1, function (idx, item) {
                        area_wt.push(item["wt"]);
                        area_tmax.push(item["tmax"]);
                        area_tmin.push(item["tmin"]);
                    });
                    var wt0 = area_wt[0];
                    var wt1 = area_wt[1];
                    var wt2 = area_wt[2];
                    var wt3 = area_wt[3];
                    var wt4 = area_wt[4];
                    var wt5 = area_wt[5];

                    var bigurl = weather_b.weatherCityIcon["default"].big;//
                    var midurl = weather_b.weatherCityIcon["default"].mid;//
                    var smallurl = weather_b.weatherCityIcon["default"].small;//
                    var wta = weather_b.weatherCityIcon[wt0].weatherTxt;
                    var tmaxa = area_tmax[0];

                    var tmina = area_tmin[1];

                    var tmaxb = area_tmax[2];

                    var tminb = area_tmin[3];

                    var tmaxc = area_tmax[4];

                    var tminc = area_tmin[5];
                    if (tmaxa == "NULL") {
                        tmaxa = area_tmax[1];
                        tmina = area_tmin[0];
                        tmaxb = area_tmax[3];
                        tminb = area_tmin[2];
                        tmaxc = area_tmax[5];
                        tminc = area_tmin[4];
                    }
                    var wtapica = weather_b.weatherCityIcon[wt0].icon;
                    var midwtapica = midurl + wtapica;
                    $("#midpictodynew").attr("src", midwtapica);
                    $(".weather_city").html(city_name);
                    $(".wtabig").html(wta);
                    $(".wdmaxmin").html(tmina + "℃~" + tmaxa + "℃");
                }
            });
        }

以上是关于javascript 腾讯天气预报接口的主要内容,如果未能解决你的问题,请参考以下文章

案例:腾讯天气

案例:腾讯天气

基于java高德天气的接口调用

天气预报API:最新全国所有城市代码(“新编码”)

天气预报API:城市代码--“新编码”和“旧编码” 对比

优酷腾讯视频播放器接口参数说明