| | |
| | | using System.Security.Policy; |
| | | using System.Text; |
| | | using System.Threading.Tasks; |
| | | using WIDESEAWCS_Core.LogHelper; |
| | | |
| | | namespace WIDESEAWCS_Core.Helper |
| | | { |
| | |
| | | // 检查请求次数和时间限制 |
| | | if (requestTracker.TryGetValue(requestKey, out var requestInfo)) |
| | | { |
| | | if (requestInfo.Count >= 5 && DateTime.Now < requestInfo.LastRequestTime.AddMinutes(10)) |
| | | if (requestInfo.Count >= 5 && DateTime.Now < requestInfo.LastRequestTime.AddMinutes(3)) |
| | | { |
| | | // 如果请求次数超过限制且未超过10分钟,抛出异常 |
| | | throw new InvalidOperationException("请求次数已达到限制,请稍后再试。"); |
| | |
| | | } |
| | | } |
| | | string result = string.Empty; |
| | | QuartzLogger.WriteLogToFile($"MOMAPI接口", $"请求地址:【{serviceAddress}】,请求时间【{DateTime.Now}】请求参数【{JsonConvert.SerializeObject(requestJson)}】{Environment.NewLine}{Environment.NewLine}"); |
| | | |
| | | using (HttpContent httpContent = new StringContent(requestJson)) |
| | | { |
| | | httpContent.Headers.ContentType = new MediaTypeHeaderValue("application/json"); |
| | | using HttpClient httpClient = new HttpClient(); |
| | | httpClient.Timeout = new TimeSpan(0, 0, 60); |
| | | httpClient.Timeout = new TimeSpan(0, 0, 360); |
| | | |
| | | if (headers != null) |
| | | { |
| | |
| | | } |
| | | result = await httpClient.PostAsync(serviceAddress, httpContent).Result.Content.ReadAsStringAsync(); |
| | | } |
| | | QuartzLogger.WriteLogToFile($"MOMAPI接口", $"请求地址:【{serviceAddress}】,返回时间【{DateTime.Now}】返回参数【{JsonConvert.SerializeObject(result)}】{Environment.NewLine}{Environment.NewLine}"); |
| | | return result; |
| | | } |
| | | catch (Exception e) |