1、和风天气:给城市名称给出天气+质量状况+未来天气预测
//获得未来三天的天气状况
getForsecast: function(){
var that = this;
return new Promise(function(done){
wx.request({
url: 'https://free-api.heweather.com/s6/weather/forecast?location=' + that.data.cityname + '&key=289eb322373d499890558a037ee1d816',
//必选参数为:location=城市名字 + key=自己申请的密钥
success: function(res){
that.setData({
forecastData: res.data.HeWeather6[0].daily_forecast,
})
}
})
});
},
2、腾讯地图:给经纬度返回城市名称
//得到城市名称
getCity: function(data){
return new Promise(function(done){
//2、向腾讯发出网络请求,提交经纬度,并获取城市信息
wx.request({
//关于为什么这个url包含的网址用`,因为url里包含了变量
url: 'https://apis.map.qq.com/ws/geocoder/v1/?location=' + data + '&key=WV7BZ-IPMK2-PSLU2-C63EH-7FBMF-TTBX3',
//最开始函数未拆分之前url内带变量,这样写
//url: `https://apis.map.qq.com/ws/geocoder/v1/?location=${latitude},${longitude}&key=WV7BZ-IPMK2-PSLU2-C63EH-7FBMF-TTBX3`,
//请求成功
success: function (locinfo) {
console.log(locinfo, "地址信息");
let cityname = locinfo.data.result.address_component.city;
console.log(cityname, "城市名字");
//发出消息。传给下一个人
done(cityname);
}
});
});
},
3、豆瓣
let index = 0;
wx.request({
url: "http://t.yushu.im/v2/movie/in_theaters?count=6&start="+index,
//count=6一次请求六条数据
//start:为请求数据的开始下标
success: function(res){
console.log(res.data.subjects);
that.setData({
movies: that.data.movies.concat(res.data.subjects)
})
index += 6;
}
})
4、