public static WeixinIps GetWeixinIps() { string url_token = "https://api.weixin.qq.com/cgi-bin/getcallbackip?access_token=" + WxPayConfig._access_token.Access_token; HttpWebRequest myRequest = (HttpWebRequest)WebRequest.Create(url_token); myRequest.Method = "GET"; WebResponse myResponse = myRequest.GetResponseAsync().Result; StreamReader reader = new StreamReader(myResponse.GetResponseStream(), Encoding.UTF8); string content = reader.ReadToEnd(); WeixinIps objectFromJsonstr = JsonConvert.DeserializeObject <WeixinIps>(content); reader.Dispose(); myRequest.Abort(); return(objectFromJsonstr); }
protected bool IsWeixinSeverIp(ILogger <GameController> logger) { string clientIp; clientIp = httpContextAccessor.HttpContext.Connection.RemoteIpAddress.ToString(); WeixinIps weisinips = WxPayConfig.GetWeixinIps(); var ips = weisinips.ip_list; logger.LogWarning("客户端Ip:" + clientIp); for (int i = 0; i < ips.Length; i++) { logger.LogWarning("微信severIps:" + ips[i]); if (ips[i] == clientIp) { return(true); } } return(false); // return true; }