示例#1
0
        public static RequestLog BuildRequestLog(HttpRequestMessage request, RequestInfo requestInfo)
        {
            RequestLog log = new RequestLog
            {
                Id         = requestInfo.Id,
                HttpMethod = request.Method.Method
            };
            IdentityInfo authInfo = new QiuxunTokenAuthorizer(new ApiAuthContainer(request)).GetAuthInfo();

            if (authInfo != null)
            {
                log.CustomerId   = new int?((int)authInfo.UserId);
                log.UserName     = authInfo.UserAccount;
                log.CustomerGuid = new Guid();
            }
            log.ClientIp         = requestInfo.ClientIP;
            log.ClientIpHttp     = requestInfo.ClientIpHttp;
            log.Lng              = requestInfo.Lng;
            log.Lat              = requestInfo.Lat;
            log.LocationType     = (int)requestInfo.LocationType;
            log.ClientNetType    = requestInfo.ClientNetType;
            log.InterfaceVersion = requestInfo.InterfaceVersion;
            log.ClientVersion    = requestInfo.ClientVersion;
            log.ClientType       = (int)requestInfo.ClientType;
            log.ClientWidth      = requestInfo.ClientWidth;
            log.ClientHeight     = requestInfo.ClientHeight;
            log.UserAgent        = requestInfo.UserAgent;
            log.RequestCookie    = requestInfo.Cookie;
            log.ServerName       = Environment.MachineName;
            log.RequestTime      = requestInfo.RequestStartTime;
            log.Route            = request.RequestUri.LocalPath;
            log.OtherHeader      = requestInfo.OtherHeader;
            RequestImeiDto imeiInfo = requestInfo.ImeiInfo;

            log.Imei         = imeiInfo.RealImei ?? "";
            log.GenerateTime = imeiInfo.GenerateTime;
            log.IsFake       = imeiInfo.IsFake;
            log.RequestData  = GetApiRequestData(request, requestInfo);
            if (requestInfo.HasRegionCodeInfo)
            {
                log.ProvinceCode = requestInfo.ProvinceCode;
                log.CityCode     = requestInfo.CityCode;
                log.DistrictCode = requestInfo.DistrictCode;
            }
            else
            {
                log.Province = requestInfo.Province;
                log.City     = requestInfo.City;
                log.District = requestInfo.District;
            }
            TimeSpan span = (TimeSpan)(DateTime.Now - log.RequestTime);

            log.ElapsedMilliseconds = (int)span.TotalMilliseconds;
            return(log);
        }
示例#2
0
        public static RequestInfo BuildRequestInfo(HttpRequestMessage request)
        {
            RequestImeiDto       dto;
            IEnumerable <string> enumerable;
            RequestInfo          info = new RequestInfo
            {
                RequestStartTime = DateTime.Now
            };
            KeyValuePair <string, string> pair = request.GetQueryNameValuePairs().FirstOrDefault <KeyValuePair <string, string> >(d => d.Key == "__h");
            string encryptedImei = "";
            string regionCode    = "";

            if (string.IsNullOrEmpty(pair.Key))
            {
                info.Lng = request.GetHeaderValue <double>("m-lng");
                info.Lat = request.GetHeaderValue <double>("m-lat");
                int headerValue = request.GetHeaderValue <int>("m-lt");
                info.LocationType     = (headerValue != 1) ? LocationType.MapLocation : LocationType.GpsLocation;
                info.ClientNetType    = request.GetHeaderValue("m-nw");
                info.InterfaceVersion = request.GetHeaderValue("m-iv");
                info.ClientVersion    = request.GetHeaderValue("m-cv");
                info.ClientType       = request.GetHeaderValue <DevicePlatform>("m-ct");
                info.ClientWidth      = request.GetHeaderValue <int>("m-cw");
                info.ClientHeight     = request.GetHeaderValue <int>("m-ch");
                encryptedImei         = request.GetHeaderValue("m-ii");
                info.ClientSourceId   = request.GetHeaderValue <byte>("m-sr");
                regionCode            = request.GetHeaderValue("m-lc");
            }
            else
            {
                NameValueCollection collection = HttpUtility.ParseQueryString(HttpUtility.UrlDecode(pair.Value));
                info.Lng              = collection.GetValue <double>("m-lng");
                info.Lat              = collection.GetValue <double>("m-lat");
                info.LocationType     = collection.GetValue <LocationType>("m-lt");
                info.ClientNetType    = collection.GetValue("m-nw");
                info.InterfaceVersion = collection.GetValue("m-iv");
                info.ClientVersion    = collection.GetValue("m-cv");
                info.ClientType       = collection.GetValue <DevicePlatform>("m-ct");
                info.ClientWidth      = collection.GetValue <int>("m-cw");
                info.ClientHeight     = collection.GetValue <int>("m-ch");
                encryptedImei         = collection.GetValue("m-ii");
                string cookies = collection.GetValue("_cookies");
                if (!string.IsNullOrEmpty(cookies))
                {
                    cookies = HttpUtility.UrlDecode(cookies);
                    request.Headers.Add("Cookie", cookies);
                }
                info.ClientSourceId = collection.GetValue <byte>("m-sr");
                info.Token          = collection.GetValue("token");
                if (!string.IsNullOrEmpty(info.Token))
                {
                    request.Headers.Add("Cookie", string.Format("{0}={1}", "token", info.Token));
                }
                regionCode = collection.GetValue("m-lc");
            }
            if (!string.IsNullOrEmpty(regionCode))
            {
                try
                {
                    //TODO:解析区域位置
                }
                catch (Exception exception)
                {
                    log4Logger.Error("区域位置解析错误", exception);
                }
            }
            string userAgent = request.Headers.UserAgent.ToString();

            info.UserAgent = userAgent;
            if (userAgent.IndexOf("MicroMessenger") > 0)
            {
                info.ClientSourceId   = 100;
                info.ClientType       = DevicePlatform.Weixin;
                info.InterfaceVersion = ConfigurationManager.AppSettings["interface_version"];
            }
            if (info.ClientSourceId == 0)
            {
                if (info.ClientType == DevicePlatform.Android)
                {
                    info.ClientSourceId = 1;
                }
                else if (info.ClientType == DevicePlatform.Ios)
                {
                    info.ClientSourceId = 2;
                }
            }
            info.OtherHeader = JsonConvert.SerializeObject(new { ClientSourceId = info.ClientSourceId });
            if (info.ClientSourceId != 100)
            {
                dto = ImeiSecurity.Decrypt(encryptedImei, request.RequestUri.PathAndQuery, info.UserAgent, info.Lng, info.Lat);
            }
            else
            {
                dto = new RequestImeiDto(encryptedImei);
            }
            info.ImeiInfo = dto;
            if (request.Headers.TryGetValues("Cookie", out enumerable))
            {
                foreach (string str10 in enumerable)
                {
                    info.Cookie = info.Cookie + str10 + "~";
                }
                if (info.Cookie.Length > 0)
                {
                    info.Cookie = info.Cookie.TrimEnd(new char[] { '~' });
                }
            }
            ClientIpSource clientIpAddress = request.GetClientIpAddress();

            info.ClientIP     = clientIpAddress.ClientIpFromTcpIp;
            info.ClientIpHttp = clientIpAddress.ClientIpFromHttp;
            info.IsHttps      = clientIpAddress.IsHttps;
            info.HttpMethod   = request.Method;
            return(info);
        }
