GetSky.cs 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using System.IO;
  4. using System.Net;
  5. using UnityEngine;
  6. using System;
  7. [Serializable]
  8. public class GetSky : MonoBehaviour
  9. {
  10. string weaidId;
  11. public Root roots;
  12. private void Start()
  13. {
  14. weaidId = "36";
  15. GetSkys();
  16. }
  17. public void GetSkys()
  18. {
  19. //version (版本号, v1代表7天, v6代表1天) 接口参数 cityid (城市编号), city (城市名称如:青岛), ip (ip地址, 默认当前ip天气)
  20. string parameters = "version=v6";
  21. string skyPath = "http://api.k780.com/?app=weather.today&weaId="+ weaidId + "&"+ "appkey=10003&sign=b59bc3ef6191eb9f747dd4e83c99f2a4&format=json";
  22. string url = String.Concat(skyPath, parameters);
  23. HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url);
  24. request.Method = "GET";
  25. request.Timeout = 5000;
  26. HttpWebResponse response = (HttpWebResponse)request.GetResponse();
  27. string jsonString;
  28. using (Stream stream = response.GetResponseStream())
  29. {
  30. StreamReader reader = new StreamReader(stream, System.Text.Encoding.UTF8);
  31. jsonString = reader.ReadToEnd();
  32. }
  33. //Root root = JsonUtility.FromJson<Root>(jsonString);
  34. //Response
  35. }
  36. }
  37. [Serializable]
  38. public class Results
  39. {
  40. public string weaid { get; set; }
  41. public string days { get; set; }
  42. public string week { get; set; }
  43. public string cityno { get; set; }
  44. public string citynm { get; set; }
  45. public string cityid { get; set; }
  46. public string temperature { get; set; }
  47. public string temperature_curr { get; set; }
  48. public string humidity { get; set; }
  49. public string aqi { get; set; }
  50. public string weather { get; set; }
  51. public string weather_curr { get; set; }
  52. public string weather_icon { get; set; }
  53. public string weather_icon1 { get; set; }
  54. public string wind { get; set; }
  55. public string winp { get; set; }
  56. public string temp_high { get; set; }
  57. public string temp_low { get; set; }
  58. public string temp_curr { get; set; }
  59. public string humi_high { get; set; }
  60. public string humi_low { get; set; }
  61. public string weatid { get; set; }
  62. public string weatid1 { get; set; }
  63. public string windid { get; set; }
  64. public string winpid { get; set; }
  65. public string weather_iconid { get; set; }
  66. }
  67. [Serializable]
  68. public class Root
  69. {
  70. public string success { get; set; }
  71. public string result { get; set; }
  72. }