Skip to content

Commit

Permalink
[fix]<GeoApi> 修复GeoApi无法正常加密的问题
Browse files Browse the repository at this point in the history
  • Loading branch information
zxbmmmmmmmmm committed Mar 23, 2024
1 parent a4e9cab commit 299adde
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 17 deletions.
22 changes: 6 additions & 16 deletions FluentWeather.QWeatherApi/ApiContracts/GeolocationApi.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System.Collections;
using System;
using System.Collections;
using System.Collections.Generic;
using System.Collections.Specialized;
using System.Linq;
Expand All @@ -19,22 +20,11 @@ public class GeolocationApi<TResponse>: QApiContractBase<IQGeolocationRequest,TR

public override string Path => ApiConstants.Geolocation.CityLookup;

public override Task<HttpRequestMessage> GenerateRequestMessageAsync(ApiHandlerOption option)
public override async Task<HttpRequestMessage> GenerateRequestMessageAsync(ApiHandlerOption option)
{
var sb = new StringBuilder(Url);
string query = GenerateQuery(option).ToString();
sb.Append(Path).Append("?").Append(query);

var requestMessage = new HttpRequestMessage(Method,sb.ToString());

var cookies = option.Cookies.ToDictionary(t => t.Key, t => t.Value);
foreach (var keyValuePair in Cookies)
{
cookies[keyValuePair.Key] = keyValuePair.Value;
}
if (cookies.Count > 0)
requestMessage.Headers.Add("Cookie", string.Join("; ", cookies.Select(c => $"{c.Key}={c.Value}")));
return Task.FromResult(requestMessage);
var result = await base.GenerateRequestMessageAsync(option);
result.RequestUri = new Uri(result.RequestUri.ToString().Replace("/api.qweather.com", "/geoapi.qweather.com").Replace("/devapi.qweather.com", "/geoapi.qweather.com"));
return result;
}
protected override NameValueCollection GenerateQuery(ApiHandlerOption option)
{
Expand Down
3 changes: 2 additions & 1 deletion FluentWeather.Uwp/Helpers/LocationHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
using FluentWeather.Uwp.Controls.Dialogs;
using FluentWeather.Uwp.Shared;
using FluentWeather.Uwp.Controls.Dialogs.QWeather;
using FluentWeather.Abstraction.Models.Exceptions;

namespace FluentWeather.Uwp.Helpers;

Expand Down Expand Up @@ -60,7 +61,7 @@ public static async Task<GeolocationBase> GetGeolocation()
}
return city.First();
}
catch
catch(HttpResponseException)
{
await new SetTokenDialog().ShowAsync();
}
Expand Down

0 comments on commit 299adde

Please sign in to comment.