示例#3
0
        internal static RequestImeiDto Decrypt(string encryptedImei, string url, string userAgent, double lng, double lat)
        {
            RequestImeiDto dto = new RequestImeiDto(encryptedImei);

            try
            {
                if (string.IsNullOrEmpty(encryptedImei))
                {
                    dto.IsFake = true;
                    return(dto);
                }
                byte[] src = null;
                src       = AESHelper.DecryptBytes(encryptedImei.HexToBinary(), _aes_key, _aes_iv);
                url       = (url == null) ? "" : url.ToLower().Trim();
                userAgent = (userAgent == null) ? "" : userAgent.ToLower().Trim();
                int      num     = (int)(lng * 10000000.0);
                int      num2    = (int)(lat * 10000000.0);
                string   str     = string.Format("{0}{1}{2}", url, num, num2);
                string   str2    = string.Format("{0}{1}{2}", userAgent, num, num2);
                int      num3    = Math.Abs(GetHashCode2(str));
                int      num4    = Math.Abs(GetHashCode2(str2));
                DateTime time    = _init_time.AddSeconds((double)-num3);
                int      length  = src.Length;
                int      num6    = length - 6;
                int      key     = num3 % num6;
                int      num8    = num4 % num6;
                int      num9    = 2;
                byte[]   dst     = new byte[8];
                byte[]   buffer3 = new byte[num6];
                KeyValuePair <int, int>[] pairArray = new KeyValuePair <int, int> [2];
                if (key <= num8)
                {
                    pairArray[0] = new KeyValuePair <int, int>(key, 0);
                    pairArray[1] = new KeyValuePair <int, int>(num8, 1);
                }
                else
                {
                    pairArray[0] = new KeyValuePair <int, int>(num8, 1);
                    pairArray[1] = new KeyValuePair <int, int>(key, 0);
                }
                int srcOffset = 0;
                int dstOffset = 0;
                for (int i = 0; i < num9; i++)
                {
                    int num13 = pairArray[i].Key + (i * 3);
                    int num14 = pairArray[i].Value;
                    int num15 = num13 - srcOffset;
                    if (num15 != 0)
                    {
                        Buffer.BlockCopy(src, srcOffset, buffer3, dstOffset, num15);
                        dstOffset += num15;
                        srcOffset += num15;
                    }
                    Buffer.BlockCopy(src, num13, dst, num14 * 3, 3);
                    srcOffset += 3;
                }
                int count = length - srcOffset;
                if (count != 0)
                {
                    Buffer.BlockCopy(src, srcOffset, buffer3, dstOffset, count);
                }
                long num17 = BitConverter.ToInt64(dst, 0);
                dto.GenerateTime = new DateTime?(time.AddMilliseconds((double)num17).ToLocalTime());
                dto.RealImei     = buffer3.BinaryToHex();
                dto.IsFake       = false;
                return(dto);
            }
            catch
            {
                dto.IsFake = true;
                return(dto);
            }
        }