using IStation.Common; using IStation.Dto; using System; using System.Collections.Generic; using System.Linq; using System.Net; using System.Net.Http; using System.Web; using System.Web.Http; using System.Web.UI.WebControls; namespace IStation.WebApi.Controllers { /// /// 取水总量 /// [RoutePrefix("TotalWaterIn")] public class TotalWaterInController : ApiController { /// /// 获取某日的取水总量 /// /// /// [Route("GetByDay")] [HttpGet] public IStation.Dto.ApiResult GetByDay(string day) { if (day == null) { return new IStation.Dto.ApiResult() { Code = ApiResultCode.Error, Message = "day null" }; } double sum = 100 + DateTime.Parse(day).Day; TotalWaterInHelper.Save(DateTime.Parse(day), sum); //var sum = ZyConnectHelper.GetTotalWaterByDay_In(DateTime.Parse(day)).Result;//.GetAwaiter().GetResult(); return new IStation.Dto.ApiResult(sum); } /// /// 获取web客户端ip /// /// public static string GetWebClientIp() { string userIP = ""; try { if (System.Web.HttpContext.Current == null || System.Web.HttpContext.Current.Request == null || System.Web.HttpContext.Current.Request.ServerVariables == null) { return ""; } string CustomerIP = ""; //CDN加速后取到的IP simone 090805 CustomerIP = System.Web.HttpContext.Current.Request.Headers["Cdn-Src-Ip"]; if (!string.IsNullOrEmpty(CustomerIP)) { return CustomerIP; } CustomerIP = System.Web.HttpContext.Current.Request.ServerVariables["HTTP_X_FORWARDED_FOR"]; if (!String.IsNullOrEmpty(CustomerIP)) { return CustomerIP; } if (System.Web.HttpContext.Current.Request.ServerVariables["HTTP_VIA"] != null) { CustomerIP = System.Web.HttpContext.Current.Request.ServerVariables["HTTP_X_FORWARDED_FOR"]; if (CustomerIP == null) { CustomerIP = System.Web.HttpContext.Current.Request.ServerVariables["REMOTE_ADDR"]; } } else { CustomerIP = System.Web.HttpContext.Current.Request.ServerVariables["REMOTE_ADDR"]; } if (string.Compare(CustomerIP, "unknown", true) == 0 || String.IsNullOrEmpty(CustomerIP)) { return System.Web.HttpContext.Current.Request.UserHostAddress; } return CustomerIP; } catch { } return userIP; } } }