// // 获取用户当前所在城市
// wx.getLocation({
// type: 'wgs84', // 默认为 wgs84 返回 gps 坐标,gcj02 返回可用于 wx.openLocation 的坐标
// success: function(res) {
// console.log('获取位置成功', res);
// // 使用腾讯地图API进行逆地址解析
// wx.request({
// url: 'https://apis.map.qq.com/ws/geocoder/v1/',
// data: {
// location: res.latitude + ',' + res.longitude,
// key: 'C', // 请替换为您自己的腾讯地图API密钥
// get_poi: 0
// },
// success: function(response) {
// console.log('逆地址解析成功', response);
// if (response.statusCode === 200 && response.data.status === 0) {
// var address = response.data.result.address_component;
// that.setData({
// province: address.province,
// city: address.city,
// district: address.district
// });
// console.log('当前所在城市:', address.city);
// wx.request({
// url: apiip + '/api/Z_tianqi?cityStr='+address.city+'', ///按getuserinfo2 写的
// method: 'Get',
// success: function (res) {
// console.log('当日的天气' + JSON.stringify(res))
// if (res.data.code == '0') {
// console.log('获得了天气,动态设置'+res.data.tianqi)
// var video1='';
// if(res.data.tianqi=='雷雨'){
// video1="http://up_tu/zy_img/leiyu.mp4"
// }else if(res.data.tianqi=="晴"){
// video1="up_tu/zy_img/qingtian.mp4"
// } else if(res.data.tianqi=="雪"){
// video1="http:/6/up_tu/zy_img/xuetian.mp4"
// } else if(res.data.tianqi=="雨"||res.data.tianqi=="小雨"||res.data.tianqi=="中雨"||res.data.tianqi=="大雨"||res.data.tianqi=="暴雨"){
// video1="http://wup_tu/zy_img/yutian.mp4"
// } else{
// video1="http://w/up_tu/zy_img/tizh.mp4"
// }
// that.setData({
// tizhiqingyuSp:video1
// })
// console.log('获得了天气,动态设置视频链接'+that.data.tizhiqingyuSp)
// }}})
// //--
// } else {
// console.log('逆地址解析失败', response);
// }
// },
// fail: function(error) {
// console.log('请求腾讯地图API失败', error);
// }
// });
// },
// fail: function(error) {
// console.log('获取位置失败', error);
// // 失败时可以请求用户手动授权
// wx.showModal({
// title: '提示',
// content: '需要获取您的地理位置,请确认授权',
// success: function(res) {
// if (res.confirm) {
// wx.openSetting({
// success: function(data) {
// if (data.authSetting["scope.userLocation"] === true) {
// wx.showToast({
// title: '授权成功',
// icon: 'success',
// duration: 1000
// });
// // 再次获取位置
// wx.getLocation({
// success: function(res) {
// console.log('再次获取位置成功', res);
// }
// });
// } else {
// wx.showToast({
// title: '授权失败',
// icon: 'none',
// duration: 1000
// });
// }
// }
// });
// }
// }
// });
// }
// });
// //end 天气情况
API:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Net.Http;
using System.Web.Http;
using System.Data;
using System.Threading.Tasks;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using System.Data.SqlClient;
using System.IO;
using System.Web.Hosting;
namespace WebApplication1.Controllers
{
public class Z_tianqiController : ApiController
{
// 主要城市列表 - 使用城市ID而不是名称
// 城市ID可以通过和风天气的城市搜索API获取:https://dev.qweather.com/docs/api/geoapi/city-lookup/
private static readonly Dictionary<string, string> Cities = new Dictionary<string, string>()
{
// 4个直辖市
{"北京", "101010100"}, // 北京市
{"上海", "101020100"}, // 上海市
{"天津", "101030100"}, // 天津市
{"重庆", "101040100"}, // 重庆市
// 河北省
{"石家庄", "101090101"},
{"唐山", "101090501"},
{"秦皇岛", "101091101"},
{"邯郸", "101091001"},
{"邢台", "101090901"},
{"保定", "101090201"},
{"张家口", "101090301"},
{"承德", "101090402"},
{"沧州", "101090701"},
{"廊坊", "101090601"},
{"衡水", "101090801"},
// 山西省
{"太原", "101100101"},
{"大同", "101100201"},
{"阳泉", "101100301"},
{"长治", "101100501"},
{"晋城", "101100601"},
{"朔州", "101100901"},
{"晋中", "101100401"},
{"运城", "101100801"},
{"忻州", "101101001"},
{"临汾", "101100701"},
{"吕梁", "101101100"},
// 内蒙古自治区
{"呼和浩特", "101080101"},
{"包头", "101080201"},
{"乌海", "101080301"},
{"赤峰", "101080601"},
{"通辽", "101080501"},
{"鄂尔多斯", "101080701"},
{"呼伦贝尔", "101081000"},
{"巴彦淖尔", "101080801"},
{"乌兰察布", "101080405"},
// 辽宁省
{"沈阳", "101070101"},
{"大连", "101070201"},
{"鞍山", "101070301"},
{"抚顺", "101070401"},
{"本溪", "101070501"},
{"丹东", "101070601"},
{"锦州", "101070701"},
{"营口", "101070801"},
{"阜新", "101070901"},
{"辽阳", "101071001"},
{"盘锦", "101071301"},
{"铁岭", "101071101"},
{"朝阳", "101071201"},
{"葫芦岛", "101071401"},
// 吉林省
{"长春", "101060101"},
{"吉林", "101060201"},
{"四平", "101060401"},
{"辽源", "101060701"},
{"通化", "101060501"},
{"白山", "101060901"},
{"松原", "101060801"},
{"白城", "101060601"},
{"延边", "101060301"},
// 黑龙江省
{"哈尔滨", "101050101"},
{"齐齐哈尔", "101050201"},
{"鸡西", "101051101"},
{"鹤岗", "101051201"},
{"双鸭山", "101051301"},
{"大庆", "101050901"},
{"伊春", "101050801"},
{"佳木斯", "101050401"},
{"七台河", "101051002"},
{"牡丹江", "101050301"},
{"黑河", "101050601"},
{"绥化", "101050501"},
{"大兴安岭", "101050701"},
// 江苏省
{"南京", "101190101"},
{"无锡", "101190201"},
{"徐州", "101190801"},
{"常州", "101191101"},
{"苏州", "101190401"},
{"南通", "101190501"},
{"连云港", "101191001"},
{"淮安", "101190901"},
{"盐城", "101190701"},
{"扬州", "101190601"},
{"镇江", "101190301"},
{"泰州", "101191201"},
{"宿迁", "101191301"},
// 浙江省
{"杭州", "101210101"},
{"宁波", "101210401"},
{"温州", "101210701"},
{"嘉兴", "101210301"},
{"湖州", "101210201"},
{"绍兴", "101210501"},
{"金华", "101210901"},
{"衢州", "101211001"},
{"舟山", "101211101"},
{"台州", "101210601"},
{"丽水", "101210801"},
// 安徽省
{"合肥", "101220101"},
{"芜湖", "101220301"},
{"蚌埠", "101220201"},
{"淮南", "101220401"},
{"马鞍山", "101220501"},
{"淮北", "101221301"},