Example #1
0
 //TDbContext tDbContex;
 public ValuesController(IOptions <MailOption> mailOption, IOptions <IpInfoQueryOption> ipQueryOption, IStudentServic studentServic, SomeoneClass someone, ISchedulerFactory schedulerFactory, MyDbContext efDbContext, ILogger <ValuesController> logger, IMapper mapper, IDistributedCache cache)
 {
     this.mailOption    = mailOption.Value;
     this.ipQueryOption = ipQueryOption.Value;
     this.db            = efDbContext;
     this.logger        = logger;
     this.mapper        = mapper;
     this.cache         = cache;
     //this.tDbContex = tDbContext;
     this.schedulerFactory = schedulerFactory;
     this.studentServic    = studentServic;
     this.someone          = someone;
 }
Example #2
0
        ///// <summary>
        ///// 异步发送短信
        ///// </summary>
        /////<param name="smsInfo">短信信息实体</param>

        //public static void AsyncSendSMS(SMSInfo smsInfo, SmsOption smsOption)
        //{
        //    if (smsInfo.ToPhone.IsPhoneNum() && !string.IsNullOrWhiteSpace(smsInfo.SMSContent))
        //    {
        //        bool canSend = true;

        //        if (!smsOption.IPWhiteList.Contains(smsInfo.OperaterIP))//如果IP不在白名单中,则检查
        //        {

        //            if (OnCheckSMS != null)
        //            {
        //                canSend = OnCheckSMS.Invoke(smsInfo);
        //            }
        //        }


        //        if (canSend)
        //        {

        //            ThreadPool.QueueUserWorkItem(new WaitCallback(x => { SendSMS(smsInfo, smsOption); }));
        //        }



        //    }
        //}


        /// <summary>
        /// 查询IP信息
        /// </summary>
        /// <param name="ip">要查询的IP</param>
        /// <returns>IP信息实体</returns>
        public static IPInfo QueryIpInfo(string ip, IpInfoQueryOption option)
        {
            try
            {
                HttpWebRequest request = (HttpWebRequest)WebRequest.Create(option.ApiUrl + ip);
                request.UserAgent = "Mozilla/5.0 (iPhone; CPU iPhone OS 9_1 like Mac OS X) AppleWebKit/601.1.46 (KHTML, like Gecko) Version/9.0 Mobile/13B137 Safari/601.1";
                WebResponse  response = request.GetResponse();
                Stream       stream   = response.GetResponseStream();
                Encoding     en       = Encoding.GetEncoding("utf-8");
                StreamReader sr       = new StreamReader(stream, en);
                string       tmp      = sr.ReadToEnd();
                sr.Close();
                sr.Dispose();
                stream.Close();
                stream.Dispose();
                response.Close();

                if (!string.IsNullOrWhiteSpace(tmp))
                {
                    Regex r = new Regex("(?<=所在地理位置:<code>).*?(?=</code></p>)");

                    IPInfo ipInfo = new IPInfo();
                    ipInfo.IP   = ip;
                    ipInfo.Info = r.Match(tmp).ToString();
                    return(ipInfo);
                }
                else
                {
                    throw new Exception("查询到的IP信息为空");
                }
            }
            catch (Exception ex)
            {
                throw new Exception("查询IP信息时出现异常:IP=" + ip + ",异常信息:" + ex);
            }
        }