示例#1
0
 public static void Request(bool IsConfig = false)
 {
     Task.Factory.StartNew(() =>
     {
         #region 后台异步处理事务
         string result    = string.Empty;
         var configEntity = bll_ConfigBLL.Find().FindAll(n => n.Keys == "url_check").FirstOrDefault();
         if ((configEntity != null && configEntity.Value != GetStr.GetCurrentDay) || IsConfig)
         {
             string sql          = @"SELECT * FROM U_URL_LIST WHERE ID NOT IN (SELECT URLID FROM U_URL_CHECK) AND STATUS=1";
             List <U_Url_List> t = bllU_Url_List.QuerySql(sql);
             if (t != null && t.Count > 0)
             {
                 foreach (var item in t)
                 {
                     #region 处理
                     try
                     {
                         U_Url_Check entity = new U_Url_Check();
                         entity.Url         = item.Url;
                         if (entity.Url.Contains("."))
                         {
                             entity.Url = entity.Url.Substring(entity.Url.IndexOf(".") + 1);
                         }
                         if (entity.Url.Contains("/"))
                         {
                             entity.Url = entity.Url.Substring(0, entity.Url.IndexOf("/"));
                         }
                         if (entity.Url.IsUrlFormat2())
                         {
                             var parameters1 = new Dictionary <string, string>();
                             parameters1.Add("domain", entity.Url);                      //域名如:juhe.cn ,1jing.com
                             parameters1.Add("dtype", "json");                           //返回类型,xml/json/jsonp可选
                             parameters1.Add("key", "cfdc0e6ed4b1fc85ecf6635066c179d6"); //你申请的key
                             result = RequestMethod.SendRequest("http://apis.juhe.cn/webscan/", parameters1, false);
                             if (result.IsNotNull() && result.Contains("200") && result.ToLower().Contains("successed"))
                             {
                                 WebSiteSecurityTest security = JsonConvert.DeserializeObject <WebSiteSecurityTest>(result);
                                 entity.Id          = GetStr.GetGuid;
                                 entity.Create_Time = GetStr.GetCurrentDate;
                                 entity.Result      = result;
                                 entity.Webstate    = security.result.webstate;
                                 entity.Msg         = security.result.msg;
                                 entity.UrlId       = item.Id;
                                 bllU_Url_Check.Add(new List <U_Url_Check> {
                                     entity
                                 });
                             }
                             else if (result.Contains("\"error_code\":10012"))
                             {
                                 configEntity.Value = GetStr.GetCurrentDay;
                                 bll_ConfigBLL.Update(configEntity);
                                 bll_LogBLL.AddLog(result, EnumLogType.Info, "调用聚和数据接口", "网站安全检测", "当日请求超过次数限制");
                                 break;
                             }
                         }
                         System.Threading.Thread.Sleep(1000);
                     }
                     catch (Exception ex) { bll_LogBLL.AddLog(ex, result, "调用聚和数据接口", "网站安全检测", "发生异常"); }
                     #endregion
                 }
             }
         }
         #endregion
     });
 }