public string GetUrl() { string uri = BuildUrl(); IDictionary <string, string?> parameters = new Dictionary <string, string?> { { ClientNames.RandomStr, ApiRequest.GetRandomStr() }, { ClientNames.Timestamp, TimeUtil.UtcNowUnixTimeMilliseconds.ToString(GlobalSettings.Culture) }, { ClientNames.DeviceId, DeviceId }//额外添加DeviceId,为了验证jwt中的DeviceId与本次请求deviceiId一致 }; return(UrlUtil.AddQuerys(uri, parameters)); }
private static void AddDeviceInfo(HttpRequestMessage request) { string deviceId = DevicePreferences.DeviceId; // 因为Jwt要验证DeviceId与token中的是否一致,所以在url的query中加上DeviceId request.RequestUri = new Uri(UrlUtil.AddQuerys(request.RequestUri.ToString(), new Dictionary <string, string?> { { ClientNames.DeviceId, deviceId } })); //DeviceWrapper deviceWrapper = new() //{ // DeviceId = deviceId, // DeviceVersion = DevicePreferences.DeviceVersion, // DeviceInfos = DevicePreferences.DeviceInfos //}; //StringContent deviceContent = new StringContent(SerializeUtil.ToJson(deviceWrapper), Encoding.UTF8, "application/json"); //if (request.Content == null) //{ // request.Content = deviceContent; //} //else if (request.Content is MultipartFormDataContent content) //{ // content.Add(deviceContent); //} //else if (request.Content is StringContent stringContent) //{ // try // { // MultipartContent multipartContent = new() // { // request.Content, // deviceContent // }; // request.Content = multipartContent; // } // catch (Exception ex) // { // GlobalSettings.Logger.Log(LogLevel.Error, ex, $"Url:{request.RequestUri.AbsoluteUri}"); // } //} }