// // 獲取用戶當前所在城市
// 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"},