public async Task <IViewComponentResult> InvokeAsync(string adcode = "410100") { var result = await _weatherHttpClient.GetLocationWeatherInfo(adcode); var weatherModel = JsonConvert.DeserializeObject <Weather>(result); return(View("default1", weatherModel)); }
public async Task Invoke(HttpContext context, GetWeatherHttpClient customHttpClient) { var weatherJson = await customHttpClient.GetLocationWeatherInfo(); context.Response.ContentType = "application/json;utf-8"; await context.Response.WriteAsync(weatherJson); // 输出天气json //await this._next(context); }
/// <summary> /// 执行具体业务逻辑,可被调度执行多次 /// </summary> /// <param name="context"></param> /// <returns></returns> public async Task Execute(IJobExecutionContext context) { this._logger.LogDebug("============================================="); this._logger.LogInformation("开始获取天气信息"); var response = await _client.GetLocationWeatherInfo(); this._logger.LogInformation($"DateTime:{DateTime.Now} weather:{response}"); this._logger.LogInformation("获取信息完成"); this._logger.LogInformation("============================================="); }