VBMAN Weather demo
Overview
This is a weather forecast query instance. It uses the weather forecast query interface to get weather forecast information and play the cctv video.
Project Structure
Download source [ Note:To bin
regedits DLL file ]
Please go to the home page to download the VBMAN project, decompress it, and open it with all DEMO projects.
Weather/
├── Form1.frm # Main form
└── Weather.vbp # VB6 project file
Core Code Analysis
1. Main Form (Form1.frm)
vb
Private Sub Command1_Click()
'City ID
Dim id$: id = Text4.Text
'City name query interface
Const areaid$ = "https://i.tq121.com.cn/j/wap2016/news/city_search_data.js?20220422"
'Weather forecast video and area
Const videos$ = "https://e.weather.com.cn/pubm/videos_vms1.htm?callback=getLbDatas&_=1747888658520"
Dim area$: area = "https://e.weather.com.cn/p/site/aqifc1h?areaid=" & id & "&callback=aqifc1h&_=1747888658537"
'Current weather forecast
Dim tq$: tq = "https://d1.weather.com.cn/sk_2d/" & id & ".html?_=1747889185006"
'One week weather forecast
Dim week$: week = "https://d1.weather.com.cn/weixinfc/" & id & ".html?_=1747889185007"
'Weather overview
Dim sum$: sum = "https://d1.weather.com.cn/weather_index/" & id & ".html?_=1747889185008"
'Direct call
'Text1.Text = VBMAN.HttpClient.Fetch(ReqGet, videos).ReturnJson().Encode(, 2, True)
With VBMAN.HttpClient.Fetch(ReqGet, videos).ReturnJson()
Text1.Text = .Encode(, 2, True) 'show text content
Dim url$: url = .Root("documents")(1)("videourl")(1)("url")
WindowsMediaPlayer1.url = url 'play weather forecast video
End With
'add "referer" header ^"referer: https://e.weather.com.cn/^" ^
With VBMAN.HttpClient
.RequestHeaders("referer") = "https://e.weather.com.cn/"
'Get current weather data
With .Fetch(ReqGet, tq).ReturnJson()
Label1.Caption = .Root("cityname") & " Current temperature: " & .Root("temp") & " degree"
Text2.Text = .Encode(, 2, True)
end With
'Get city ID data
Text3.Text = .Fetch(ReqGet, areaid).ReturnText()
end With
end sub
Function Description
- Interface List
- Query city ID interface
- Get city ID data
- Get weather forecast video and area
- Get current weather forecast
- Get one week weather forecast
- Get weather overview
- Effect Screenshots
Technical Points
- VBMAN library provides HttpClient class for HTTP requests.
- The Fetch method of HttpClient class can send HTTP requests and return response results.
- The ReturnJson method of Fetch method can convert response results to JSON objects and perform subsequent processing.
- The ReturnText method of Fetch method can convert response results to text and perform subsequent processing.
- The RequestHeaders property of HttpClient class can add request headers, such as adding Referer header.
- The Root method of Json class can get the root node of JSON objects and use the Root method to get the value of a node.
- The Encode method of Json class can convert JSON objects to text and set indentation and line breaks.
- The WindowsMediaPlayer control can play videos.
Use Cases
- Add more city query functions, such as adding city lists, users enter city names to query city IDs, and display weather forecasts.
- Add more weather forecast query functions, such as adding weather forecast query lists, users select cities to query weather forecasts.
- Add more weather forecast query functions, such as adding weather forecast query lists, users select cities to query weather forecasts.